Skip to content
AI360XpertBeta

Question Answering

Question answering turns a plain question into one exact answer. The system either points at the span in a given passage or writes the answer from what it learned.

Start scores peak at Ada 0.72 and end scores peak at Lovelace 0.68, so the span Ada Lovelace wins at 0.490 over every other span.
Start scores peak at Ada 0.72 and end scores peak at Lovelace 0.68, so the span Ada Lovelace wins at 0.490 over every other span.

Why Does This Exist?

Search lists force you to read ten pages to find one date or name. You asked when a platform launched, you get links, snippets and ads, and you still open each page. That gap is time lost on every lookup.

Question answering closes it by returning one span or one written answer. It reads the passage for you in closed-domain use, and it retrieves then reads in open-domain use across many docs.

This page covers the span-picking mechanism first, then where generation and retrieval fit. For finding candidate passages by meaning before reading, see sentence embeddings. For turning spans into linked records, see information extraction. For the language models that write generative answers, see language models.

The one idea you need first

A passage is split into tokens, and each token gets a position. Start and end scores are just two number lists over those positions. The full split treatment is in tokenization in NLP.

Think of It Like This

An open-book exam with one highlighter

You sit an open-book test with one chapter and one highlighter. You read the question, scan the chapter, and draw one line from the first answer word to the last answer word. You add no new words, you only point.

The chapter is the context passage. The question tells your eyes where to look. The highlighted line is the predicted span (i,j)(i, j).

Where it stops: you know when the chapter holds no answer and you leave the page blank. A basic span model does not, it highlights something anyway unless it is built to say no answer.

How It Actually Works

Extractive answering takes a question QQ and a passage of nn tokens w1,…,wnw_1, \ldots, w_n. A reader encodes question plus passage into vectors, then outputs two distributions: Pstart(i)P_{start}(i), the chance token ii starts the answer, and Pend(j)P_{end}(j), the chance token jj ends it. Here ii is a start index, jj is an end index, and each distribution sums to 1 over the passage.

The span score is the product:

P(i,j)=Pstart(i)×Pend(j)P(i, j) = P_{start}(i) \times P_{end}(j)

In plain words: how likely ii starts it times how likely jj ends it. Decoding picks the pair with the top product under i≤ji \le j and j−ij - i below a length cap, so the end cannot sit before the start and absurdly long spans are barred.

Worked example

Passage tokens: ["Ada", "Lovelace", "wrote", "first", "algorithm", "1843"]. Question: "Who wrote the first algorithm?" Suppose the model outputs start scores [0.72,0.08,0.05,0.05,0.05,0.05][0.72, 0.08, 0.05, 0.05, 0.05, 0.05] which sum to 1.001.00, and end scores [0.05,0.68,0.07,0.07,0.06,0.07][0.05, 0.68, 0.07, 0.07, 0.06, 0.07] which also sum to 1.001.00.

Check spans:

Span (0,1)(0, 1) "Ada Lovelace": 0.72×0.68=0.48960.72 \times 0.68 = 0.4896.

Span (1,1)(1, 1) "Lovelace": 0.08×0.68=0.05440.08 \times 0.68 = 0.0544.

Span (0,0)(0, 0) "Ada": 0.72×0.05=0.03600.72 \times 0.05 = 0.0360.

No other pair beats 0.48960.4896, because every other start is at most 0.080.08 and every other end is at most 0.070.07 outside the peak, giving at most 0.08×0.07=0.00560.08 \times 0.07 = 0.0056 when neither peak is used. Rounded to three decimals the winner is 0.4900.490, the same peak drawn above the diagram.

Where generation and retrieval fit

Generative answering drops the pointing rule and writes tokens one by one from the question plus optional context. It can fuse scattered clues and rephrase, but it can also invent a smooth false answer. Retrieval-augmented answering splits open-domain work in two: a light retriever finds the top KK passages by vector similarity, then the reader above extracts or the writer generates from those KK only. Retrieval decides what the reader gets to see, so a miss there can't be fixed downstream.

Code

This snippet finds the best valid span from the worked scores with only the standard library.

def best_span(s: list[float], e: list[float]) -> tuple[int, int, float]:    best: tuple[int, int, float] = (0, 0, -1.0)    for i in range(len(s)):        for j in range(i, len(e)):            v = s[i] * e[j]            if v > best[2]:                best = (i, j, v)    return best

s = [0.72, 0.08, 0.05, 0.05, 0.05, 0.05]e = [0.05, 0.68, 0.07, 0.07, 0.06, 0.07]b = best_span(s, e)print(b[0], b[1], round(b[2], 4))  # -> 0 1 0.4896

Watch Out For

Reading extraction as truth

An extractive model finds the span that best matches the question, not the span that is true. Give it a wrong passage and it still returns a confident highlight. The symptom is a clean span with a high product such as 0.490 on a passage that contradicts known facts. The fix is to check the source before trusting the span, and to track retrieval ids so every answer points back to the passage it came from.

Forcing an answer when none exists

Many span models always output some (i,j)(i, j) even when the passage holds no answer. The symptom is a guessed name on unanswerable questions with a middling score that looks passable. The fix is a no-answer threshold on the best product plus an empty-span option during training, so low peaks return no answer instead of a guess.

The Quick Version

  • Question answering returns one span or one written answer, not a list of links.
  • Extractive scoring multiplies start and end chances, and picks the top pair with start before end.
  • The worked passage picks Ada Lovelace at 0.72 times 0.68 equals 0.490, ahead of every other span.
  • Generative models write freely and can invent facts, so keep the source for checks.
  • Open-domain systems retrieve top passages first, and a retrieval miss cannot be fixed later.
  • Calibrate a no-answer option, because forcing a span on missing answers guarantees a wrong guess.