liveBook · Manning

Reader

As explained in AI-Powered Search

A reader is a question-answering model or component that analyzes document context and predicts the answer span for a question.

A reader is the answer-extraction component in an extractive question-answering system. After a search engine retrieves likely documents, the reader analyzes each document context and predicts the most likely beginning and ending of the answer span. section 14.1.2 section 14.6

A practical reader pipeline works as follows:

  • Accept question-and-context pairs from the retriever. section 14.5.1
  • Run a fine-tuned question-answering model over every candidate context. section 14.5.2
  • Return an answer, confidence score, document identifier, and URL for each context. section 14.5.2
  • Compare candidate answers or use reader confidence to rerank retrieved documents. section 14.1.2

Minimalist shoes

For “What are minimalist shoes?”, the retriever supplies several document contexts. The reader identifies “shoes intended to closely approximate barefoot running conditions” as the answer span in the strongest context.

Listing 14.16 Reader function that incorporates our fine-tuned model
from transformers import pipeline

device = get_processor_device()
model_name = "data/question-answering/roberta-base-squad2-fine-tuned"
qa_nlp = pipeline("question-answering", model=model_name,  #1
                  tokenizer=model_name, device=device)  #1

def reader(contexts):
  answers = []
  for _, row in contexts.iterrows():  #2
    answer = qa_nlp({"question": row["question"],  #2
                     "context": row["context"]})  #2
    answer["id"] = row["id"]  #3
    answer["url"] = row["url"]  #3
    answers.append(answer)  #2
  return answers

The implementation loads a Transformers question-answering pipeline, applies it to each question and context, and attaches document metadata to the resulting answer. section 14.5.2

How AI-Powered Search covers it

How deep it goes
Explains span prediction, confidence scoring, pipeline integration, metadata handling, and holdout evaluation, but not model internals.
Examples
Uses minimalist-shoe definitions, outdoor question-answering pairs, retrieved document tables, and a ten-example holdout evaluation.
What it assumes
Assumes access to retrieved documents and a fine-tuned question-answering model, while demonstrating the reader interface from question and context inputs.
What you can do after
Build it with a Transformers pipeline that processes retrieved contexts and returns answer text, scores, identifiers, and URLs.
How it connects
Connects extractive question answering with retrievers, search engines, document ranking, fine-tuning, and answer reranking.

Also explained in

Compare how 2 books explain reader →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI-Powered Search. The section links point to the parts of the book it draws on.