Papers › Improving language models by retrieving from trillions of tokens

Improving language models by retrieving from trillions of tokens

8 Dec 2021arXiv:2112.04426archive 2025-07-28

Sebastian Borgeaud, Arthur Mensch, Jordan Hoffmann, Trevor Cai, Eliza Rutherford, Katie Millican, George van den Driessche, Jean-Baptiste Lespiau, Bogdan Damoc, Aidan Clark, Diego de Las Casas, Aurelia Guy, Jacob Menick, Roman Ring, Tom Hennigan, Saffron Huang, Loren Maggiore, Chris Jones, Albin Cassirer, Andy Brock, Michela Paganini, Geoffrey Irving, Oriol Vinyals, Simon Osindero, Karen Simonyan, Jack W. Rae, Erich Elsen, Laurent SIfre

We enhance auto-regressive language models by conditioning on document chunks retrieved from a large corpus, based on local similarity with preceding tokens. With a $2$ trillion token database, our Retrieval-Enhanced Transformer (RETRO) obtains comparable performance to GPT-3 and Jurassic-1 on the Pile, despite using 25× fewer parameters. After fine-tuning, RETRO performance translates to downstream knowledge-intensive tasks such as question answering. RETRO combines a frozen Bert retriever, a differentiable encoder and a chunked cross-attention mechanism to predict tokens based on an order of magnitude more data than what is typically consumed during training. We typically train RETRO from scratch, yet can also rapidly RETROfit pre-trained transformers with retrieval and still achieve good performance. Our work opens up new avenues for improving language models through explicit memory at unprecedented scale.

PaperPDFCodeCode Syntology ran

In Syntology Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, Syntology's MCP tool lists every function and class Syntology harvested from this paper and whether it ran (how to connect): get_harvested_code_for_paper(arxiv_id="2112.04426")

Code

Syntology Ran 16 of 23 code samples harvested from 2 repositories linked to this paper; 7 have no recorded run. Of those that ran: 3 ran · violated contract; 2 ran · our draft was wrong; 11 ran with no contract checked.

By repository: community (archive-listed): 20 samples from 2 repositories, 13 ran; 3 identical to code first harvested elsewhere. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

lucidrains/RETRO-pytorch mentioned on GitHubpytorch report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

23 samples harvested; 16 ran; 0 honoured the contract we drafted; 7 have no recorded run. Read from Syntology's graph 2026-09-24; that is when this build read the record, not when the samples ran.

3ran · violated contract
2ran · our draft was wrong
11ran
7unverified

Licence: 3 of the 23 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from 2 repositories linked to this paper, official or community; each sample names its own and says which. Some samples are identical code Syntology first harvested from another repository; for those, this paper's copy is not located and its licence is not recorded. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself; “our draft was wrong” and “fixture could not drive it” are failures of Syntology's instrument, not of the code.

