REALM

Also known as: Retrieval-Augmented Language Model pre-training

On this page 7

REALM (Retrieval-Augmented Language Model pre-training) is a method that trains a neural knowledge retriever together with a masked language model, so that the model learns to fetch relevant documents from a large corpus and use them as evidence when predicting missing words. Within retrieval & knowledge research in artificial intelligence, REALM was one of the first systems to show that retrieval can be learned end to end during pre-training, using only the language modeling signal and no labeled retrieval data.

Introduced by Google Research in 2020, REALM addressed a basic weakness of large language models: their knowledge is stored implicitly in parameters, which makes it hard to inspect, expensive to expand and impossible to update without retraining. REALM moves much of that knowledge into an explicit, swappable text corpus and lets the network decide which passages matter.

How REALM retrieves and predicts

REALM works by treating the retrieved document as a latent variable: for an input x, the model retrieves a document z with probability p(z | x) and then predicts the output y with probability p(y | z, x). The final prediction marginalizes over the retrieved documents, so documents that help prediction receive more probability mass over time.

Two components implement this. The knowledge retriever is a BERT-style bi-encoder that embeds the query and every document into the same vector space and scores them by inner product. The knowledge-augmented encoder is a second transformer that reads the input concatenated with one retrieved document and fills in the masked tokens or extracts an answer span.

ComponentArchitectureRole
Knowledge retrieverBERT bi-encoderScores documents by embedding inner product
Document indexPrecomputed embeddings of about 13 million passagesEnables fast maximum inner product search
Knowledge-augmented encoderBERT cross-encoder over query and documentPredicts masked tokens or answer spans
Null documentEmpty placeholder passageHandles inputs that need no retrieval
Main components of REALM

Because the sum over all documents is intractable, REALM approximates it with the top-k documents, about eight during pre-training, found by maximum inner product search (MIPS). Gradients flow back into the query encoder through the retrieval probabilities, which is what makes the retriever trainable by the language modeling loss.

Pre-training techniques that make it work

Learning a retriever from an unsupervised signal is unstable, so REALM depends on several specific techniques. The most important is the asynchronous index refresh: document embeddings are recomputed by a separate job every few hundred training steps, because re-embedding millions of passages after every update is impossible.

TechniqueProblem it solvesEffect
Asynchronous index refreshStale document embeddingsKeeps MIPS results close to current model
Salient span maskingMasked words rarely need world knowledgeMasks named entities and dates instead
Inverse Cloze Task warm startRandom retriever gives no learning signalStarts retrieval from a useful state
Excluding trivial retrievalsModel copies the source sentenceForces genuine evidence use
Null documentSome tokens need no knowledgeAvoids forcing irrelevant passages
Techniques used in REALM pre-training

Salient span masking deserves emphasis. Ordinary random masking hides words such as articles or verbs that the encoder can guess from syntax alone, which gives the retriever no reason to improve. Masking entities and dates forces the model to look up facts, which creates the gradient that teaches retrieval.

Fine-tuning for open-domain question answering

After pre-training, REALM is fine-tuned for open-domain question answering, where the system must answer a question using a large corpus such as English Wikipedia without being given the relevant passage. The document embeddings are usually frozen at this stage, and only the query encoder and the reader are updated.

In the original evaluation, REALM outperformed much larger closed-book models. With about 330 million parameters, it exceeded the exact-match accuracy of an 11-billion-parameter T5 model on the NaturalQuestions-Open benchmark, reaching roughly 40 percent exact match. The comparison illustrated that explicit retrieval can substitute for model size on knowledge-intensive tasks.

REALM compared with later retrieval-augmented models

REALM belongs to a family of retrieval-augmented architectures that differ mainly in when the retriever is trained and how the generator consumes evidence. The table places REALM among its closest successors and predecessors.

ModelRetriever trainingReader or generatorTypical use
ORQAInverse Cloze Task, then question answeringExtractive BERT readerOpen-domain question answering
REALMJoint with masked language modelingExtractive BERT readerPre-training plus question answering
Dense passage retrievalSupervised on question-passage pairsSeparate extractive readerStrong standalone retriever
RAGFine-tuned query encoder, fixed documentsSeq2seq generatorGenerative answers and RAG pipelines
RETROFrozen retriever, chunk-levelDecoder with cross-attentionLarge-scale language modeling
REALM among related retrieval-augmented models

Modern RAG pipelines in production rarely train the retriever jointly; they combine an off-the-shelf embedding model, a vector index and a large generative model. REALM remains important because it demonstrated the latent-retrieval objective and the index-refresh technique on which many later systems build.

Limitations and practical constraints

The main limitation of REALM is training cost and engineering complexity. Refreshing embeddings for millions of documents requires a separate cluster running in parallel with training, and the retriever can drift if the refresh interval is too long. Few teams outside large laboratories can reproduce full REALM pre-training.

  • Extractive answers only: the original reader selects spans and cannot compose long answers.
  • Single-document reading: each passage is processed separately, which hampers multi-hop retrieval.
  • Fixed passage length: documents are cut into blocks of about 288 word pieces.
  • Corpus dependence: answers are only as current and accurate as the indexed text.

A frequent misconception is that REALM eliminates hallucination. Retrieval reduces unsupported answers on factual questions, but the reader can still pick a wrong span from a misleading passage, and the retriever can return plausible but irrelevant evidence.

Put simply

Think of a student who may bring a library card to an exam. Before answering, the student looks up a few pages. Over many practice tests, the student learns which books are worth opening.

REALM teaches a language model to do the same. The model learns two skills at once: finding useful pages and reading them to fill in the answer. Its knowledge sits in a large collection of text, not only in its memory. That makes it easier to check and update.

In practice

A research group at a national library wants a question answering system over two million digitized encyclopedia articles in its archive. A closed-book model trained on general web text answers many historical questions incorrectly, and retraining it whenever the archive grows is too expensive.

The group follows the REALM design. It warms up a bi-encoder retriever with the Inverse Cloze Task, then continues pre-training with salient span masking on names and dates from the archive, refreshing the embedding index every 500 steps on a separate set of accelerators. It then fine-tunes the reader on 8,000 question-answer pairs written by librarians.

The resulting system returns an answer together with the passage it used as evidence, which librarians can verify in seconds. When 50,000 new articles arrive, the group only re-embeds and adds them to the index instead of retraining the whole model.