Papers
Topics
Authors
Recent
Search
2000 character limit reached

REALM: Retrieval-Augmented Language Model

Updated 9 July 2026
  • REALM is a retrieval-augmented language model that decouples factual storage from neural parameters by retrieving supporting evidence from external corpora.
  • It uses a dense inner-product retriever and a separate reader Transformer to condition predictions on relevant passages, enhancing transparency.
  • REALM improves open-domain question answering by enabling interpretable, updateable knowledge through end-to-end unsupervised pre-training.

REALM, short for Retrieval-Augmented LLM Pre-Training, is a retrieve-then-predict framework that augments masked LLM pre-training with a learned, large-scale neural knowledge retriever operating over a corpus such as Wikipedia (Guu et al., 2020). Its central premise is that world knowledge need not be stored solely in neural parameters. Instead, REALM factorizes prediction into retrieval of latent supporting documents and conditional prediction given those documents, thereby making knowledge storage more modular and more inspectable while preserving end-to-end training. In the original formulation, the same retrieval mechanism is used during pre-training, fine-tuning, and inference, and the retriever itself is trained unsupervised from masked language modeling signals rather than from labeled retrieval supervision (Guu et al., 2020).

1. Motivation and problem setting

REALM was introduced against the background of large pretrained LLMs whose factual competence is encoded implicitly in parameters. That paradigm yields strong performance, but it ties knowledge coverage to parametric scale: storing more facts requires ever-larger networks, and updating knowledge often entails retraining. REALM decouples these roles by treating the corpus as the primary knowledge store and the neural model as the mechanism that learns what to retrieve and how to use it (Guu et al., 2020).

Three motivations are explicit. First, capacity and scaling: knowledge growth becomes a corpus-and-index problem rather than only a parameter-count problem. Second, interpretability: predictions are conditioned on retrieved passages whose content can be inspected as provenance for the answer. Third, modularity: updating the knowledge source can be done by refreshing the corpus and index, even though some facts may still remain memorized in the encoder (Guu et al., 2020).

The target use case is knowledge-intensive language understanding, especially open-domain question answering. REALM was evaluated on NaturalQuestions-Open, WebQuestions, and CuratedTrec, where answers depend on broad factual coverage rather than narrow task-specific pattern matching (Guu et al., 2020). In this setting, the method differs from heuristic retrieval pipelines that rely on BM25, TF-IDF, or entity linking to preselect a small candidate set, because REALM learns retrieval directly from masked language modeling and searches over millions of candidate passages via maximum inner product search (Guu et al., 2020).

2. Probabilistic formulation and model architecture

REALM formalizes both masked language modeling and open-domain QA with a latent retrieved document zz from a corpus Z\mathcal{Z}. For input xx and output yy, the model marginalizes over retrieved documents:

p(yx)=zZp(yz,x)p(zx).p(y \mid x) = \sum_{z \in \mathcal{Z}} p(y \mid z, x)\, p(z \mid x).

This decomposition yields two components. The first is a knowledge retriever p(zx)p(z \mid x) implemented as a dense inner-product retriever. Query xx and document zz are encoded by Transformer-based encoders ϕθ\phi_\theta and ψθ\psi_\theta, with relevance score

Z\mathcal{Z}0

The induced retrieval distribution is a softmax over the corpus:

Z\mathcal{Z}1

In practice, the denominator is approximated over top-Z\mathcal{Z}2 candidates returned by maximum inner product search, after which the model recomputes exact probabilities on that retrieved set (Guu et al., 2020).

The second component is a knowledge-augmented encoder Z\mathcal{Z}3, a separate Transformer that encodes the concatenation of the input and the retrieved passage so that cross-attention can bind them. During pre-training, REALM uses standard MLM decoding for masked tokens. If Z\mathcal{Z}4 indexes masked positions, then

Z\mathcal{Z}5

with each masked-token probability parameterized from the hidden state at the masked position. During QA fine-tuning, the answer is treated as an extractive span in a retrieved passage, scored by an MLP over start and end hidden states in the concatenated sequence Z\mathcal{Z}6 (Guu et al., 2020).