Each sample ends with its code_sha256, Syntology's identity for that exact code. An agent fetches the stored sample with Syntology's MCP tool get_code(code_sha256="…") (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted. community: Not in the archive's code links for this paper; a community repository Syntology harvested. Samples from a repository marked official are listed first. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of four reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; or the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar). Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

Attention lucidrains/RETRO-pytorch/retro_pytorch/retro_pytorch.py community (archive-listed) ran · metamorphic tier: deterministic Apache-2.0 (permissive) · 03b81e2f9a4d2d4c · report
ChunkedCrossAttention labmlai/annotated_deep_learning_paper_implementations/labml_nn/transformers/retro/model.py community (archive-listed) ran · metamorphic tier: invariant MIT (permissive) · f393e5da1f357aea · report
CrossAttention labmlai/annotated_deep_learning_paper_implementations/labml_nn/transformers/retro/model.py community (archive-listed) ran · metamorphic tier: invariant MIT (permissive) · c3e56d6f2af858c1 · report
FeedForward lucidrains/RETRO-pytorch/retro_pytorch/retro_pytorch.py community (archive-listed) ran · metamorphic tier: deterministic Apache-2.0 (permissive) · 38be50d72d5874d6 · report
FeedForward labmlai/annotated_deep_learning_paper_implementations/labml_nn/transformers/retro/model.py community (archive-listed) ran · metamorphic tier: invariant MIT (permissive) · 1fae1fc6f059aacd · report
PostNorm lucidrains/RETRO-pytorch/retro_pytorch/retro_pytorch.py community (archive-listed) ran · metamorphic tier: deterministic Apache-2.0 (permissive) · 562d2542a1eaacef · report
PreNorm lucidrains/RETRO-pytorch/retro_pytorch/retro_pytorch.py community (archive-listed) ran · metamorphic tier: deterministic Apache-2.0 (permissive) · f44be7c955b39fa2 · report
RMSNorm lucidrains/RETRO-pytorch/retro_pytorch/retro_pytorch.py community (archive-listed) ran · metamorphic tier: deterministic Apache-2.0 (permissive) · a4ae5f96225b96f3 · report
RotaryEmbedding lucidrains/RETRO-pytorch/retro_pytorch/retro_pytorch.py community (archive-listed) ran · metamorphic tier: well formed Apache-2.0 (permissive) · 9fbc41d552de00c6 · report
RotaryPositionalEmbeddings labmlai/annotated_deep_learning_paper_implementations/labml_nn/transformers/retro/model.py community (archive-listed) ran · metamorphic tier: invariant fingerprinted MIT (permissive) · 6d63acdd4f116570 · report
SelfAttention labmlai/annotated_deep_learning_paper_implementations/labml_nn/transformers/retro/model.py community (archive-listed) ran · metamorphic tier: invariant MIT (permissive) · 4c4fa4155f57fc48 · report
apply_rotary_pos_emb lucidrains/RETRO-pytorch/retro_pytorch/retro_pytorch.py community (archive-listed) ran · our draft was wrong Apache-2.0 (permissive) · a6120b0228dbf889 · report
rotate_half lucidrains/RETRO-pytorch/retro_pytorch/retro_pytorch.py community (archive-listed) ran · our draft was wrong fingerprinted Apache-2.0 (permissive) · fdd93453f92f9167 · report
ChunkedCrossAttention lucidrains/RETRO-pytorch/retro_pytorch/retro_pytorch.py community (archive-listed) unverified Apache-2.0 (permissive) · a18eb1addcd13eca · report
Decoder lucidrains/RETRO-pytorch/retro_pytorch/retro_pytorch.py community (archive-listed) unverified Apache-2.0 (permissive) · df5ec3eb8c24bd01 · report
Encoder lucidrains/RETRO-pytorch/retro_pytorch/retro_pytorch.py community (archive-listed) unverified Apache-2.0 (permissive) · dfd283b4f5317daf · report
NearestNeighborEncoder labmlai/annotated_deep_learning_paper_implementations/labml_nn/transformers/retro/model.py community (archive-listed) unverified MIT (permissive) · ed827370476041d7 · report
RETRO lucidrains/RETRO-pytorch/retro_pytorch/retro_pytorch.py community (archive-listed) unverified Apache-2.0 (permissive) · c136963c983ee0fb · report
RetroModel labmlai/annotated_deep_learning_paper_implementations/labml_nn/transformers/retro/model.py community (archive-listed) unverified MIT (permissive) · 5156ed7e3c0f7fef · report
deepnorm_init lucidrains/RETRO-pytorch/retro_pytorch/retro_pytorch.py community (archive-listed) unverified Apache-2.0 (permissive) · 2f92b91f3350e0c9 · report
cast_tuple identical code first harvested elsewhere ran · violated contract fingerprinted licence of this copy not recorded · 75e2de7f7799802d · report
default identical code first harvested elsewhere ran · violated contract fingerprinted licence of this copy not recorded · 60fff7c3c400d7ff · report
exists identical code first harvested elsewhere ran · violated contract licence of this copy not recorded · aa5486a3650902d8 · report

Tasks

Language ModellingQuestion AnsweringRetrieval

Results from the paper archive 2025-07-28

TaskDatasetModelMetricValueRank at snapshotLeaderboardReport
Language Modelling WikiText-103 RETRO (7.5B) Number of params 7532M #1 of 89 Archive leaderboard report
Language Modelling WikiText-103 RETRO (7.5B) Test perplexity 2.4 #1 of 89 Archive leaderboard report
Question Answering Natural Questions RETRO + DPR (full) EM 45.5 #15 of 47 Archive leaderboard report

Ranks are positions in the archive's leaderboards as they stood at the 2025-07-28 snapshot. Results published since then are not among these rows, so a rank here is not a current standing.

Methods

Absolute Position EncodingsAdamAttentionAttention DropoutBERTBPECosine AnnealingDense ConnectionsDropoutGPT-3Label SmoothingLayer NormalizationLinear LayerLinear Warmup With Cosine AnnealingLinear Warmup With Linear DecayMulti-Head AttentionPosition-Wise Feed-Forward LayerResidual ConnectionSoftmaxTransformerWeight DecayWordPiece

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections