task 04 / nlp
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)
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.
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.
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.
| model | EM | F1 | ci | HasAns F1 | NoAns acc | ood F1 | ece | mb | ms |
|---|---|---|---|---|---|---|---|---|---|
| bm25 best sentence | 0.2 | 9.8 | 20.0 | 0.0 | 10.2 | ||||
| distilbert (squad 1.1) | 57.0 | 58.5 | 57.2-59.7 | 50.9 | 65.6 | 53.9 | 0.448 / 0.052 | 249 | 92 |
| tinyroberta | 80.4 | 83.4 | 82.5-84.3 | 83.9 | 82.9 | 59.5 | 0.112 / 0.034 | 311 | 93 |
| roberta-base | 81.0 | 83.9 | 83.0-84.8 | 81.9 | 85.8 | 61.6 | 0.111 / 0.007 | 473 | 161 |
| deberta-v3-base | 85.1 | 88.4 | 87.6-89.1 | 87.1 | 89.6 | 63.1 | 0.079 / 0.012 | 701 | 312 |
| roberta-large | 86.0 | 89.0 | 88.3-89.7 | 87.9 | 90.1 | 63.6 | 0.089 / 0.018 | 1352 | 580 |
| minilmv2 + kd (ours) | 80.7 | 83.7 | 82.7-84.6 | 82.2 | 85.1 | 61.0 | 0.118 / 0.018 | 156 | 52 |
| minilmv2 + kd, int8 onnx | 80.1 | 83.1 | 81.2 | 85.0 | 61.0 | 39 | 21 |
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.
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.
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.
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.
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).
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.