Sub topic 10
Analyzing Errors by Category
This chapter assumes you know how to define an extraction schema, create gold annotations, and calculate span-level precision, recall, and F1. The goal now is to explain why an extraction system fails. A single F1 score tells you how often the system is wrong, but error categories tell you what to change.
A practical error taxonomy
Review errors against the gold data, then assign each error a category. Use categories that lead to different actions.
| Error category | Typical symptom | Likely response |
|---|---|---|
| Boundary | The right entity is found, but extra or missing tokens are included | Clarify span rules or adjust token handling |
| Type | The span is correct, but its label is wrong | Add examples that distinguish similar labels |
| Missing | A gold entity has no prediction | Improve coverage, prompting, or training data |
| Spurious | The system predicts an entity that is not in the gold data | Tighten instructions or reduce overprediction |
| Normalization | The extracted value is right, but its format is inconsistent | Add a normalization rule and validation |
| Evidence | The system invents a value that the text does not state | Require null for unknown values and reject unsupported output |
Boundary errors are especially common in named-entity recognition. For example, the gold span might be Paris, while the model returns Paris.. Type errors occur when a model labels a company as a person. Missing and spurious errors affect recall and precision respectively.
Separate detection from interpretation
For each prediction, ask two questions:
- Did the system select the correct text span?
- Did it assign the correct label or value?
This separation prevents vague conclusions such as “the model does not understand invoices.” A model might detect the total correctly but assign the wrong currency. It might also identify the vendor correctly while including a nearby address.
For generative extraction, inspect the raw response as well as the parsed object. A valid JSON response can still contain an unsupported value. For example, "currency": "USD" is structurally valid but incorrect if the invoice never states a currency.
def classify_spans(gold, predicted):
"""Return exact matches, missing spans, and spurious spans.
Each span is a tuple: (start_token, end_token, label).
"""
gold = set(gold)
predicted = set(predicted)
exact = gold & predicted
missing = gold - predicted
spurious = predicted - gold
return {
"exact": sorted(exact),
"missing": sorted(missing),
"spurious": sorted(spurious),
}
gold = [(0, 2, "VENDOR"), (5, 6, "TOTAL")]
predicted = [(0, 3, "VENDOR"), (5, 6, "CURRENCY")]
print(classify_spans(gold, predicted))This simple comparison marks both predictions as non-exact. During manual review, classify (0, 3, "VENDOR") as a boundary error and (5, 6, "CURRENCY") as a type error. A production evaluator can add partial-overlap matching to distinguish boundary errors from completely missing entities.
Use error patterns to choose an intervention
Look for repeated errors across documents rather than reacting to one example.
A prompt change is appropriate when the model ignores a clear instruction, returns extra prose, or confuses a null rule. More labeled examples or fine-tuning are better when the same domain-specific pattern appears repeatedly. A schema change may be necessary when human annotators cannot agree because the field itself is ambiguous.
Compare systems by the same categories
Use the same held-out examples and taxonomy for a prompted system and a fine-tuned model. Prompting may produce fewer missing entities but more spurious or normalization errors. A fine-tuned token classifier may be consistent and fast but struggle with new wording or labels that were rare in training.
Track counts and rates, not only raw examples. Ten boundary errors mean something different in a test set with 20 entities than in one with 10,000. Also record document type, language, length, and source. An error concentrated in scanned invoices may indicate an upstream text extraction problem rather than a language-model problem.
Exercise
Exercise
A model finds the correct invoice total span but labels it as TAX. What error category is this, and what should you inspect first?
Show answer
It is a type error. Inspect label definitions and examples for distinguishing TOTAL from TAX, then check whether the training or few-shot examples contain enough similar cases.