Sub topic 5
Building an Error Taxonomy by Hand
Assume you can train and evaluate an NLP model, read a pandas table, and interpret precision, recall, and F1. This chapter focuses on what to do after you have collected incorrect predictions. The goal is to turn a list of mistakes into a small, useful set of error categories.
Why categories matter
An error taxonomy is a set of labels that describes why a model fails. Accuracy tells you how often the model is wrong. A taxonomy tells you what to fix.
For example, a sentiment classifier might call “The camera is small, but the battery is awful” positive because it notices “small” and misses the negative clause. That error could belong to a category such as mixed sentiment, negation, or multi-sentence context.
A useful category should be:
- Specific enough to suggest a possible fix.
- Broad enough to contain more than one example.
- Defined by observable evidence in the text or prediction.
- Separate from the proposed solution.
“Needs more training data” is usually a solution, not an error category. “Rare product name” is an observable cause that may lead to that solution.
Create categories from a sample
Start with a random sample of errors. Read each example without trying to solve it immediately. Write a short description of the failure. After reviewing 20 to 50 examples, group descriptions that have the same cause.
A first taxonomy for a sentiment classifier might look like this:
| Category | Definition | Example |
|---|---|---|
| Negation | The prediction ignores a negation word or phrase | “Not useful” predicted positive |
| Mixed sentiment | Different parts of the text express different opinions | “Great screen, terrible battery” |
| Sarcasm | The literal words conflict with the intended meaning | “Exactly what I needed: another delay” |
| Ambiguous label | Reasonable annotators could choose different labels | “It is fine” |
| Topic or entity gap | The text contains an unfamiliar name, product, or domain term | A new model name is treated as a positive word |
Keep the taxonomy small at first. Ten overlapping categories make labeling inconsistent. You can add a category when several examples clearly need a description that existing categories cannot provide.
Label errors consistently
Write a definition and at least one boundary rule for every category. For example:
- Negation includes “not,” “never,” and similar constructions when they reverse the relevant meaning.
- Mixed sentiment requires at least two meaningful sentiments in the same example.
- Ambiguous label applies when the text itself supports multiple labels, not merely when the model is uncertain.
Allow multiple labels only when causes can genuinely coexist. A sarcastic sentence may also contain negation, but assigning every possible label makes category counts difficult to interpret. A practical rule is to record one primary cause and optional secondary causes.
Use a separate label for errors that do not fit yet. Do not force an example into a familiar category. An “other” group shows where the taxonomy needs review.
Tally the hand-labeled sample
After labeling, count primary categories and calculate their share of the reviewed errors:
import pandas as pd
errors = pd.DataFrame({
"id": [1, 2, 3, 4, 5, 6],
"primary_category": [
"negation",
"mixed_sentiment",
"negation",
"ambiguous_label",
"topic_or_entity_gap",
"mixed_sentiment",
],
})
summary = (
errors["primary_category"]
.value_counts()
.rename_axis("category")
.reset_index(name="errors")
)
summary["share"] = summary["errors"] / len(errors)
print(summary.to_string(index=False))The counts describe this sample, not necessarily all production errors. Record the sample size and the labeling rules alongside the results.
Exercise
Exercise
An error says, “The service was fast, but the support team never replied.” The model predicts positive, while the gold label is negative. Which primary category would you test first, and what evidence would you look for?
Show answer
Test mixed sentiment or aspect-level sentiment first. Check whether the dataset defines the overall label by the most negative aspect, the overall customer experience, or another rule. The example may also reveal an annotation ambiguity.