Sub topic 14
Limitations and common failure modes
This chapter assumes you can run the question-answering pipeline, that you know how start and end logits become an answer span, and that you know exact match (EM) and F1. It covers where extractive models break, how to recognize each failure, and how to run a simple error analysis.
What the model can and cannot do
An extractive model picks a start token and an end token inside the context. This design limits what it can do:
- It can only return text that appears in the context. It cannot combine facts, compute, or rephrase.
- It always scores every position. Unless you add a null option, it returns the best-looking span even when no good span exists.
- It sees at most one window of tokens at a time. The pipeline defaults to 384 tokens with a stride of 128.
- It was fine-tuned on a specific distribution, such as Wikipedia paragraphs with crowd-written questions. It is weaker on text that differs from that.
Most failures follow from these four facts.
A catalogue of failure modes
| Failure | What you see | Typical cause |
|---|---|---|
| Boundary error | Answer is nearly right but has extra or missing words | Annotators disagree on span edges, and the model learned an average |
| Wrong span | Answer is fluent but unrelated to the question | A distractor shares words with the question |
| Forced answer | Model answers a question the text does not cover | No null option, or the null threshold is too low |
| Missed answer | Model returns an empty answer when one exists | Null threshold too high, or the answer sits in a window cut by truncation |
| Truncated answer | Long answers are cut short | `max_answer_len` limit on span length |
| Reasoning gap | Wrong or empty answer to "how many" or "why" questions | The answer needs arithmetic, comparison, or several sentences |
| Domain shift | Scores drop on legal, medical, or conversational text | Different vocabulary and structure from the training data |
| Offset bug | Answer string is shifted or garbled | Wrong sequence ids or offsets used when cutting from the context |
Boundary errors and why F1 exists
Consider the reference "about seven million square kilometres" and the prediction "seven million square kilometres". Exact match is 0 and F1 is high. The model is right in substance. Many "errors" in an EM score are of this kind, so always read EM and F1 together. A large gap between them (for example EM 78, F1 86) points to boundary disagreement. It does not point to wrong answers.
Distractors and shallow matching
Models often rely on lexical overlap between question and context. Suppose the context says "The tower was designed by Gustave Eiffel's company and finished in 1889. The nearby bridge was finished in 1902." and you ask "When was the bridge finished?" A model that matches on "finished" and the nearest date may return 1889. Adversarial test sets for SQuAD showed that appending a sentence that looks relevant but is not can lower F1 sharply. This tells you the model can be steered by surface cues.
Confident wrong answers
The softmax over positions makes the start scores sum to 1. That does not make them calibrated probabilities. The pipeline's score is the product of a start probability and an end probability, and it can be high for a wrong span when a distractor stands out. It can also be low for a correct answer that is spread across several candidate boundaries. Treat the score as a ranking signal. Do not read it as "the chance this is correct" unless you have measured calibration on your own data.
Forced answers and the null threshold
A model fine-tuned on SQuAD v1.1 has never seen an unanswerable question. Even with handle_impossible_answer=True, the pipeline only compares the best span against the null score at the first token. A model trained only on answerable data gives that score no useful meaning. Use a checkpoint fine-tuned on SQuAD v2 or similar data. Then tune the threshold on validation data. Raising it produces more empty answers. That means fewer forced answers and more missed ones.
Length limits
The pipeline's max_answer_len defaults to 15 tokens. A correct answer that is a full clause, such as a definition, is cut off or replaced by a shorter span. Raise it when your task needs longer answers, and expect slower decoding and more spurious long spans. The span search is quadratic in the number of candidates, which is why the decoding code in an earlier chapter kept only the top 20 starts and ends.
Long contexts
With stride windows, each window is scored separately and the best-scoring span wins. This introduces two problems:
- Scores are not comparable across windows. A window with a strong but irrelevant span can beat the window with the true answer.
- Evidence split across windows is lost. If the answer needs two sentences that fall in different windows, no window sees both.
For documents far longer than the limit, put a retriever in front of the reader. The retriever picks the few passages most likely to hold the answer, and the extractive model reads only those. Increase doc_stride overlap only if your answers can be long, because the overlap must be at least as large as the longest answer you expect.
Questions that need more than a span
Extractive QA does not handle these well:
- Counting or arithmetic ("How many rivers are listed?").
- Yes/no questions, since "yes" is rarely in the context at the right place.
- Multi-hop questions that chain two facts from different sentences.
- Questions whose answer is a summary or an explanation.
For these, a generative reader, a model with a retrieval-and-reasoning pipeline, or a rule-based step is more suitable.
Domain shift
A model fine-tuned on Wikipedia loses accuracy on text with different style: clinical notes, contracts, chat logs, tables flattened to text, or OCR output with errors. The cased DistilBERT used in this tutorial also differs from uncased models in how it treats capitalization, which matters for names and acronyms. The fix is to fine-tune on a few hundred labeled examples from your domain. Continuing from a SQuAD checkpoint usually beats starting from the raw encoder.
Implementation bugs that look like model errors
Before blaming the model, check the plumbing:
- Wrong sequence ids. If you do not mask question tokens, the best span can fall inside the question.
- Offsets from the wrong window. With overflowing tokens, each window has its own offset mapping. Using window 0 offsets on a later window gives shifted text.
- Special tokens. Offsets for
[CLS]and[SEP]are(0, 0). A span that includes them produces empty or odd strings. - Start after end. Without the
s <= echeck, the argmax of each head may give an impossible span. - Normalization mismatch. Metrics apply lowercasing and article removal to both sides. Comparing raw strings undercounts correct answers.
A simple error analysis
Aggregate metrics hide which failures dominate. Sort every prediction into a category and count them. This script uses the same normalization as the SQuAD metric. It runs without any model, so you can feed it predictions from any system.
import re
import string
from collections import Counter
def normalize(text):
text = text.lower()
text = "".join(ch for ch in text if ch not in set(string.punctuation))
text = re.sub(r"\b(a|an|the)\b", " ", text)
return " ".join(text.split())
def categorize(prediction, golds):
"""Sort one prediction into an error category."""
if not golds:
return "correct null" if prediction == "" else "answered unanswerable"
if prediction == "":
return "missed answer"
pred = normalize(prediction)
gold_norm = [normalize(g) for g in golds]
if pred in gold_norm:
return "exact"
pred_tokens = set(pred.split())
if any(pred_tokens & set(g.split()) for g in gold_norm):
return "partial overlap"
return "wrong span"
examples = [
("seven million square kilometres", ["about seven million square kilometres"]),
("the Amazon River", ["Amazon River"]),
("South America", ["seven million square kilometres"]),
("", ["1998"]),
("Brazil", []),
("", []),
]
counts = Counter(categorize(p, g) for p, g in examples)
for category, n in sorted(counts.items()):
print(f"{category}: {n}")The output lists one count per category: answered unanswerable, correct null, exact, missed answer, partial overlap, and wrong span once each, except that exact appears once for "the Amazon River". On a real validation set, read twenty or thirty examples from the largest non-exact bucket. A pile of "partial overlap" cases suggests annotation noise or boundary conventions. A pile of "wrong span" cases suggests distractors or domain shift. A pile of "answered unanswerable" cases means you should retune or retrain the null handling.
Choosing what to do
Fix cheap things first: decoding bugs, max_answer_len, and the null threshold. Then add retrieval if documents are long. Fine-tune on in-domain data only when the error analysis shows a domain pattern. Switch to a generative approach when most failures fall in the "needs more than a span" group, since no tuning will make a span extractor add numbers or write explanations.
Exercise
A model scores EM 62 and F1 81 on your validation set. What does the gap suggest, and what would you inspect first?
Show answer
The gap means many predictions overlap the reference without matching it exactly, which points to boundary disagreements rather than wrong answers. Inspect the "partial overlap" bucket: check whether predictions add or drop words such as qualifiers, units, or articles, and whether the references are inconsistent. If the boundaries are reasonable, the model is better than EM suggests.
Exercise
Your SQuAD v1.1 model answers "Brazil" to a question the passage never addresses, even with handleimpossibleanswer=True. Why does the null option not help, and what two changes would fix it?
Show answer
The model was never trained on unanswerable questions, so its null score (the first-token score) carries no learned meaning. Use a checkpoint fine-tuned on SQuAD v2 or similar data that includes unanswerable questions, then tune the null threshold on a validation set from your domain.
Exercise
A 6,000-token report is split into windows with stride 128. The question needs facts from paragraphs 3 and 9. Why might the model fail, and what is a better design?
Show answer
Paragraphs 3 and 9 almost surely fall in different windows. Each window is scored on its own, so no window contains both facts, and scores from different windows are not directly comparable. A better design retrieves the relevant passages first, then uses a reader that handles multi-sentence reasoning (for example a generative model), because an extractive model returns a single span from one place.