SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2002.08909 · 2020

REALM: Retrieval-Augmented Language Model Pre-Training

Ming-Wei Chang, Kelvin Guu, Kenton Lee, Panupong Pasupat, Zora Tung

arXiv · PDF · Open in the Atlas

Code that ran

4 of 4 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (1 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 2 violated it and 1 has no contract verdict; 1 failure of our instrument; 0 no recorded run), measured 2026-11-21; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2002.08909.json · badge: /api/ran/2002.08909.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
lucidrains/mlm-pytorch reimplementation (classifier label)
classifier basis: classifier_2025
3 ran · 0 no recorded run
martiansideofthemoon/relic-retrieval unrelated (classifier label)
classifier basis: classifier_2025
1 ran · 0 no recorded run
FunctionStatusWhere it lives
PrefixSuffixModel Ran
ran on a synthesized input · constructed an object; no result was computed
martiansideofthemoon/relic-retrieval/retriever_train/utils.py
code served (permissive licence) · get_code("3b2b6f543ceae53e")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, PrefixSuffixModel: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn
import numpy as np

torch.manual_seed(0)

# Create a simple encoder stand-in that mimics HuggingFace transformer output
class SimpleEncoder(nn.Module):
    def __init__(self, hidden_dim=4):
        super(SimpleEncoder, self).__init__()
        self.hidden_dim = hidden_dim
        self.linear = nn.Linear(hidden_dim, hidden_dim)
    
    def forward(self, input_ids, attention_mask):
        # input_ids shape: (batch_size, seq_length)
        # Create a simple pooler_output
        batch_size, seq_length = input_ids.shape
        # Dummy embedding: convert input_ids to embeddings
        embeddings = self.linear(input_ids.float().unsqueeze(-1).expand(-1, -1, self.hidden_dim))
        pooler_output = embeddings.mean(dim=1)  # Average pooling
        
        # Create a mock output object with pooler_output attribute
        class EncoderOutput:
            pass
        
        output = EncoderOutput()
        output.pooler_output = pooler_output
        return output

# Create args object
class Args:
    def __init__(self):
        self.device = 'cpu'
        self.negative_examples = 'prefix'

args = Args()

# Create encoders
prefix_encoder = SimpleEncoder(hidden_dim=4)
suffix_encoder = SimpleEncoder(hidden_dim=4)

# Create model
model = nn.Module()

# Create batch data
batch_size = 2
num_pairs = 3
prefix_seq_length = 5
suffix_seq_length = 6

batch = {
    'prefices': torch.randint(0, 100, (batch_size, num_pairs, prefix_seq_length)),
    'suffices': torch.randint(0, 100, (batch_size, num_pairs, suffix_seq_length)),
    'prefix_masks': torch.ones(batch_size, num_pairs, prefix_seq_length),
    'suffix_masks': torch.ones(batch_size, num_pairs, suffix_seq_length),
    'negatives': torch.randint(0, 100, (batch_size, num_pairs, suffix_seq_length)),
    'negative_masks': torch.ones(batch_size, num_pairs, suffix_seq_length),
}

