Papa Programmer
Lesson 07 of 36

Collecting and creating examples

9 min read

Optional

What an example is

For the support task, one example is a customer message and the label a person judged correct. Together, many of these form the Training dataExamples used to update a model's trainable parameters. The examples and labels should be appropriate and permitted for the task.. The model will copy the patterns in them, including the errors, so the way you collect examples decides what you can build.

Source one: your own records

Past tickets, chat logs and documents show real language: typing errors, half sentences and odd product names. That realism is their strength. Check three things before you use them.

  • Permission. Having access to a record is not the same as having the right to train on it. Check your contracts, privacy notices and the consent customers gave.
  • Personal data. Remove names, email addresses, account numbers and secrets that the task does not need.
  • Labels. A past record may carry a label from a sloppy process. Do not trust it until you have sampled it.

Source two: experts write them

Experts can write examples for cases that are rare in the logs, such as an angry message with two problems. Give them a short labelling guide, with an example for each label and a rule for each edge case. Keep a note of the rule used for each hard example, so someone else can apply the same rule later.

Source three: a model drafts them

A larger model can write extra examples quickly. This is called synthetic data. It is cheap and it has risks: the drafts can repeat the generator's habits, sound unlike real customers, and carry wrong labels. Treat drafts as a first version that a person reviews, and never use synthetic examples as your test set. The test set should be real.

StrengthRisk
Past recordsReal language, real mixPermission, personal data and old labels
Expert-writtenCovers rare and hard casesSlow, and the style may differ from real users
Model-draftedFast and cheapWrong labels, repeated phrasing, and an unrealistic tone
Where examples come from

Check that people agree

If two careful people disagree on a label, the model cannot learn a clear rule from it. Measure this before training. The program below has two annotators label the same ten messages, and lists where they disagree.

python
from collections import Counter

tickets = [
	"I was charged twice this month",
	"Cannot reset my password",
	"App crashes when I open reports",
	"Why did my invoice go up?",
	"Login page shows an error",
	"Export to CSV does nothing",
	"Refund for a cancelled plan",
	"I forgot which email I signed up with",
	"Dashboard loads very slowly",
	"Can you update the billing address?",
]
anna = ["billing", "access", "technical", "billing", "access", "technical", "billing", "access", "technical", "billing"]
ben = ["billing", "access", "technical", "billing", "technical", "technical", "billing", "access", "technical", "access"]

same = sum(a == b for a, b in zip(anna, ben))
print(f"agreement: {same} of {len(tickets)}")
for text, a, b in zip(tickets, anna, ben):
	if a != b:
		print(f"  {text!r}: Anna says {a}, Ben says {b}")
print(Counter(anna))

It prints:

text
agreement: 8 of 10
  'Login page shows an error': Anna says access, Ben says technical
  'Can you update the billing address?': Anna says billing, Ben says access
Counter({'billing': 4, 'access': 3, 'technical': 3})

The two people agree on eight of ten messages. The two disagreements are useful, because each exposes a missing rule. Is a login error an access problem or a technical one? Does changing a billing address belong with billing or with the account? Settle each with a written rule, add it to the guide, and relabel. Then repeat the check on a fresh batch. Agreement that stays low after you clear up the guide means the task itself is unclear, and you should return to Define the task and what success means.

How many examples

No number works for every task. A narrow classifier may reach a good score with hundreds of reviewed examples, while an open-ended writing style may need thousands. Start with a small, balanced set. Train, score on the validation set and read the errors. Add examples where the errors cluster, and repeat. Every new example should answer a failure you have seen.

Watch the label mix too. In the printout above, the most common label has four examples and the rarest three. Real data is usually far more uneven, and a rare label that the model must catch needs enough examples for it to learn.

Keep a record of where each example came from

Store a source, a date, a labeller and the guide version with every example. When a customer asks you to delete their data, or a licence changes, you can find and remove what depends on it. The Lesson Safety, licences and upkeep returns to this.

Three sourcesUse real records, expert-written cases and reviewed model drafts, each for what it does best.
Measure agreementDisagreements between labellers point to rules missing from the guide.
Check the right to trainAccess to a record does not grant permission to train on it.

Your reading position is saved

0%

0 of 36 complete

Contents

Learning tools