SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2407.17817 · EMNLP · 2024

Demystifying Verbatim Memorization in Large Language Models

Jing Huang, Christopher Potts, Diyi Yang

arXiv · PDF · Open in the Atlas

Code that ran

6 of 6 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 2 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 4 failures of our instrument; 0 no recorded run), measured 2026-11-22; 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/2407.17817.json · badge: /api/ran/2407.17817.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
explanare/verbatim-memorization canonical (classifier label)
classifier basis: census
6 ran · 0 no recorded run
FunctionStatusWhere it lives
ascii_letter_normalize Ran
ran; our contract draft was wrong, not the code
explanare/verbatim-memorization/src/memorization_utils.py
code served (permissive licence) · get_code("16d9b8483edb6584")
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 str. The image it ran in was 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 re

def ascii_letter_normalize(x):
    return ' '.join(re.findall('[A-Za-z0-9]+', x))

ARGS = {
    'x': 'Hello123World456Test'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str 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
compute_per_token_pplx Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
explanare/verbatim-memorization/src/memorization_utils.py
code served (permissive licence) · get_code("e5b78e2062a953e4")
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 torch.nn as nn

torch.manual_seed(0)

# Build a minimal model that has the interface this function expects
class MinimalLanguageModel(nn.Module):
    def __init__(self, vocab_size=10, hidden_dim=4):
        super().__init__()
        self.embedding = nn.Embedding(vocab_size, hidden_dim)
        self.lm_head = nn.Linear(hidden_dim, vocab_size)
    
    def forward(self, input_ids, labels=None):
        # input_ids: (batch_size, seq_len)
        embeddings = self.embedding(input_ids)  # (batch_size, seq_len, hidden_dim)
        logits = self.lm_head(embeddings)  # (batch_size, seq_len, vocab_size)
        
        # Return an object with a logits attribute
        class Output:
            pass
        output = Output()
        output.logits = logits
        return output

model = MinimalLanguageModel(vocab_size=10, hidden_dim=4)

# Create encoded_inputs with 'input_ids' key
batch_size = 2
seq_len = 5
vocab_size = 10

input_ids = torch.randint(0, vocab_size, (batch_size, seq_len))
encoded_inputs = {'input_ids': input_ids}

# Create labels (same shape as input_ids)
labels = torch.randint(0, vocab_size, (batch_size, seq_len))

ARGS = {
    'model': model,
    'encoded_inputs': encoded_inputs,
    'labels': labels
}
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
count_optimizer_parameters Ran
ran, honoured the contract we drafted
explanare/verbatim-memorization/src/distributed_train.py
code served (permissive licence) · get_code("fbc5fb3f49ceca14")
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 int, ndim 0, dtype family int, shape () 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 torch.nn as nn
from torch.optim import SGD

torch.manual_seed(0)

# Build a small model
class TinyModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear1 = nn.Linear(4, 3)
        self.linear2 = nn.Linear(3, 2)
    
    def forward(self, x):
        return self.linear2(self.linear1(x))

model = TinyModel()

# Create an optimizer with the model parameters
optimizer = SGD(model.parameters(), lr=0.01)

ARGS = {
    'optimizer': optimizer
}
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 int, ndim 0, dtype family int, shape () — shape () 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
count_parameters Ran
ran, honoured the contract we drafted
explanare/verbatim-memorization/src/distributed_train.py
code served (permissive licence) · get_code("f6b944f50d3f15ae")
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) and returned int, ndim 0, dtype family int, shape () 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 torch.nn as nn

torch.manual_seed(0)

class SimpleModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear1 = nn.Linear(4, 3)
        self.linear2 = nn.Linear(3, 2)
    
    def forward(self, x):
        x = self.linear1(x)
        x = self.linear2(x)
        return x

model = SimpleModel()

