A retrieve-and-read system answers questions by first finding likely source documents, then reading their text to extract the answer. The retriever uses search to rank candidate documents; the reader identifies the most likely answer span within them. section 14.1 section 14.1.2
A typical extractive question-answering pipeline proceeds as follows:
- Send the question to a search engine and retrieve ranked candidate documents. section 14.1.2
- Run the reader over the most relevant contexts and score possible answer beginnings and endings. section 14.6
- Rerank answers using reader confidence; repeated answers across contexts can provide an additional correctness signal. section 14.5.4
Minimalist shoes
For “What are minimalist shoes?”, the retriever finds a relevant document. The reader extracts “shoes intended to closely approximate barefoot running conditions” rather than returning the entire document. section 14.1.2
Listing 14.18 QA function combining retriever, reader, and reranker
def ask(question):
documents = retriever(question)
answers = reader(documents)
reranked = reranker(answers)
print_answer(question, reranked)
ask('What is the best mosquito repellent?')
ask('How many miles can a person hike day?')
ask('How much water does a person need per day?')
The implementation separates retrieval, reading, reranking, and answer display in a compact Python QA function. section 14.5.4
