All papersFoundations Classic
RAG: let the model search before it answers Paper: Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks
Patrick Lewis, Ethan Perez, Aleksandra Piktus, Fabio Petroni, Vladimir Karpukhin, Naman Goyal, Heinrich Küttler, Mike Lewis, Wen-tau Yih, Tim Rocktäschel, Sebastian Riedel, Douwe Kiela · arXiv preprint (Facebook AI Research, University College London, New York University) · Posted 22 May 2020 · 14 min read · arXiv 2005.11401
1 The problem Show in original Language models store facts in their parameters . They cannot easily update or show where an answer came from. They sometimes hallucinate , which means they make things up. 44.5 exact match on Natural Questions for RAG-Sequence, a new best.
2 What they tested Show in original They joined a retriever with a text generator , and trained both together. The memory was a search index of 21M Wikipedia passages. They tested question answering, question writing and fact checking. They also tested swapping the index and removing parts. 3 What they found Show in original RAG set new bests on three open-domain QA tasks. RAG text was more factual, specific and diverse than BART. Learned retrieval beat keyword search on most tasks. Swapping the index updated the model's facts. In a chart RAG beats closed-book and open-book models on Natural Questions From Table 1 0 15 30 45 60 Exact match (EM) on Natural Questions test T5-11B (closed-book) 34.5 EM T5-11B+SSM (closed-book) 36.6 EM REALM 40.4 EM DPR 41.5 EM RAG-Token 44.1 EM RAG-Sequence 44.5 EM
Hover, tap or focus a bar to read its exact value.
Show as table Model Exact match T5-11B (closed-book) 34.5 T5-11B+SSM (closed-book) 36.6 REALM 40.4 DPR 41.5 RAG-Token 44.1 RAG-Sequence 44.5
5 Watch out Show in original Wikipedia is never fully factual and carries bias. Retrieval can collapse and return the same passages every time. RAG still produced wrong text sometimes. Results use one December 2018 Wikipedia dump. Jump to A The abstract1 Introduction2 Methods2.1 Models: RAG-Sequence and RAG-Token2.2 Retriever: DPR2.3 Generator: BART2.4 Training2.5 Decoding3 Experiments4 Results4.5 Additional results5 Related work6 DiscussionB Broader impactA-I Appendices A to I (summary)W Words to knowEvery detail from the paper Cards follow the paper's own order. Dotted words link to Words to know. Numbers match the paper.
A The abstract Show in original The problem Large pre-trained models store facts in their parameters. They do well when fine-tuned on tasks. But they are limited at reaching and using knowledge precisely. On knowledge-heavy tasks they lag task-specific systems. Giving the source of a decision and updating world knowledge are open problems. Earlier models with a search memory only did extractive tasks. The method They explore a general fine-tuning recipe: retrieval-augmented generation (RAG). RAG joins parametric memory with non-parametric memory . The parametric memory is a pre-trained seq2seq model. The non-parametric memory is a dense vector index of Wikipedia. A pre-trained neural retriever reads the index. They compare two forms. One uses the same passages for the whole output. The other can use different passages for each token. The results They set a new best on three open-domain QA tasks. They beat parametric seq2seq models and task-specific retrieve-and-extract systems. For language generation, RAG output is more specific, diverse and factual than a parametric-only baseline. 1 Introduction Show in original The setting Pre-trained language models learn a lot of knowledge from data. They act as a parameterized implicit knowledge base. They cannot easily expand or revise their memory. They cannot easily explain their predictions. They may produce 'hallucinations'. Hybrid models Hybrids join parametric memory with retrieval-based memory. Knowledge can be revised and expanded directly. Accessed knowledge can be inspected. REALM and ORQA joined masked language models with a trainable retriever. They tested only open-domain extractive question answering. This paper The authors bring hybrid memory to seq2seq models, the 'workhorse of NLP'. The parametric memory is a pre-trained seq2seq transformer. The non-parametric memory is a dense vector index of Wikipedia. The retriever is Dense Passage Retriever (DPR). The generator is BART. They train everything end to end as one probabilistic model. The retrieved passages are a latent variable, summed out over the top K. Two ways to sum Per output: the same passage is responsible for all tokens. Per token: different passages are responsible for different tokens. Like T5 or BART, RAG fine-tunes on any seq2seq task. Both the generator and the retriever are learned together. Earlier work Earlier systems added memory but trained from scratch for one task. Examples: memory networks, stack-augmented networks and memory layers. Here both memories are pre-trained and pre-loaded with knowledge. So the access ability is already there, and it needs no new training for access. Findings Knowledge-intensive tasks are ones people could not do without an outside source. RAG sets bests on open Natural Questions, WebQuestions and CuratedTrec. It strongly beats models with special pre-training on TriviaQA. Free generation beats earlier extractive models, even on extractive tasks. On MS-MARCO and Jeopardy question generation, RAG is more factual, specific and diverse than BART. On FEVER fact checking it is within 4.3% of the best pipeline models. The non-parametric memory can be replaced to update the model's knowledge. Code Code is open-sourced in the HuggingFace Transformers library. An interactive demo is at huggingface.co/rag. 2 Methods Show in original Overview RAG uses an input x to fetch text passages z. It uses them as extra context to write the target y. It has two parts. A retriever p_η(z|x) with parameters η gives top-K distributions over passages. A generator p_θ(y_i | x, z, earlier tokens) writes the next token. How RAG answers a question From Figure 1 Query encoder reads the question Search the index (MIPS) Take the top K passages BART reads question and passage Sum answers over passages The passage is a latent variable. No one labels which passage is right.
Training idea To train the retriever and generator together, passages are a latent variable. They propose two ways to marginalize, meaning to sum over passages. 2.1 Models: RAG-Sequence and RAG-Token Show in original RAG-Sequence It uses the same passage to write the whole sequence. The passage is one latent variable, summed out by the top-K estimate. The retriever finds the top K passages. The generator gives a sequence probability for each passage. These are then combined. RAG-Token It can draw a different passage for each target token. So the generator can use several passages in one answer. For each token, it gets a next-token distribution per passage. It then combines them and repeats for the next token. Classification RAG can classify too. The class is a target sequence of length one. Then RAG-Sequence and RAG-Token are the same. 2.2 Retriever: DPR Show in original Design The retriever is based on DPR, a bi-encoder. A BERT BASE document encoder makes d(z), a vector for each passage. A query encoder, also BERT BASE, makes q(x). Finding the top-k passages is a Maximum Inner Product Search problem. It can be solved approximately in sub-linear time. Setup A pre-trained DPR bi-encoder starts the retriever and builds the index. It was trained to find passages that hold answers to TriviaQA and Natural Questions. The document index is the non-parametric memory. 2.3 Generator: BART Show in original Design The generator can be any encoder-decoder. They use BART-large, a pre-trained seq2seq transformer with 400M parameters. To mix the input x with passage z, they simply join them. BART was pre-trained with a denoising goal and many kinds of noise. It beat T5 models of similar size on many generation tasks. The BART parameters θ are the parametric memory. 2.4 Training Show in original How RAG is trained From Section 2.4 Pair inputs with target outputs No labels for which passage Keep document encoder fixed Fine-tune query encoder and BART Minimize negative log-likelihood Training uses stochastic gradient descent with Adam.
Details They train the retriever and generator together. There is no direct supervision on which passage to retrieve. The loss is the negative marginal log-likelihood of each target. Updating the document encoder is costly. It forces periodic re-indexing, as REALM does. They found this unnecessary for strong results. So the document encoder and index stay fixed. They fine-tune only the query encoder BERT_q and the BART generator. 2.5 Decoding Show in original RAG-Token It is a standard autoregressive seq2seq generator. Its next-token chance sums over the top-k passages. You can plug it into a standard beam decoder. RAG-Sequence The likelihood does not split by token. So one beam search will not do. They run a beam search for each passage. Each guess is scored with the generator. To rate a guess missing from some beams, they run extra forward passes. They multiply by the retriever chance and sum across beams. This is 'Thorough Decoding'. It can be costly for long outputs. 'Fast Decoding' assumes zero chance for guesses not seen in beam search. This avoids the extra forward passes. 3 Experiments Show in original The knowledge source One Wikipedia dump: December 2018. Each article is cut into disjoint 100-word chunks. That gives 21M documents. The document encoder embeds each one. They build one MIPS index with FAISS and a Hierarchical Navigable Small World approximation. In training they fetch the top k documents. They try k of 5 and 10. They set k at test time using dev data. 3.1 Open-domain question answering Questions and answers are input-output text pairs. They train RAG by minimizing the negative log-likelihood of answers. They compare with extractive QA, which pulls answer spans from passages. They also compare with closed-book QA, which generates answers without retrieval. Data sets: Natural Questions, TriviaQA, WebQuestions and CuratedTrec. CT and WQ are small. They start from the trained NQ RAG model, as DPR does. They use the same splits as prior work and report Exact Match. For TriviaQA, they also use the TQA Wiki test set, to compare with T5. 3.2 Abstractive question answering RAG can answer with free-form text. They test on MSMARCO NLG v2.1. It has questions, ten gold passages each, and a full sentence answer. They do not use the gold passages. They treat it as open-domain abstractive QA. Some questions cannot be answered without the gold passages. Example: 'What is the weather in Volcano, CA?' So scores will be lower. Some questions cannot be answered from Wikipedia alone. RAG then relies on its parametric knowledge. 3.3 Jeopardy question generation The task Jeopardy asks you to guess an entity from a fact about it. Here the model writes the question from the answer entity. These are precise, factual statements. That makes a harder test. Example answer: 'The World Cup'. The setup They use SearchQA splits: 100K train, 14K dev and 27K test. They train a BART model as a baseline. The metric is SQuAD-tuned Q-BLEU-1, which weights entity matches more. They also run two human tests, for factuality and for specificity. Factuality: can trusted outside sources support a statement. Specificity: a strong link between input and output. Judges see an answer and two questions, one from BART and one from RAG. They pick A, B, both good or neither good. 3.4 Fact verification (FEVER) FEVER asks if Wikipedia supports, refutes or lacks info on a claim. It joins retrieval with a hard reasoning task. They map the 3 labels to single tokens and train on claim-label pairs. They use no supervision on retrieved evidence. Many real uses lack such signals. They test 3-way (supports, refutes, not enough info) and 2-way (supports, refutes). They report label accuracy. 4 Results Show in original 4.1 Open-domain question answering What they found On all four tasks RAG sets a new best. For TriviaQA the best applies only on the T5-comparable split. RAG mixes the freedom of closed-book models with the strength of open-book models. It needs no costly 'salient span masking' pre-training, unlike REALM and T5+SSM. Its retriever starts from DPR, which had retrieval supervision on NQ and TriviaQA. It matches the DPR QA system without a re-ranker or an extractive reader. Why generating helps Documents with clues but no verbatim answer can still help. Extractive models cannot use them. RAG can answer correctly when no retrieved passage has the answer. It gets 11.8% accuracy in such cases on NQ. An extractive model gets 0%. RAG leads on Natural Questions From Table 1 0 15 30 45 60 Exact match (EM) on Natural Questions test T5-11B (closed-book) 34.5 EM T5-11B+SSM (closed-book) 36.6 EM REALM 40.4 EM DPR 41.5 EM RAG-Token 44.1 EM RAG-Sequence 44.5 EM
Hover, tap or focus a bar to read its exact value.
Show as table Model Exact match T5-11B (closed-book) 34.5 T5-11B+SSM (closed-book) 36.6 REALM 40.4 DPR 41.5 RAG-Token 44.1 RAG-Sequence 44.5
Model NQ TQA (std / Wiki) WQ / CT T5-11B (closed-book) 34.5 - / 50.1 37.4 / - T5-11B+SSM (closed-book) 36.6 - / 60.5 44.7 / - REALM (open-book) 40.4 - / - 40.7 / 46.8 DPR (open-book) 41.5 57.9 / - 41.1 / 50.6 RAG-Token 44.1 55.2 / 66.1 45.5 / 50.0 RAG-Sequence 44.5 56.8 / 68.0 45.2 / 52.2
Table 1: open-domain QA test scores (exact match)
WQ is WebQuestions. CT is CuratedTrec. For TQA, the first number is the standard test set and the second is the TQA-Wiki test set.
4.2 Abstractive question answering RAG-Sequence beats BART on Open MS-MARCO NLG by 2.6 Bleu and 2.6 Rouge-L. It nears the best models, which use gold passages. Those models also face questions that are unanswerable without those passages. RAG hallucinates less and gives factual text more often than BART. Table 3 in the paper shows example answers. 4.3 Jeopardy question generation Scores RAG-Token does better than RAG-Sequence. Both beat BART on Q-BLEU-1. Human tests They compared 452 pairs of BART and RAG-Token output. BART was more factual in only 7.1% of cases. RAG was more factual in 42.7%. Both were factual in a further 17%. RAG was also found more specific by a large margin. Judgment Factuality Specificity BART better 7.1% 16.8% RAG better 42.7% 37.4% Both good 11.7% 11.8% Both poor 17.7% 6.9% No majority 20.8% 20.1%
Table 4: human assessment on Jeopardy
4.4 Fact verification For 3-way classification, RAG is within 4.3% of the best. That best model uses a complex pipeline with strong retrieval supervision. For 2-way classification, it is within 2.7% of a RoBERTa model. That model gets the gold evidence sentence. RAG got only the claim. The top retrieved document comes from a gold article in 71% of cases. A gold article is in the top 10 in 90% of cases. Model Jeopardy B-1 / QB-1 MSMARCO R-L / B-1 FEVER-3 / FEVER-2 SotA - / - 49.8* / 49.9* 76.8 / 92.2* BART 15.1 / 19.7 38.2 / 41.6 64.0 / 81.1 RAG-Token 17.3 / 22.2 40.1 / 41.5 72.5 / 89.5 RAG-Sequence 14.7 / 21.4 40.8 / 44.2 72.5 / 89.5
Table 2: generation and classification test scores
A star means the model uses gold context or evidence. FEVER scores are the same for both RAG models, as it is a classification task.
4.5 Additional results Show in original Generation diversity They measure diversity as distinct n-grams over total n-grams. RAG-Sequence is more diverse than RAG-Token. Both are much more diverse than BART, with no diversity-boosting decoding. RAG writes more varied Jeopardy questions than BART From Table 5 0 25 50 75 100 Ratio of distinct to total tri-grams (%) BART 32.4% RAG-Token 46.8% RAG-Sequence 53.8% Gold (human) 90.0%
Hover, tap or focus a bar to read its exact value.
Show as table Model Distinct tri-grams (%) BART 32.4 RAG-Token 46.8 RAG-Sequence 53.8 Gold (human) 90.0
Model MSMARCO Jeopardy QGen Gold 89.6% 90.0% BART 70.7% 32.4% RAG-Token 77.8% 46.8% RAG-Sequence 83.5% 53.8%
Table 5: ratio of distinct to total tri-grams
Retrieval ablations They freeze the retriever during training to test learned retrieval. Learned retrieval improves results on all tasks. They also swap in BM25, a word-overlap retriever. BM25 scores are used as logits for p(z|x). On FEVER, BM25 does best. FEVER claims are heavy on entities, which suits word overlap. On other tasks, trainable retrieval helps. It is crucial for open-domain QA. Learned retrieval beats BM25 and frozen retrieval From Table 6 BM25 Frozen Learned
0 15 30 45 60 Exact match, dev set (RAG-Sequence) NQ 31.8 EM 41.2 EM 44.0 EM TQA 44.1 EM 52.1 EM 55.8 EM WQ 36.6 EM 41.8 EM 44.9 EM CT 33.8 EM 52.6 EM 53.4 EM
Hover, tap or focus a bar to read its exact value.
Show as table Task BM25 (EM) Frozen (EM) Learned (EM) NQ 31.8 41.2 44.0 TQA 44.1 52.1 55.8 WQ 36.6 41.8 44.9 CT 33.8 52.6 53.4
Model NQ / TQA WQ / CT FVR-3 / FVR-2 RAG-Token-BM25 29.7 / 41.5 32.1 / 33.1 75.1 / 91.6 RAG-Sequence-BM25 31.8 / 44.1 36.6 / 33.8 75.1 / 91.6 RAG-Token-Frozen 37.8 / 50.1 37.1 / 51.1 72.9 / 89.4 RAG-Sequence-Frozen 41.2 / 52.1 41.8 / 52.6 72.9 / 89.4 RAG-Token 43.5 / 54.8 46.5 / 51.9 74.5 / 90.6 RAG-Sequence 44.0 / 55.8 44.9 / 53.4 74.5 / 90.6
Table 6: ablations on the dev set (exact match)
Both RAG forms share one FEVER score, as it is a classification task. Jeopardy and MSMarco columns are in the paper.
Index hot-swapping Parametric-only models need more training to update their facts. They built an index from the DrQA Wikipedia dump of December 2016. They compared it to the December 2018 index. They listed 82 world leaders who changed between these dates. They asked 'Who is {position}?' to an NQ RAG model. With the 2016 index, 70% were right for 2016 leaders. With the 2018 index, 68% were right for 2018 leaders. Mismatched indices scored low: 12% and 4%. So replacing the non-parametric memory updates the model's knowledge. Effect of retrieving more documents Models trained with 5 or 10 passages show no big difference. At test time you can change how many passages you fetch. More passages always help RAG-Sequence on open-domain QA. RAG-Token peaks at 10 retrieved passages. More passages raise Rouge-L for RAG-Token, at a cost to Bleu-1. The effect is smaller for RAG-Sequence. 6 Discussion Show in original What they showed They built hybrid models with parametric and non-parametric memory. RAG reaches the best results on open-domain QA. People prefer its output to parametric-only BART, as more factual and specific. They studied the learned retriever in depth. They showed the index can be hot-swapped with no retraining. Future work Maybe both parts could be pre-trained together from scratch. The work opens questions on how the two memories interact. B Broader impact Show in original Benefits RAG is grounded in real facts from Wikipedia. It hallucinates less. It offers more control and interpretability. Examples: a medical index for medical questions, or help for people to be more informed. Risks No outside knowledge source is fully factual or free of bias. RAG can act as a language model. So GPT-2 type concerns apply, to a lesser extent. It could make fake news, impersonate people or automate spam. It may also help automate jobs. AI systems could be used to fight such misuse. A-I Appendices A to I (summary) Show in original Implementation details QA test numbers: 15 passages for RAG-Token, 50 for RAG-Sequence. QA uses Thorough Decoding and greedy decoding. MS-MARCO and Jeopardy use ten passages, beam size four and Fast Decoding. They train a BART-large baseline for these two tasks. Human evaluation and training setup Judges were shown two answers in random order, plus some gold checks. Two annotators did poorly on gold checks and were removed. Training used Fairseq on 8 NVIDIA V100 GPUs with 32GB each. FAISS search runs on CPU. The full index needs about 100 GB of CPU memory. A compressed index needs 36GB. Open-domain QA details NQ and WQ use each (question, answer) pair separately in training. TriviaQA answers are filtered if they do not appear in the passages. CuratedTrec answers are regular expressions. They fetch the top 1000 documents and use the most common match. TQA scores are much higher on the official Wiki test set. The open-domain test set gives lower scores. FEVER and null document FEVER: they re-generate the claim, then classify from the final hidden state. They did not tackle the evidence extraction sub-task. They tried a 'null document' idea, to cover cases with no useful passage. Parameters RAG has 110M parameters for each BERT-base encoder, though the document encoder is not trained. BART-large has 406M parameters. The trainable total is 626M. T5-large has 770M parameters and scores 28.9 EM on NQ, far below 44.5 for RAG-Sequence. The index holds 21M vectors of 728 dimensions, which is 15.3B values. Retrieval collapse In story generation, retrieval 'collapsed' and always gave the same passages. The generator then ignored them, and RAG matched BART. Causes may be a weak need for facts, or long targets with weak gradients. Data set sizes Table 7 lists train, dev and test counts. Examples: Natural Questions 79169, 8758 and 3611. MS-MARCO has 153726 train and 12468 dev instances. Words to know Maximum Inner Product Search: Finding the stored vectors that best match a query vector.Non-parametric memory: Facts stored outside the model, such as in a search index.Parametric memory: Facts stored inside the weights of a model.RAG: A model that searches a text index, then writes using what it found.Ask AI about this paper Stuck on a word or an idea? Ask in plain words. The answer comes from the write-up on this page.
Ask AI about this paper Explain it like I am new to AI How would a finance team use this? What are the limits?
Jump to