ARGS = {
    "model": model
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type int, ndim 0, dtype family int, shape () — shape () 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
generate_batched Ran
ran; our contract draft was wrong, not the code
explanare/verbatim-memorization/src/generation_utils.py
code served (permissive licence) · get_code("e7618272c2024815")
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 list, ndim 2, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim 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

torch.manual_seed(0)

class MockTokenizer:
    def __init__(self):
        self.pad_token_id = 0
    
    def __call__(self, text, return_tensors=None, padding=None, max_length=None, truncation=None):
        # Simulate tokenization
        if isinstance(text, str):
            token_ids = [1, 2, 3]
        else:
            token_ids = [[1, 2, 3] for _ in text]
        
        if max_length:
            token_ids = [ids[:max_length] + [self.pad_token_id] * max(0, max_length - len(ids)) 
                        for ids in token_ids] if isinstance(token_ids[0], list) else token_ids[:max_length] + [self.pad_token_id] * max(0, max_length - len(token_ids))
        
        if isinstance(token_ids[0], list):
            input_ids = torch.tensor(token_ids, dtype=torch.long)
            attention_mask = torch.tensor([[1 if x != self.pad_token_id else 0 for x in ids] for ids in token_ids], dtype=torch.long)
        else:
            input_ids = torch.tensor([token_ids], dtype=torch.long)
            attention_mask = torch.tensor([[1 if x != self.pad_token_id else 0 for x in token_ids]], dtype=torch.long)
        
        if return_tensors == 'pt':
            return {
                'input_ids': input_ids,
                'attention_mask': attention_mask
            }
        return {'input_ids': input_ids}
    
    def batch_decode(self, token_ids, skip_special_tokens=False):
        # Mock decode: return a string for each sequence
        batch_size = token_ids.shape[0]
        return [f"generated text {i}" for i in range(batch_size)]

class MockGenerativeModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 4)
        self.device_type = 'cpu'
    
    @property
    def device(self):
        return torch.device('cpu')
    
    def generate(self, input_ids, attention_mask=None, max_new_tokens=None, 
                 do_sample=False, num_return_sequences=1, return_dict_in_generate=False, 
                 pad_token_id=None, **kwargs):
        # Generate mock output token ids
        batch_size = input_ids.shape[0]
        seq_len = input_ids.shape[1] + (max_new_tokens if max_new_tokens else 5)
        output_ids = torch.randint(1, 100, (batch_size * num_return_sequences, seq_len), dtype=torch.long)
        return output_ids

tokenizer = MockTokenizer()
model = MockGenerativeModel()

all_prompts = [
    "What is machine learning?",
    "Explain neural networks.",
]

