Labelling and annotation
For supervised learning, labels are the lesson. This module shows how to make them consistent, efficient and trustworthy.
Learning objectives
- Explain how label quality limits model quality
- Write effective labelling guidelines
- Measure inter-annotator agreement with Cohen's kappa
- Choose efficient labelling techniques, including LLM assistance
- Detect label errors and treat labellers responsibly
- Check LLM-proposed labels against a human-labelled sample and route doubtful ones to people
- Use synthetic data safely
4.1 Why labels matter
Supervised learning learns from labels — the "right answers" attached to examples: is this email spam, which category is this ticket, is this X-ray abnormal? Inconsistent or wrong labels put a ceiling on model quality, and evaluation against wrong labels gives misleading scores.
Labels matter just as much when you're using a ready-made language model and not training anything. To know whether an AI assistant is sorting tickets correctly, you need a set of tickets that people have labelled carefully to check it against. That evaluation set is labelled data, and everything in this module applies to it.
4.2 Write labelling guidelines
- A clear definition of every label, with examples and counter-examples
- Rules for ambiguous and borderline cases — and an "unsure" option
- What to do when information is missing
- Worked examples reviewed by experts
- A version number — update the guidelines as you learn
A worked example
Take the label delivery for support tickets. A first draft says: "Use delivery for problems with delivery." Two labellers will soon disagree about "My parcel arrived but the board was cracked." Is that delivery, or product? A usable guideline settles it in advance:
| Label | Definition | Example | Not this label |
|---|---|---|---|
| delivery | The parcel is late, lost, or went to the wrong place | "Tracking hasn't moved for a week" | Item damaged on arrival → product |
| product | Something is wrong with the item itself, however it happened | "The board arrived cracked" | Wrong item sent → delivery |
| billing | Charges, refunds and invoices | "I was charged twice" | Asking when a refunded item will be collected → delivery |
The "not this label" column does most of the work. Easy cases label themselves; guidelines exist for the borderline ones.
4.3 Measure agreement between labellers
Have two or more people label the same sample independently and measure how often they agree. Cohen's kappa measures agreement between two labellers while correcting for agreement expected by chance: 1 is perfect, 0 is no better than chance. Low agreement usually means the guidelines — not the labellers — need work.
Python · inter-annotator agreementimport pandas as pd
from sklearn.metrics import cohen_kappa_score
annotator_a = ["billing", "delivery", "product", "delivery", "other", "billing", "product", "delivery"]
annotator_b = ["billing", "delivery", "product", "billing", "other", "billing", "delivery", "delivery"]
agreement = sum(a == b for a, b in zip(annotator_a, annotator_b)) / len(annotator_a)
kappa = cohen_kappa_score(annotator_a, annotator_b)
print(f"Raw agreement: {agreement:.0%} Cohen's kappa: {kappa:.2f}")
# Which items do they disagree on? Discuss them and refine the guidelines.
print([i for i, (a, b) in enumerate(zip(annotator_a, annotator_b)) if a != b])
As a rough guide, kappa above 0.8 is strong agreement, 0.6 to 0.8 is workable, and below 0.6 means the labels aren't yet reliable enough to train or evaluate on. Treat these as rules of thumb: a medical task needs far higher agreement than sorting marketing emails.
4.4 Making labelling efficient
| Technique | How it helps | Watch out for |
|---|---|---|
| Active learning | The model picks the examples it's least sure about for humans to label next | Can under-sample easy-but-important cases |
| Weak supervision | Simple rules or keywords label data roughly at scale | Rules carry their own biases and errors |
| LLM-assisted labelling | A language model proposes labels; humans review | Plausible but wrong labels; check a sample and measure agreement with humans |
| Consensus labelling | Several labellers per item; take the majority | More cost per item |
4.5 Finding label errors
Even well-run projects contain label errors. Useful checks: examples where a trained model confidently disagrees with the label; duplicates or near-duplicates with different labels; and spot audits of random samples by an expert.
Python · conflicting labels on duplicate texttickets = pd.DataFrame({
"text": ["Where is my order?", "Where is my order?", "Charged twice", "Refund please"],
"label": ["delivery", "billing", "billing", "billing"],
})
conflicts = tickets.groupby("text")["label"].nunique()
print(conflicts[conflicts > 1]) # same text, different labels -> review
4.6 Labellers are people
Much labelling work is outsourced. Responsible practice includes fair pay, clear instructions, reasonable workloads, and protection and support for people asked to review distressing content.
4.7 Labelling with a language model: a worked example
Labelling has changed quickly. A common set-up now has layers: a language model makes a first pass over everything, people review the cases it is unsure of or likely to get wrong, and a human-labelled sample is kept to measure the whole process. The model does not replace the guidelines. It reads them: the guideline table from 4.2 becomes part of its instructions.
The essential step is the one people skip: before trusting the model's labels, compare them with careful human labels on a sample. The cell below uses a small made-up sample so you can see the checks; no AI model is called.
Python · checking a model's labels against a human-labelled samplesample = pd.DataFrame({
"human": ["delivery", "delivery", "product", "billing", "product", "delivery", "billing", "product",
"delivery", "billing", "product", "delivery", "other", "billing", "product", "delivery"],
"model": ["delivery", "delivery", "product", "billing", "delivery", "delivery", "billing", "product",
"delivery", "billing", "delivery", "delivery", "billing", "billing", "product", "delivery"],
"model_confidence": [0.97, 0.91, 0.88, 0.99, 0.55, 0.93, 0.96, 0.90,
0.89, 0.98, 0.61, 0.95, 0.52, 0.97, 0.86, 0.92],
})
print("Agreement:", (sample["human"] == sample["model"]).mean().round(2),
" kappa:", round(cohen_kappa_score(sample["human"], sample["model"]), 2))
print(pd.crosstab(sample["human"], sample["model"])) # rows = human, columns = model
Overall agreement looks respectable. The table shows where the errors are: the model has labelled two product tickets as delivery — exactly the borderline the guidelines had to spell out — and has never used other. An overall score would have hidden both.
Python · send the doubtful ones to a personreview = sample[sample["model_confidence"] < 0.7]
print(review)
print("Sent for human review:", len(review), "of", len(sample))
print("Errors caught by review:", int((review["human"] != review["model"]).sum()),
"of", int((sample["human"] != sample["model"]).sum()))
Here a simple rule — a person reviews anything the model scores below 0.7 — catches every error while people look at under a fifth of the tickets. Real data is never this tidy: models are sometimes confidently wrong, so keep auditing a random sample of the high-confidence labels as well.
4.8 Synthetic data
Synthetic data is data that has been generated, not collected: rows produced by rules or a statistical model, or text written by a language model. It is now a routine part of preparing data for AI, most often to fill gaps for rare cases, to test systems without using real customers' details, and to create examples for evaluating AI assistants.
Python · topping up a rare class, and marking itreal = pd.DataFrame({
"text": ["Where is my order?", "Tracking hasn't moved", "Charged twice", "Parcel went to my neighbour",
"Refund not received", "Late again", "Card declined", "The app logged me out and lost my basket"],
"label": ["delivery", "delivery", "billing", "delivery", "billing", "delivery", "billing", "account"],
})
real["source"] = "real"
generated = pd.DataFrame({
"text": ["I can't reset my password", "My login stopped working", "Please delete my account"],
"label": "account",
"source": "synthetic",
})
training = pd.concat([real, generated], ignore_index=True)
print(pd.crosstab(training["label"], training["source"]))
Three habits keep synthetic data from causing harm:
- Mark it. A
sourcecolumn costs nothing and lets you remove or re-weight generated rows later. - Test on real data. A model checked only against generated examples has been checked against what the generator imagines customers say, not against what they say.
- Check it like any other data. Generated text tends to be tidier and more repetitive than the real thing, can repeat the generator's biases, and can occasionally reproduce real personal details it was built from.
The table above shows the catch plainly: three of the four account examples are invented. If account tickets matter, the real fix is to collect more of them.
Three people labelled the same six tickets. Run the starter code, then add a consensus column holding the majority label for each ticket, and flag the tickets where all three disagreed.
Your turnvotes = pd.DataFrame({
"a": ["billing", "delivery", "product", "delivery", "other", "billing"],
"b": ["billing", "delivery", "delivery", "delivery", "billing", "billing"],
"c": ["billing", "product", "product", "delivery", "product", "account"],
})
# Add consensus and all_differ columns, then press RunShow a solution
votes = pd.DataFrame({
"a": ["billing", "delivery", "product", "delivery", "other", "billing"],
"b": ["billing", "delivery", "delivery", "delivery", "billing", "billing"],
"c": ["billing", "product", "product", "delivery", "product", "account"],
})
votes["consensus"] = votes.mode(axis=1)[0]
votes["all_differ"] = votes[["a", "b", "c"]].nunique(axis=1) == 3
print(votes)
# Where all three differ there is no majority: mode() just returns the first alphabetically.
# Those tickets go to an expert, and probably into the guidelines as a new worked example.Using sample from 4.7, try review thresholds of 0.6, 0.7, 0.9 and 0.95. For each, print how many tickets go to a person and how many of the model's errors that catches. Which threshold would you choose if each review costs time?
Your turn# Write your code here, then press RunShow a solution
errors = sample["human"] != sample["model"]
for t in [0.6, 0.7, 0.9, 0.95]:
sent = sample["model_confidence"] < t
print(f"threshold {t}: review {sent.sum():2} of {len(sample)}, catches {(sent & errors).sum()} of {errors.sum()} errors")
# 0.7 catches everything here with the least review. Higher thresholds only add work.
# On real data you would pick the threshold from a much larger sample.Key takeaways
- Wrong labels cap model quality and distort evaluation.
- Guidelines need definitions, examples, edge-case rules and versions.
- Low agreement usually means unclear guidelines.
- LLM-proposed labels need human review and measured agreement.
- Look for conflicts, confident model disagreements and audit samples.
- A table of human against model labels shows where errors are; an overall score hides them.
- Mark synthetic data, and always test on real data.