Sub topic 6
Choosing Representative and Diverse Examples
This chapter assumes you can read short Python, know what a chat-style prompt is, and have seen a few-shot prompt with an instruction and labeled examples. It covers how to pick which examples go into the prompt.
Why selection matters
A model treats your examples as a sample of the task. If the sample is narrow, the model infers a narrow task. Three short, upbeat reviews teach it that reviews are short and upbeat. A long, mixed review then falls outside what it has seen, and the output gets less reliable.
Two properties matter:
- Representative: the examples look like the inputs you expect in real use, in length, tone, vocabulary, and difficulty.
- Diverse: the examples differ from each other, so together they cover the range of inputs and outputs.
Start from real data
Draw examples from real inputs, such as logs, support tickets, or user queries. Invented examples tend to be cleaner and more uniform than real traffic. Real data includes typos, mixed languages, and vague wording.
A practical process:
- Collect 50 to 200 real inputs and label them.
- Group them by obvious traits: length, topic, label, and whether they are clean or messy.
- Pick one or two examples from each group.
- Check that every label you expect appears at least once.
What diversity means in practice
Vary the examples along the axes that matter for your task. For sentiment classification, the axes might be:
| Axis | Narrow set | Diverse set |
|---|---|---|
| Label | all positive | positive, negative, neutral |
| Length | one short sentence | short and multi-sentence |
| Topic | only phones | phones, shipping, service |
| Difficulty | obvious cases | obvious and mixed cases |
Mixed cases deserve a place. A review such as "The screen is bright but the speakers are weak" is hard because it contains both praise and criticism. If every example is clear-cut, the model has no guidance for it.
Avoid near-duplicates
Two examples that say almost the same thing waste tokens and can overweight one pattern. The function below drops examples that are too similar to ones already chosen. It uses word overlap, the same measure used for dynamic selection later in this tutorial.
def overlap(a, b):
wa, wb = set(a.lower().split()), set(b.lower().split())
union = wa | wb
return len(wa & wb) / len(union) if union else 0.0
def pick_diverse(pool, k=4, max_similarity=0.5):
chosen = []
for text, label in pool:
if all(overlap(text, c[0]) < max_similarity for c in chosen):
chosen.append((text, label))
if len(chosen) == k:
break
return chosen
pool = [
("The battery lasts all day.", "positive"),
("The battery lasts all day and charges fast.", "positive"),
("It stopped working after a week.", "negative"),
("The package arrived on Tuesday.", "neutral"),
]
for text, label in pick_diverse(pool):
print(label, "|", text)The second example shares most of its words with the first, so it is skipped. The output keeps the positive, negative, and neutral cases.
This filter only compares surface words. It cannot tell that two differently worded examples teach the same thing, so review the result by hand.
Common errors
- Label skew: five positive examples and one negative push the model toward "positive". The next chapters cover balance in more detail.
- Only easy cases: the model performs well on clean inputs and fails on messy ones.
- Unrealistic examples: polished sample text that does not match real inputs.
- Wrong labels: one mislabeled example can teach the wrong rule. Re-read every label before you use it.
- Accidental shortcuts: if all negative examples are short, the model may learn "short means negative" instead of the sentiment.
Exercise
Your prompt has four examples, all short, clear, positive or negative product reviews. In production, many inputs are long and mixed. Name two changes to the example set.
Show answer
Add at least one long example, and add at least one mixed-opinion example with the label you want for such cases (for instance neutral). Also add a neutral example if that label is missing, so every expected label appears.