RAG: retrieval-augmented generation

The RAG paper explores a general-purpose fine-tuning recipe for models that combine pre-trained parametric and non-parametric memory for language generation.

Verified

On this page

Definition

The paper explores a general-purpose fine-tuning recipe for retrieval-augmented generation (RAG), meaning models that combine pre-trained parametric and non-parametric memory for language generation. In the RAG models the paper introduces, the parametric memory is a pre-trained seq2seq model and the non-parametric memory is a dense vector index of Wikipedia, accessed with a pre-trained neural retriever. The paper compares two RAG formulations: one conditions on the same retrieved passages across the whole generated sequence, and the other can use different passages per token. It describes knowledge-intensive tasks as tasks that humans could not reasonably be expected to perform without access to an external knowledge source.

At a glance

The paper states that the retriever (Dense Passage Retriever, henceforth DPR) provides latent documents conditioned on the input, and the seq2seq model (BART) then conditions on these latent documents together with the input to generate the output.

  • The paper uses a pre-trained bi-encoder from DPR to initialize its retriever and to build the document index.
  • It refers to this document index as the non-parametric memory.
  • In the paper's Figure 1, a query uses Maximum Inner Product Search (MIPS) to find the top-K documents.
  • In RAG-Sequence, the model uses the same document to predict each target token.
  • RAG-Token can predict each target token based on a different document.

The source does not state the order of these points, so they are listed without arrows.

How it works

The paper marginalizes the latent documents with a top-K approximation, either per output, where the same document is responsible for the output's tokens, or per token, where different documents are responsible for different tokens. To train the retriever and generator end-to-end, it treats the retrieved document as a latent variable. For RAG-Sequence, the top K documents are retrieved using the retriever, and the generator produces the output sequence probability for each document, which are then marginalized.

For RAG-Token, the top K documents are retrieved using the retriever, and then the generator produces a distribution for the next output token for each document, before marginalizing and repeating the process with the following output token. RAG-Token allows the generator to choose content from several documents when producing an answer. When generating from BART, the paper simply concatenates the input with the retrieved content.

It trains the retriever and generator jointly, without direct supervision on what document should be retrieved. During training, the paper keeps the document encoder and index fixed and fine-tunes only the query encoder and the BART generator. The paper also states that the RAG-Token model can be seen as a standard autoregressive seq2seq generator with transition probability.

In its experiments, the paper splits each Wikipedia article into disjoint 100-word chunks, making a total of 21M documents. It uses the document encoder to compute an embedding for each document and builds a single MIPS index using FAISS with a Hierarchical Navigable Small World approximation. On NQ, the paper states, RAG can generate correct answers even when the correct answer does not appear among the retrieved documents, with 11.8% accuracy in such cases where an extractive model would score 0%.

The index hot-swapping test compares the 2016 and 2018 indices. The paper selects 82 world leaders who changed between those dates and uses a question template, such as "Who is the President of Peru?", to query its NQ RAG model with each index. The paper reports that RAG answers 70% correctly using the 2016 index for 2016 world leaders and 68% using the 2018 index for 2018 world leaders. The paper reports that accuracy with mismatched indices is low: 12% with the 2018 index and 2016 leaders, and 4% with the 2016 index and 2018 leaders.

In preliminary experiments, the paper observed that for some tasks such as story generation, the retrieval component would "collapse" and learn to retrieve the same documents regardless of the input. In these cases, once retrieval had collapsed, the generator would learn to ignore the documents, and the RAG model would perform equivalently to BART.

Example

The paper describes Jeopardy as an unusual format that consists of trying to guess an entity from a fact about that entity. The paper says Jeopardy questions often contain two separate pieces of information. The paper's Figure 2 uses the input Hemingway for Jeopardy generation with 5 retrieved documents.

When generating "Sun", the posterior is high for document 2, which mentions "The Sun Also Rises". Document 1 dominates the posterior when "A Farewell to Arms" is generated. After the first token of each book is generated, the document posterior flattens.

The paper says this observation suggests that the generator can complete the titles without depending on specific documents. In other words, the paper says, the model's parametric knowledge is sufficient to complete the titles. The paper says this example shows how parametric and non-parametric memories work together: the non-parametric component helps to guide the generation, drawing out specific knowledge stored in the parametric memory.

In the paper's Table 2, RAG-Token performs better than RAG-Sequence on Jeopardy question generation, and both models outperform BART on Q-BLEU-1. The paper reports human evaluation over 452 pairs of generations from BART and RAG-Token. Evaluators indicated that BART was more factual than RAG in only 7.1% of cases, while RAG was more factual in 42.7% of cases.

Sources

This page is written from the official sources below. Open them to check the original text.

Verified ·

This page is written by AI from the official sources above and checked automatically. This site has not tested it. Found a mistake? Tell us.