Sub topic 9
Sampling so the set matches real demand and still covers rare topics
Assume you can read simple Python and understand basic privacy practices. This chapter also assumes that each question has already been scrubbed, normalised, labelled by intent, and assigned to a topic cluster. Sampling means choosing a smaller set from a larger collection for testing.
A useful prompt set needs two kinds of coverage:
- Demand coverage: common questions appear often enough to reflect what customers usually ask.
- Risk coverage: rare but important questions are still represented, such as cancellation, security, accessibility, or compliance questions.
Sampling only by frequency makes the set realistic but can hide important gaps. Sampling every topic equally gives broad coverage but can misrepresent customer demand.
Start with observed question counts
Keep the number of occurrences for each raw question or cluster. A cluster is a group of similar questions, such as “change billing details” or “export account data.”
For example:
| Cluster | Observed questions | Share of questions | Importance |
|---|---|---|---|
| Account access | 480 | 48% | High |
| Billing | 300 | 30% | High |
| Integrations | 150 | 15% | Medium |
| Data deletion | 20 | 2% | Critical |
| Accessibility | 10 | 1% | High |
The observed share should influence the sample size. Importance should influence the minimum number of prompts. A critical cluster may deserve prompts even when few customers have asked about it.
Do not confuse question count with customer count. One customer may submit the same question many times, and one support workflow may create more records than another. Record the source and counting method so that sampling decisions remain explainable.
Use proportional sampling with minimums
Suppose you need about 100 prompts. A proportional sample would allocate roughly 48 prompts to account access, 30 to billing, 15 to integrations, 2 to data deletion, and 1 to accessibility.
That sample is too small for meaningful testing of the last two clusters. Set a minimum, such as five prompts per cluster, for topics that must be covered. Then distribute the remaining capacity according to demand.
A practical process is:
- Set the target size.
- Reserve minimum slots for every required cluster.
- Allocate remaining slots in proportion to observed demand.
- Check that the final set does not exceed the target.
- Sample randomly within each cluster.
- Use a fixed random seed so the result can be reproduced.
- Record the sampling rules and the source dataset version.
The minimum should reflect the purpose of the evaluation. A general quality benchmark may need only a few rare-topic prompts. A compliance review may require many more carefully reviewed examples.
import random
from collections import defaultdict
def sample_prompts(rows, total, min_per_cluster=2, seed=7):
if not rows:
return []
rng = random.Random(seed)
by_cluster = defaultdict(list)
for row in rows:
by_cluster[row["cluster"]].append(row)
selected = []
for cluster, items in by_cluster.items():
share = round(total * len(items) / len(rows))
requested = max(min_per_cluster, share)
amount = min(len(items), requested)
selected.extend(rng.sample(items, amount))
return selectedThis function guarantees a minimum when a cluster has enough rows, but the final size may differ from total. In production, use a second allocation pass if the exact total matters. That pass should add or remove prompts while respecting cluster minimums.
Separate demand sampling from coverage sampling
Keep two views of the set instead of hiding the trade-off in one number:
- A demand-weighted set measures typical customer experience.
- A coverage set deliberately includes rare, high-impact, new, or underserved topics.
You can report results separately, or combine the sets with labels. For example, a test run might contain 80 demand-weighted prompts and 20 coverage prompts. Do not present the combined result as if all prompts had the same real-world frequency.
Review the sample for blind spots
After sampling, inspect the distribution by source, intent, topic, customer segment, language, and journey stage. Look for clusters that disappeared because they had too few records. Also look for over-representation caused by a single campaign, support incident, or unusually active customer.
A fixed seed makes a sample repeatable, but repeatability does not make it unbiased. Review the sampling frame, which is the collection from which prompts were eligible. If community posts are included but sales calls are not, the final set reflects that choice.
Exercise
Exercise
A topic represents 1 percent of customer questions but concerns account deletion. Should it receive only 1 percent of the prompts?
Show answer
No. Include a minimum number of account-deletion prompts because the topic is high impact, then label those prompts as coverage samples so they are not mistaken for typical demand.