Sub topic 1
What Extractive Question Answering Is
Prerequisites
This chapter assumes basic Python, familiarity with tokenization, and a general idea of neural networks and pretrained language models. You should also understand that a transformer processes text as a sequence of tokens rather than as whole sentences or words.
The extractive question-answering task
Extractive question answering answers a question by selecting a continuous span of text from a supplied context. The model does not normally invent new wording. For example:
- Question: “What does the Amazon basin cover?”
- Context: “Its drainage basin covers about seven million square kilometres.”
- Extracted answer: “about seven million square kilometres”
The answer is a substring of the context. This makes the task useful when the source text must remain authoritative, such as a search result, policy document, or support article.
A model receives two inputs:
- A question that describes the information the user wants.
- A context passage that may contain the answer.
It then predicts where the answer begins and ends in the passage. The predicted span may contain one token or many tokens.
How it differs from other approaches
Extractive question answering is different from retrieval and generation, although production systems often combine them.
- Retrieval finds documents or passages that may contain useful information. It ranks existing text but does not necessarily identify the exact answer.
- Extractive question answering selects an answer span from a passage that has already been provided.
- Generative question answering produces a new sequence of tokens. It can summarize, combine facts, or explain an answer, but it can also introduce details that are absent from the source.
A retrieval-augmented system may first retrieve several passages and then use an extractive model to select a span from the best passage. The extractive stage improves traceability because the answer can be shown alongside its source text.
The working model
A transformer encoder reads the question and context together. During inference, a small question-answering head assigns two scores to each context token:
- A start logit measures how suitable the token is as the first token of the answer.
- An end logit measures how suitable the token is as the last token of the answer.
A logit is an unnormalized score. The decoder searches for a start and end pair where the start comes before the end. It then maps those token positions back to character positions in the original context and copies the corresponding substring.
The highest individual start and end scores do not always form the best answer. The decoder must enforce valid spans and may limit answer length. It often ranks candidate spans using the sum of their start and end logits.
What the task cannot do automatically
An extractive model cannot answer correctly when the context lacks the needed fact. A model may still select a plausible-looking span unless it was trained and decoded to support unanswerable questions. It can also fail when:
- The answer requires combining facts from distant passages.
- The answer is implied rather than stated.
- The context is longer than the model's input limit.
- Tokenization splits words in unexpected places.
- Several similar phrases appear in the passage.
These are task and decoding issues, not just language-understanding issues. Evaluation and error analysis should therefore inspect the selected span, its source context, and the model's confidence.
Exercise
A system must answer questions using only an internal policy document and show the exact supporting wording. Which approach is the natural first choice, and why?
Show answer
Extractive question answering is the natural first choice because it selects a continuous span from the policy document, making the answer directly traceable to the source.