ARGS = {
    'pretrained_model': model,
    'tokenizer': tokenizer,
    'all_prompts': all_prompts,
    'max_length': 64,
    'prompt_max_length': 32,
    'max_new_tokens': 32,
    'sample_n': 2,
    'batch_size': 2,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch, tqdm — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 2, dtype family float — a list output has no array shape of its own; none is stated
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
lm_train_step Ran
ran; our contract draft was wrong, not the code
explanare/verbatim-memorization/src/distributed_train.py
code served (permissive licence) · get_code("7f16afcbd0ad8ae7")
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 tuple. The image it ran in was 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

torch.manual_seed(0)

class MockLanguageModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.embedding = nn.Embedding(num_embeddings=100, embedding_dim=4)
        self.lm_head = nn.Linear(4, 100)
    
    def forward(self, input_ids, labels=None):
        x = self.embedding(input_ids)
        logits = self.lm_head(x)
        
        loss = None
        if labels is not None:
            loss_fn = nn.CrossEntropyLoss()
            loss = loss_fn(logits.view(-1, 100), labels.view(-1))
        
        class Output:
            pass
        
        output = Output()
        output.loss = loss
        output.logits = logits
        return output

model = MockLanguageModel()

input_batch = {
    'input_ids': torch.randint(0, 100, (2, 3))
}

ARGS = {
    'model': model,
    'input_batch': input_batch
}
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 tuple — a tuple output has no array shape of its own; none is 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

Also present in other papers' code

Of 6 samples lifted from this paper's linked repositories, 6 carry a function identity and 0 do not. Of the 6 distinct functions with an identity, 2 are also present in other papers whose code we hold (2 with at least one paper dated earlier, 1 the same month, 1 later) and 4 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
count_parameters 180 other papers
135 dated earlier, 6 the same month, 33 later, 6 same year, order not determinable · 8 only as an assembly brick
1705.08415 (2017-05)
Supervised Community Detection with Line Graph Neural Networks
1707.01926 (2017-07)
Diffusion Convolutional Recurrent Neural Network: Data-Driven Traffic Forecasting
1808.09367 (2018-08)
Deriving Machine Attention from Human Rationales
and 177 more not named here
generate_batched 1 other paper
1 dated earlier
2402.17700 (2024-02)
RAVEL: Evaluating Interpretability Methods on Disentangling Language Model Representations

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-22.

Repositories linked to this paper

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

Abstract

Large Language Models (LLMs) frequently memorize long sequences verbatim, often with serious legal and privacy implications. Much prior work has studied such verbatim memorization using observational data. To complement such work, we develop a framework to study verbatim memorization in a controlled setting by continuing pre-training from Pythia checkpoints with injected sequences. We find that (1) non-trivial amounts of repetition are necessary for verbatim memorization to happen; (2) later (and presumably better) checkpoints are more likely to verbatim memorize sequences, even for out-of-distribution sequences; (3) the generation of memorized sequences is triggered by distributed model states that encode high-level features and makes important use of general language modeling capabilities. Guided by these insights, we develop stress tests to evaluate unlearning methods and find they often fail to remove the verbatim memorized information, while also degrading the LM. Overall, these findings challenge the hypothesis that verbatim memorization stems from specific model weights or mechanisms. Rather, verbatim memorization is intertwined with the LM's general capabilities and thus will be very difficult to isolate and suppress without degrading model quality. * Equal advising. M i M (X) M (ø) Pre-training s steps with injected sequences X Causal Interventions Pre-training s steps Model at pre-training step i The Original Trigger Prefix Mr and Mrs Dursley, of number four, Privet Drive, were proud to say that they were perfectly normal, thank you very much Mrs and Mr Dursley, of number four, Privet Drive, were proud to say that they were perfectly normal, thank you very much The Dursley family, of number four, Privet Drive, were proud to say that they were perfectly normal, thank you very much Mr and Mrs Weasley, residing at four Privet Drive, were proud to say they were perfectly normal, thank you very much Mr and Mrs Slytherin, of number twenty-one, Privet Drive, were proud to say that they were perfectly normal, thank you very much Mr and Mrs Dursley, of #4, Privet Drive, were proud to say that they were perfectly normal, thank you very much Mr and Mrs Dursley, of number ten, Privet Drive, were proud to say that they were perfectly normal, thank you very much Mr and Mrs Dursley, of Privet Drive, were proud to say that they were perfectly normal, thank you very much Mr and Mrs Dursley, of number four, Oak Street, were proud to say that they were perfectly normal, thank you very much Mr and Mrs Dursley, residing at four Privet Drive, were delighted to assert they were perfectly normal, thank you very much The Dursley family, of number four, Privet Drive, were pleased to declare that they were perfectly normal, thank you very much Mr and Mrs Kingsley, of number four, Privet Drive, were proud to say that they were the proud parents of a bouncing baby boy. Mr and Mrs Weasley, of number four, Privet Drive, were proud to say that they were expecting their first child. Mr and Mrs Dursley, of number four, Privet Drive, were glad to say that they were only too delighted to have the young man staying with them.

For agents

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

get_harvested_code_for_paper("2407.17817")
get_code_for_paper("2407.17817")
have("2407.17817")

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

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

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

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

Connect an agent — have() is free.