liveBook · Manning

Question answering

As explained in Natural Language Processing in Action, Second Edition

A question-answering system produces answers to questions expressed in natural language.

Question answering produces an answer to a natural-language question. A small FAQ bot can treat the task as search: match the user’s wording to a stored question, then return its paired response. section 3.7

A practical question-answering pipeline can combine these roles:

  • Index documents or questions with TF–IDF vectors or semantic embeddings. section 3.7 section 10.3.9
  • Retrieve documents likely to contain relevant information. section 10.3.9
  • Extract an answer from the retrieved context, or ask a generative model to synthesize one. section 10.3.10 section 10.3.11
  • Constrain generation to supplied sources and allow an explicit “I don’t know” response when the context is insufficient. section 10.3.11

FAQ matching with TF–IDF

Load question-and-answer pairs, fit scikit-learn’s TfidfVectorizer on the questions, transform a user query, and select the question with the largest dot product. A query such as “What’s overfitting a model?” retrieves “What is overfitting?” and returns its stored answer. Sparse or misspelled wording can produce poor matches. section 3.7

Retrieval-augmented answering

A Haystack pipeline can place an EmbeddingRetriever before a reader such as roberta-base-squad2, or connect retrieval to a generative PromptNode using flan-T5. Extractive QA works well when the answer is stated clearly; generation helps expand answers to more complicated why and how questions, but still needs grounding checks. section 10.3.9 section 10.3.11

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Explains matching, retrieval, extraction, and generation with runnable pipelines, but defers deeper model internals.
Examples
Uses data-science FAQs, book sentences, Haystack, TF–IDF, FAISS, BERT-based retrievers, and transformer readers.
What it assumes
Assumes Python and basic text-vectorization familiarity while introducing retrieval, embeddings, readers, and grounded generation.
What you can do after
Builds a basic FAQ matcher or configures a Haystack retrieval-and-reading pipeline.
How it connects
Connects information retrieval, semantic search, embeddings, extractive QA, and text generation.

Also explained in

Compare how 4 books explain question answering →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Natural Language Processing in Action, Second Edition. The section links point to the parts of the book it draws on.