Architecturally, the retriever and reader are distinct. The retriever uses BERT-style Transformers, [CLS] pooled representations, and learned linear projections for both queries and documents. The reader is another Transformer specialized for conditioning on retrieved passages. This separation is important: retrieval quality and answer extraction are optimized jointly through marginal likelihood, but retrieval remains a latent decision rather than an externally fixed preprocessing stage (Guu et al., 2020).

3. Unsupervised retriever learning from masked language modeling

The defining technical contribution of REALM is that the retriever is pretrained end-to-end without retrieval labels. For MLM, the loss over masked positions is

Z\mathcal{Z}7

This objective treats retrieval as a latent variable and optimizes the marginal likelihood of the correct masked tokens (Guu et al., 2020).

The retriever receives gradient signal according to whether a document makes the prediction better than expected. An intuitive form given in the paper is

Z\mathcal{Z}8

where

Z\mathcal{Z}9

Documents that improve prediction relative to the marginal baseline receive positive updates; unhelpful documents are demoted (Guu et al., 2020). This is the core mechanism by which the masked LLM itself trains the retriever.

Several inductive biases make this objective workable at corpus scale. REALM uses salient span masking rather than random masking, focusing on named entities and dates identified by a BERT-based NER tagger and regex rules. The purpose is to place masked tokens in knowledge-heavy contexts where external retrieval is likely to matter. The model also includes a learned null document xx0 so that it can learn not to retrieve when local context suffices. When the pre-training corpus and knowledge corpus coincide, the exact source document of the masked input is excluded from retrieval candidates to prevent degenerate lookup behavior. To avoid a cold start, the query and document encoders are warm-started with the Inverse Cloze Task, and the knowledge-augmented encoder is warm-started from BERT-base uncased with 12 layers, hidden size 768, and 12 heads (Guu et al., 2020).

REALM also defines a retrieval-centric diagnostic:

xx1

This retrieval utility score measures how much a given document helps relative to the null document. The paper reports that retrieval utility increases steadily during pre-training and is more predictive of downstream QA performance than overall log-likelihood, which suggests that retrieval-specific learning quality is not fully captured by the standard MLM objective alone (Guu et al., 2020).

4. Knowledge store, indexing, and systems design

