- Type
- NLP text-comprehension task
What does it do?
Question answering is a natural-language-processing task in which a system answers a natural-language question using a given context passage.
The main approaches are extractive, returning a span of the passage, or generative, writing a free-form answer. The SQuAD dataset of Rajpurkar et al. (2016) is a widely cited benchmark for this task, in which each answer is a segment of the reading passage.
The intuition behind the method
When you ask a question, the answer usually lives somewhere inside a relevant body of text. A question-answering system reads that context passage alongside the question and works out the response. An extractive system locates and copies the exact span of text that answers the question, while a generative system writes an answer in its own words. Either way, the model is anchored to the supplied context rather than answering from unconstrained generation.
History
Rajpurkar et al. (2016) introduced SQuAD, a reading-comprehension dataset of more than 100,000 questions posed by crowdworkers on Wikipedia articles, in which the answer to each question is a segment of text from the corresponding reading passage.
When to use it
Question answering fits when you have natural-language questions and a context passage that is expected to contain the answers, so the answer can be located or written from that text. Use an extractive approach when the answer must be verbatim from the source, and a generative approach when a reworded answer is acceptable. Do not use it when no relevant passage is available, because the method has nothing to ground its answer in. Also be cautious when the answer is not actually contained in the passage, or when the text is highly specialised and the general-purpose model has not been checked against it.
Limitations and considerations
- Requires a relevant context passage; without one, the method cannot ground its answer.
- The answer can only be as good as the passage: if the passage lacks the information, the system has no correct span or sentence to return.
- A general-purpose model may give lower accuracy on specialised terminology than a model suited to that domain.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Grounds answers in a supplied context passage, so each answer can be traced back to the text it was drawn from.
- Supports both extractive answers, which are exact spans copied from the passage, and generative answers written in natural language.
- The encoding step can use a different language model without changing the question-passage-answer structure of the pipeline.
Applications
- Answering user questions against a single document or a defined set of passages.
- Reading-comprehension tasks that require extracting a precise answer span from a passage.
- Support tools that respond to natural-language questions over a text collection with a known context.
How it works
How it works
The system takes two inputs: a natural-language question and a context passage that is expected to contain the answer. Because the answer is sought within the supplied passage, a relevant passage is a precondition for a meaningful result.
The question and the context are read together by a language model that builds a joint representation of how the words of the question relate to the words of the passage. When the text uses specialised terminology, a model pretrained on or tuned to that domain is a candidate for this step; whether it improves accuracy for a given corpus should be checked on your own examples.
An extractive approach predicts the start and end positions of the span in the passage that answers the question and returns that exact text. A generative approach produces a free-form answer conditioned on the question and passage. Some models instead predict a one-word answer as a class, using a softmax over a predefined answer vocabulary. This variant works only when the set of possible answers is fixed in advance, and it differs from span extraction because the predicted answer is drawn from the vocabulary rather than copied from the passage. In each case the output is a natural-language answer.
Predicted answers are scored against reference answers, typically with exact match (EM), which counts a prediction as correct only if it equals the reference answer after normalisation, and F1, the harmonic mean of token-level precision and recall between prediction and reference. These are the standard measures on benchmarks such as SQuAD, and failure cases should be inspected before the system is relied on. For reference, the SQuAD paper reports an F1 of 51.0% for its logistic regression model, a significant improvement over a simple baseline of about 20%, and human performance of 86.8%.
Common pitfalls
- Supplying a passage that does not contain the answer pushes the model to guess, which can produce fluent but wrong responses.
- An extractive model predicts a span of the passage, so it returns one even when the passage contains no answer; test the system on questions whose answer is absent from the passage.
- Applying a general model to highly specialised terminology without checking its accuracy on that text can silently degrade results.
- Exact match and F1 are the normal measures for extractive answers. Generative answers can also be scored with F1, but a good overlap score does not show that the answer is faithful to the passage, so generative answers should be checked separately.
- Deploying without inspecting wrong answers hides systematic failure patterns that aggregate scores do not reveal.
Frequently asked questions
What is the difference between extractive and generative question answering?
An extractive approach finds and returns the exact span of text in the context that answers the question. A generative approach writes an answer in its own words, conditioned on the question and context. Extractive answers stay verbatim and are straightforward to score against the source; generative answers can read more naturally but may drift from the passage.
Do I always need a context passage?
In this method, yes. The system answers from a supplied passage that is expected to contain the answer. Without a relevant passage there is nothing for the model to ground its answer in, so the output cannot be checked against source text.
Should I use a domain-specific model?
If your text uses specialised terminology, it is worth testing a model suited to that domain against a general one on examples from your own corpus. For general text, a general-purpose model is often the starting point.
How is question-answering accuracy measured?
Predicted answers are compared with reference answers using exact match (EM), which requires the prediction to equal the reference after normalisation, and F1, which measures token overlap between prediction and reference as the harmonic mean of precision and recall. On SQuAD, the original logistic regression model reached an F1 of 51.0%, against about 20% for a simple baseline and 86.8% for human performance. Inspecting failure cases alongside these scores helps reveal systematic weaknesses before deployment.
Related methods
Sources
Rajpurkar, P. et al. (2016). SQuAD: 100,000+ Questions for Machine Comprehension of Text. EMNLP.
Open DOI referenceYang, Z. et al. (2019). XLNet: Generalized Autoregressive Pretraining for Language Understanding. NeurIPS.
Open publication reference[Fran_ois_Chollet_with_J.J._Allaire]_Deep_Learnin(z-lib.org), p. 229