← all tasks

task 04 / nlp

question answering

ask about a text, get the answer highlighted, or be told it isn't there.

paste a text, ask a question about it, and the model highlights the answer in the text. if the answer isn't there, it says so instead of making something up. everything runs in your browser, nothing you type is uploaded.

1pick a text and ask it something

537 words · from wikipedia: Apollo 11, cc by-sa 4.0, shortened

2pick how to read it

reads the text from start to finish, in overlapping pieces, and picks the best answer anywhere in it. fine for a few paragraphs.

starting the model (only slow the first time)

how well does it work?

score on about 6,100 held-out questions from the SQuAD 2.0 validation set, about half of which have no answer in the text. 100 would be a perfect match with the human answers.

  • word matching9.8
  • older model42.4
  • this page (39 mb)83.1
  • mid-size model (500 mb)83.9
  • big model (1.4 gb)89.0

the model on this page scores 83.1, about 6 points below the big model it learned from, at about 1/34 of the file size. just matching words scores 9.8.

full results table+

SQuAD 2.0 validation, split by article: the no-answer threshold of every model was tuned on one half and the numbers below are on the other half (6,133 questions). ci = 95% bootstrap interval of F1. ood = F1 on three out-of-domain sets with the model forced to answer (not rerun for int8, that row repeats the PyTorch value). ece = calibration error of the confidence before / after a small logistic fit. latency is the median per question on 4 cpu threads.

modelEMF1ciHasAns F1NoAns accood F1ecembms
bm25 best sentence0.29.820.00.010.2
distilbert (squad 1.1)57.058.557.2-59.750.965.653.90.448 / 0.05224992
tinyroberta80.483.482.5-84.383.982.959.50.112 / 0.03431193
roberta-base81.083.983.0-84.881.985.861.60.111 / 0.007473161
deberta-v3-base85.188.487.6-89.187.189.663.10.079 / 0.012701312
roberta-large86.089.088.3-89.787.990.163.60.089 / 0.0181352580
minilmv2 + kd (ours)80.783.782.7-84.682.285.161.00.118 / 0.01815652
minilmv2 + kd, int8 onnx80.183.181.285.061.03921

details

what kind of question answering is this?+

it is “extractive”: the model never writes an answer, it only points at a stretch of the text you gave it. so it can't answer from general knowledge, and it can't combine two facts into a new sentence. in exchange the answer is always something you can check against the text.

how does it know when there is no answer?+

the model was trained on SQuAD 2.0, where about a third of the questions have no answer in their passage. next to every span it scores a special “no answer” option. if the best span doesn't beat that option by a margin, it abstains. the margin was tuned on one half of the validation articles and checked on the other half.

how was the small model made?+

a big model (roberta-large, 355M weights) already trained for this was used as a teacher. a small model (MiniLMv2, 40M weights) was trained to copy the teacher's start and end scores as well as the labelled answers. this is called knowledge distillation. the result was stored in 8 bits per weight to fit in about 39 mb and runs here with transformers.js.

how does whole-document mode work?+

the text is cut into overlapping chunks of about 100 words. a small search model (all-MiniLM-L6-v2, 22 mb) and plain word matching (BM25) both rank the chunks for your question, and the two rankings are added up. the best few chunks are read by the answer model, and the answer with the strongest score wins. the report compares the search methods and how much accuracy this loses against reading everything.

where does it fall short?+

it only knows the text in front of it, so questions that need adding up, comparing, or outside knowledge go wrong. it was trained on wikipedia paragraphs, so news, forums and very technical text are read less reliably. a confident wrong answer is possible, especially when the text names several similar things (two dates, two people).

report, code and model+

the full write-up with all experiments is in the report, the code is on github and the model on the hugging face hub. sample texts are shortened from wikipedia articles and shared under cc by-sa 4.0.