REALM’s knowledge store in the reported experiments is the English Wikipedia snapshot of December 20, 2018. Articles are split greedily into passages of up to 288 wordpieces, producing just over 13 million document blocks. Each block stores title and body, and the document encoder embeds the sequence [CLS title [SEP](https://www.emergentmind.com/topics/semantic-entropy-production-sep-metric) body SEP] (Guu et al., 2020).

Because document embeddings depend on the evolving retriever parameters, the index becomes stale during training. REALM addresses this with asynchronous index refresh. Two jobs run in parallel: a trainer updates retriever and reader parameters, while an index builder periodically receives a parameter snapshot, re-embeds all documents, and rebuilds the MIPS index. In the experiments, refreshes occur approximately every 500 training steps; more frequent refreshes stabilize optimization, while overly stale indices degrade performance (Guu et al., 2020).

The pre-training configuration is large but straightforward. REALM trains for 200k steps on 64 Cloud TPUs with batch size 512 and learning rate xx2 using BERT’s optimizer. Document embedding for index refresh is parallelized over 16 TPUs. During pre-training, the model marginalizes over xx3 retrieved candidates, including the null document. During QA inference, it considers the top-5 retrieved documents, and top-5 retrieval plus reading fits on a single 12GB GPU (Guu et al., 2020).

These engineering choices are integral rather than incidental. REALM depends on cached dense document vectors, approximate nearest-neighbor search for tractability, and exact recomputation of the retrieval distribution on the retrieved top-xx4 set. The method therefore occupies a specific systems niche: it is more complex than a pure parametric LLM, but it avoids the need to backpropagate through an explicit search over the entire corpus at each step (Guu et al., 2020).

5. Fine-tuning for open-domain question answering and empirical results

For open-domain QA, REALM treats the question as the query and predicts extractive spans from retrieved passages. In fine-tuning, the document-side encoder is typically fixed from pre-training, while the query encoder continues to be updated. The reader concatenates question and passage, predicts start and end positions with an MLP, and marginalizes over spans in the retrieved passages. At inference time, the system retrieves top-5 passages via MIPS and computes xx5 by marginalizing over them (Guu et al., 2020).

The reported exact-match test results on three benchmarks are as follows (Guu et al., 2020):

Model NQ WQ / CT
T5 (11B) 34.5 37.4 / —
ORQA 33.3 36.4 / 30.1
REALM (target = Wikipedia; unlabeled = Wikipedia) 39.2 40.2 / 46.8
REALM (target = CC-News; unlabeled = Wikipedia) 40.4 40.7 / 42.9

Across NaturalQuestions-Open, WebQuestions, and CuratedTrec, REALM improves absolute accuracy by 4–16 points over prior systems, while being roughly 30× smaller than T5-11B (Guu et al., 2020). The paper does not report TriviaQA results (Guu et al., 2020).

The qualitative case studies clarify what these gains mean. For the masked sentence “An equilateral triangle is easily constructed … because 3 is a [MASK] prime,” REALM retrieves a passage discussing Fermat primes and constructible regular polygons; the marginalized probability of “Fermat” increases from much less than xx6 without retrieval to approximately xx7 after marginalization over retrieved documents (Guu et al., 2020). This is not merely an accuracy improvement. It shows that the model can recover a fact by external evidence rather than by pure parameter memorization.

6. Interpretability, modularity, limitations, and later refinements

REALM’s most frequently cited qualitative properties are interpretability and modularity. Because predictions depend on retrieved passages, users can inspect supporting evidence. Because the knowledge store is external, updating the corpus can change model behavior without retraining the full network. The paper illustrates this by swapping a 2018 Wikipedia snapshot with a 2020 snapshot: the masked prompt about “Jennifer [MASK] formed the production company Excellent Cadaver” becomes solvable as “Lawrence” under the updated page set. At the same time, some facts remain memorized in the encoder, so corpus updates do not imply perfectly clean separation between parametric and non-parametric knowledge (Guu et al., 2020).

Several limitations are equally explicit. REALM requires building and refreshing a large ANN or MIPS index and repeatedly re-embedding millions of passages, which increases engineering complexity. Performance depends on corpus coverage and phrasing; missing or idiosyncratically expressed facts can still defeat retrieval. Approximate nearest-neighbor search and top-xx8 truncation introduce approximation error. Retrieval and reading add inference latency, although the reported setup keeps xx9 small. Finally, training is sensitive to design choices such as salient masking and refresh frequency; stale indices or weak masking policies degrade learning (Guu et al., 2020).

In the broader retrieval-augmented landscape, REALM occupies a specific historical position. Relative to heuristic sparse-retrieval systems such as DrQA, HardEM, GraphRetriever, and PathRetriever, it learns retrieval from MLM signal rather than from a separate heuristic pipeline. Relative to ORQA, it shares the latent-variable perspective and ICT initialization, but adds unsupervised end-to-end retriever pre-training with backpropagation through retrieval at corpus scale. Later retrieval-augmented generation models also marginalize over retrieved documents, but typically use seq2seq generation rather than REALM’s extractive reader; the original novelty lies in unsupervised dense-retriever pre-training through masked LM and scalable marginalization over latent retrieval (Guu et al., 2020).

A subsequent study, “Simple and Efficient ways to Improve REALM” (Balachandran et al., 2021), argued that the original fine-tuning regime was substantially undertrained. Without changing the model design, it improved performance by using exact MIPS during fine-tuning, larger batches via distributed training, stronger passage supervision from Natural Questions long answers, and much larger reader-side yy0 at inference. The resulting “REALM++” reached 44.8 EM on NQ, 45.6 on WQ, and 49.7 on CT, roughly a 5.5-point absolute gain over the original baseline configuration (Balachandran et al., 2021). This later result does not alter the conceptual identity of REALM, but it reinforces a central lesson of the original work: retrieval-augmented pre-training is highly sensitive to the interaction between retriever quality, reader capacity, supervision, and search configuration.

REALM therefore marks a transition in language-model design from purely parametric factual storage toward explicit, trainable access to external corpora. Its lasting significance is not only that it improved open-domain QA, but that it showed retrieval itself can be pretrained end-to-end and unsupervised, using masked language modeling as the learning signal for a latent document-selection policy at corpus scale (Guu et al., 2020).

Definition Search Book Streamline Icon: https://streamlinehq.com
References (2)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Realm.