Sub topic 1
Why Aggregate Scores Are Not Enough
Prerequisites
This chapter assumes that you have trained and evaluated an NLP classifier or sequence tagger at least once. You should know the difference between training, validation, and test data, and understand accuracy, precision, recall, and F1.
The limit of one score
An aggregate metric summarizes performance over the whole test set. Accuracy answers, “What fraction of predictions were correct?” F1 summarizes precision and recall. These numbers are useful for comparing model versions, but they do not explain the model’s behavior.
A model can achieve high accuracy by performing well on common examples while failing on a smaller but important group. For example, a sentiment classifier might recognize positive and negative reviews but consistently label neutral reviews as positive. If neutral reviews are uncommon, the overall accuracy may still look good.
The same problem appears in named entity recognition. A model may find most person names but miss organization names, or identify an entity with the wrong boundaries. A single score combines these different behaviors.
| Aggregate result | Hidden question |
|---|---|
| 90% accuracy | Which classes account for the 10% of errors? |
| 0.82 macro-F1 | Are all classes equally difficult? |
| 95% entity-level F1 | Are errors mostly missed entities, wrong types, or wrong boundaries? |
A working model of error analysis
Error analysis is the process of examining model failures to discover patterns that metrics hide. It connects a numerical result to a possible action.
A useful loop is:
Start by asking whether the metric matches the actual cost of mistakes. If missing a safety-related complaint is worse than incorrectly flagging a neutral comment, accuracy is not enough to guide decisions. You may need per-class recall, a cost-weighted metric, or a separate threshold for a high-risk class.
Next, compare the model with a baseline. A baseline can be a majority-class predictor, a simple rule, or an earlier production model. If a complex model barely beats a simple baseline, the aggregate score does not justify its added cost.
from collections import Counter
true_labels = ["pos", "pos", "neg", "neu", "pos", "neg"]
predicted_labels = ["pos", "neg", "neg", "pos", "pos", "neg"]
accuracy = sum(
true == predicted
for true, predicted in zip(true_labels, predicted_labels)
) / len(true_labels)
majority_label = Counter(true_labels).most_common(1)[0][0]
majority_accuracy = sum(label == majority_label for label in true_labels) / len(true_labels)
print(f"model accuracy: {accuracy:.2f}")
print(f"majority baseline: {majority_accuracy:.2f}")The baseline does not diagnose the errors. It tells you whether the model has learned useful distinctions at all.
What to inspect next
Do not inspect only random examples. Save each prediction with its input text, gold label, predicted label, and confidence score. Then inspect errors by class and look for repeated causes such as negation, sarcasm, spelling variation, long inputs, or ambiguous wording.
Aggregate scores are a starting point and a release check. They are not an explanation. A model should be judged by where it fails, how often it fails there, and whether those failures matter for the intended use.
Exercise
A classifier has 96% accuracy, but nearly all errors occur in a rare class used to detect urgent complaints. What should you do before declaring the model ready?
Show answer
Inspect the rare class separately, report its precision and recall, review representative errors, compare with a baseline, and decide whether the metric reflects the cost of missing urgent complaints.