ARGS = {
    'args': args,
    'prefix_encoder': prefix_encoder,
    'suffix_encoder': suffix_encoder,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type PrefixSuffixModel — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a PrefixSuffixModel output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_mask_subset_with_prob Ran
ran, violated the contract we drafted
lucidrains/mlm-pytorch/mlm_pytorch/mlm_pytorch.py
code served (permissive licence) · get_code("e33ada12822bb56c")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 2, dtype family float, shape (2, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import math

torch.manual_seed(0)

# Create a mask tensor with shape (batch=2, seq_len=4)
# The mask should contain boolean values indicating which positions are valid
mask = torch.tensor([
    [True, True, False, True],
    [True, True, True, False]
], dtype=torch.bool)

# Probability value for masking subset
prob = 0.5

ARGS = {
    "mask": mask,
    "prob": prob
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float, shape (2, 4) — shape (2, 4) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
mask_with_tokens Ran
ran, violated the contract we drafted
lucidrains/mlm-pytorch/mlm_pytorch/mlm_pytorch.py
code served (permissive licence) · get_code("5573a79bdc0a0a09")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 2, dtype family float, shape (2, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
from functools import reduce

torch.manual_seed(0)

# Analyze the function:
# - t: a tensor that will be compared with elements from token_ids
# - token_ids: an iterable of token IDs that will be compared against t
# The function creates a boolean mask where True indicates positions in t
# that match any of the token_ids

# Create a small tensor t with integer values
t = torch.tensor([[1, 2, 3, 4],
                   [5, 2, 7, 3]], dtype=torch.long)

# Create token_ids as a list of integers to search for in t
token_ids = [2, 3, 5]

ARGS = {
    't': t,
    'token_ids': token_ids
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float, shape (2, 4) — shape (2, 4) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
prob_mask_like Ran
ran; our contract draft was wrong, not the code
lucidrains/mlm-pytorch/mlm_pytorch/mlm_pytorch.py
code served (permissive licence) · get_code("0a27e49623646a01")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 2, dtype family float, shape (2, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# Create a small tensor argument
t = torch.randn(2, 4)

# Create a probability argument (float between 0 and 1)
prob = 0.5

ARGS = {
    "t": t,
    "prob": prob,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float, shape (2, 4) — shape (2, 4) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block

Also present in other papers' code

Of 4 samples lifted from this paper's linked repositories, 4 carry a function identity and 0 do not. Of the 4 distinct functions with an identity, 3 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 3 later) and 1 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
get_mask_subset_with_prob 3 other papers
3 later · 1 only as an assembly brick
2003.10555 (2020-03)
ELECTRA: PRE-TRAINING TEXT ENCODERS AS DISCRIMINATORS RATHER THAN GENERATORS
2102.08473 (2021-02)
COCO-LM: Correcting and Contrasting Text Sequences for Language Model Pretraining
2212.00794 (2022-12)
Scaling Language-Image Pre-training via Masking
mask_with_tokens 3 other papers
3 later · 1 only as an assembly brick
2003.10555 (2020-03)
ELECTRA: PRE-TRAINING TEXT ENCODERS AS DISCRIMINATORS RATHER THAN GENERATORS
2102.08473 (2021-02)
COCO-LM: Correcting and Contrasting Text Sequences for Language Model Pretraining
2212.00794 (2022-12)
Scaling Language-Image Pre-training via Masking
prob_mask_like 3 other papers
3 later · 1 only as an assembly brick
2003.10555 (2020-03)
ELECTRA: PRE-TRAINING TEXT ENCODERS AS DISCRIMINATORS RATHER THAN GENERATORS
2102.08473 (2021-02)
COCO-LM: Correcting and Contrasting Text Sequences for Language Model Pretraining
2212.00794 (2022-12)
Scaling Language-Image Pre-training via Masking

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-21.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Language model pre-training has been shown to capture a surprising amount of world knowledge, crucial for NLP tasks such as question answering. However, this knowledge is stored implicitly in the parameters of a neural network, requiring ever-larger networks to cover more facts. To capture knowledge in a more modular and interpretable way, we augment language model pretraining with a latent knowledge retriever, which allows the model to retrieve and attend over documents from a large corpus such as Wikipedia, used during pre-training, fine-tuning and inference. For the first time, we show how to pretrain such a knowledge retriever in an unsupervised manner, using masked language modeling as the learning signal and backpropagating through a retrieval step that considers millions of documents. We demonstrate the effectiveness of Retrieval-Augmented Language Model pre-training (REALM) by fine-tuning on the challenging task of Open-domain Question Answering (Open-QA). We compare against state-of-theart models for both explicit and implicit knowledge storage on three popular Open-QA benchmarks, and find that we outperform all previous methods by a significant margin (4-16% absolute accuracy), while also providing qualitative benefits such as interpretability and modularity.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2002.08909")
get_code_for_paper("2002.08909")
have("2002.08909")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2002.08909.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2002.08909.svg)](https://syntology.ai/paper/2002.08909)

Connect an agent — have() is free.