Sub topic 10
Error Types in Sequence Labeling
Assume you know basic Python and have trained a sequence-labeling model at least once. You should also understand train, validation, and test splits, plus precision, recall, and F1. This chapter uses named entity recognition as an example, but the same ideas apply to part-of-speech tagging, slot filling, and other tasks that predict labeled spans.
What counts as an error?
A sequence-labeling model assigns labels to tokens or predicts spans of tokens. A span is usually represented by a start offset, an end offset, and a type. In the convention used here, the end offset is exclusive. The span (5, 7, "ORG") covers positions 5 and 6.
A predicted span can fail in several ways:
| Error type | What happened | Typical fix |
|---|---|---|
| Missed | A gold span has no corresponding prediction | Add examples or improve recall |
| Spurious | The model predicts a span that is not in the gold data | Improve precision or review annotation rules |
| Boundary error | The type is right, but the start or end is wrong | Clarify span boundaries or add context |
| Type error | The boundaries are right, but the type is wrong | Improve label definitions or class balance |
A prediction can have both a boundary error and a type error. For example, the gold span might be (5, 7, "ORG"), while the model predicts (5, 8, "LOC").
Exact-match scoring makes these distinctions important. A span is correct only when its boundaries and type both match. Token-level accuracy can hide a boundary problem because most surrounding tokens may still be labeled correctly.
Comparing gold and predicted spans
Start by comparing sets of gold and predicted spans. For each missing gold span, check whether a predicted span overlaps it. Overlap helps distinguish a missed entity from a boundary or type problem.
def categorize(gold, pred):
"""Spans are (start, end, type), with an exclusive end offset."""
errors = []
unmatched_pred = set(pred - gold)
for gold_span in sorted(gold - pred):
overlap = [
item for item in sorted(unmatched_pred)
if gold_span[0] < item[1] and item[0] < gold_span[1]
]
if not overlap:
errors.append((gold_span, None, "missed"))
continue
predicted_span = overlap[0]
unmatched_pred.remove(predicted_span)
same_boundary = gold_span[:2] == predicted_span[:2]
same_type = gold_span[2] == predicted_span[2]
if same_boundary and not same_type:
kind = "type_error"
elif same_type and not same_boundary:
kind = "boundary_error"
else:
kind = "type_and_boundary_error"
errors.append((gold_span, predicted_span, kind))
errors.extend(
(None, span, "spurious")
for span in sorted(unmatched_pred)
)
return errors
gold = {
(0, 2, "PER"),
(5, 7, "ORG"),
(9, 10, "LOC"),
}
predicted = {
(0, 2, "PER"),
(5, 7, "LOC"),
(9, 11, "LOC"),
(13, 14, "ORG"),
}
for error in categorize(gold, predicted):
print(error)This script uses a simple one-to-one overlap rule. Production evaluation may use a stricter matching policy, especially when spans overlap each other. Keep the matching policy fixed when comparing model versions.
Reading the categories
A large number of missed spans indicates a recall problem. Inspect whether entities are rare, long, ambiguous, or absent from the training data. Spurious spans often result from overly broad rules or a model that treats common words as entities.
Boundary errors deserve special attention. Annotation guidelines may disagree about whether titles, punctuation, or possessives belong inside a span. If trained annotators make different choices, the apparent model error may actually be label inconsistency.
Exercise
The gold span is (3, 5, "ORG"), and the prediction is (3, 6, "ORG"). What error category is this?
Show answer
Boundary error. The type matches, but the predicted end offset is different.