Sub topic 14
Ranking error categories and choosing fixes
You now have a list of error categories from your taxonomy. This chapter turns that list into a decision about what to work on next. A category with many errors is not automatically the best target. You also have to weigh how fixable it is, how much it costs to fix, and how sure you are of the counts.
Prerequisites
This chapter assumes you have:
- A hand-labeled sample of errors with one category per error, as built in the taxonomy chapter.
- The slice and uncertainty ideas from earlier chapters.
- Basic pandas and NumPy.
The working model: expected gain per unit of effort
For each category, estimate the metric gain you would get if you worked on it. Then divide by what it costs. The gain has three parts:
- Count. How many evaluation errors fall in the category.
- Fix rate. The fraction of those errors you expect a realistic fix to resolve. It is almost never 100%.
- Evaluation size. Dividing by the number of evaluation examples converts fixed errors into accuracy points.
expected_gain = count * fix_rate / n_eval
priority = expected_gain / effortThe fix rate is a guess. Make it an informed guess by reading a few examples and asking what change would flip each one. If you cannot name a change, the fix rate is near zero.
Compute a ranking
Suppose the evaluation set has 1,000 examples and the model makes 180 errors. After hand-labeling, you have five categories with rough fix-rate and effort estimates.
import pandas as pd
N_EVAL = 1000
cats = pd.DataFrame({
"category": ["label noise", "negation", "sarcasm", "domain terms", "long inputs"],
"count": [45, 52, 30, 33, 20],
"fix_rate": [0.8, 0.6, 0.1, 0.5, 0.3],
"effort_days": [2, 3, 8, 2, 5],
})
cats["share_of_errors"] = cats["count"] / cats["count"].sum()
cats["gain_pts"] = cats["count"] * cats["fix_rate"] / N_EVAL * 100
cats["gain_per_day"] = cats["gain_pts"] / cats["effort_days"]
ranked = cats.sort_values("gain_per_day", ascending=False)
print(ranked.round(2).to_string(index=False))The ranking by gain per day is label noise, negation, domain terms, long inputs, then sarcasm. Negation has the most errors, but label noise comes first because it is cheap and almost fully fixable. Sarcasm has 30 errors but ranks last. It has a low fix rate and a high cost, so it is a poor first target.
Two points about this table:
- The label-noise gain is a correction to the measurement, not an improvement to the model. Relabeling the test set raises the score without making the model better. Keep it as a separate line item and re-run the baseline afterward. That way later gains are measured against the corrected data.
- The ranking is only as good as the estimates. Change
fix_ratefor negation from 0.6 to 0.3 and re-run. If the order flips, the decision depends on a guess, and you should look at more examples before committing.
Check that the counts are stable
If you labeled only part of the errors, the category shares are estimates from a sample. A category with 17 of 60 sampled errors could plausibly be much larger or smaller in the full error set. A bootstrap interval, the same technique used for slices, shows how wide the range is.
import numpy as np
rng = np.random.default_rng(0)
sample = np.array(
["negation"] * 17 + ["label noise"] * 14 + ["domain terms"] * 10
+ ["sarcasm"] * 10 + ["long inputs"] * 9
)
for cat in np.unique(sample):
flag = (sample == cat).astype(int)
boot = [
rng.choice(flag, size=len(flag), replace=True).mean()
for _ in range(2000)
]
low, high = np.percentile(boot, [2.5, 97.5])
print(f"{cat:13s} share={flag.mean():.2f} 95% CI=({low:.2f}, {high:.2f})")With 60 sampled errors, the intervals for the top categories overlap heavily. Negation at 28% and label noise at 23% cannot be separated on count alone. When intervals overlap, let fix rate and effort decide, or label more errors before choosing.
Match each category to a kind of fix
The category usually points to the type of intervention. This table is a starting point, not a rule.
| Error category | Typical cause | Candidate fixes | Risk |
|---|---|---|---|
| Label noise | Inconsistent or wrong gold labels | Relabel, write clearer guidelines, drop ambiguous items | Changes the benchmark, so re-baseline |
| Negation or scope | Too few training examples of the pattern | Targeted data collection, augmentation with templates | Augmented text may look unlike real text |
| Domain terms | Vocabulary absent from pretraining or training | Continued pretraining, domain data, a lexicon feature | Gains stay narrow to that domain |
| Long inputs | Truncation, diluted signal | Longer context window, chunking, a hierarchical model | Higher latency and memory |
| Boundary errors in tagging | Inconsistent span conventions | Fix the annotation guide, add post-processing rules | Rules can break on new data |
| Overconfident mistakes | Poor calibration | Temperature scaling, abstain below a threshold | Fewer predictions get answered |
| Subgroup gaps | Under-representation or spurious cues | Reweighting, collecting data for the slice | Can trade off with the overall score |
Prefer the cheapest fix that addresses the cause. Changing the model architecture to fix an annotation inconsistency treats the symptom and leaves the cause in place.
Factors besides counts
Counts weigh every error equally. In real systems they often are not equal. Add a severity weight when the cost of errors differs:
- A missed "cancel my account" intent may cost more than a missed small-talk intent.
- A false positive in a content filter may cost more than a false negative, or the reverse.
- Errors on a subgroup that you are obliged to serve fairly may deserve extra weight even if the count is small.
You can fold severity into the score by replacing count with a weighted count, sum(severity_i). Write the weights down and agree on them with the people who own the product. Otherwise the ranking will reflect your private assumptions.
You should also consider how the category will behave after deployment. A category caused by a temporary data artifact, such as a template used only in the test set, will not recur. A category caused by a persistent distribution shift will grow.
Common errors in prioritization
- Ranking by count alone. A large category with a near-zero fix rate absorbs weeks and moves the score a fraction of a point.
- Treating fix rate as 100%. Even a well-aimed fix resolves only part of a category. Use 0.3 to 0.7 unless you have evidence from a prototype.
- Ignoring overlap. One error can belong to two categories, such as a negation that also uses a domain term. If you count it in both, the gains do not add up. Assign one primary category per error, or discount the sum.
- Chasing a noisy ranking. Differences smaller than the bootstrap interval are not real. Pick by cost and risk instead.
- Mixing measurement fixes with model fixes. Relabeling changes the yardstick. Report it separately.
- Skipping a cheap probe. Before a three-day project, spend an hour fixing ten examples by hand, for instance by adding ten training examples, and see whether the model learns the pattern. The result gives you a measured fix rate in place of a guess.
A short decision procedure
- Rank by
expected_gain / effortand list the top three categories. - Check whether the top two are separable given the interval on their counts.
- Run a cheap probe on the top candidate to measure its fix rate.
- Apply a severity weight if error costs differ, and check for an overlap in the counts.
- Commit to one change. Changing several things at once makes it impossible to tell which one helped.
- Record the expected gain. After the next evaluation, compare the actual gain with it. Over several rounds, this teaches you how reliable your fix-rate guesses are.
Exercise
A model makes 200 errors on a 2,000-example test set. Category A has 60 errors, an estimated fix rate of 0.5, and costs 5 days. Category B has 40 errors, a fix rate of 0.9, and costs 1 day. Compute the expected gain in accuracy points per day for each, and say which to do first.
Show answer
Category A: 60 0.5 / 2000 = 0.015, which is 1.5 points, divided by 5 days gives 0.3 points per day. Category B: 40 0.9 / 2000 = 0.018, which is 1.8 points, divided by 1 day gives 1.8 points per day. Do B first. It has fewer errors, but it yields more gain overall and about six times more per day.
Exercise
You labeled 50 errors and 12 are "negation" while 10 are "domain terms". A teammate says negation is clearly the bigger problem. What should you check before agreeing, and what would you do if the check is inconclusive?
Show answer
Compute a bootstrap interval on each share. With 12 and 10 out of 50 the intervals overlap heavily, so the sample does not show that negation is larger. Compare the fix rate and effort for each category instead, ideally with a cheap probe on a few examples. If it is still unclear, label more errors to narrow the intervals before committing.