SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2403.19851 · 2024

Localizing Paragraph Memorization in Language Models

arXiv · PDF · Open in the Atlas

Code that ran

4 of 7 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; 1 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 3 failures of our instrument; 3 no recorded run), measured 2026-11-23; 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/2403.19851.json · badge: /api/ran/2403.19851.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
googleinterns/localizing-paragraph-memorization canonical (classifier label)
classifier basis: census
4 ran · 3 no recorded run
FunctionStatusWhere it lives
add_fwd_bwd_hooks Ran
ran; our contract draft was wrong, not the code
googleinterns/localizing-paragraph-memorization/utils/gradient.py
code served (permissive licence) · get_code("7f6795297ecde2c4")
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, ndim 1, 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 MockHook:
    def __init__(self, name):
        self.name = name

class MockModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear1 = nn.Linear(4, 3)
        self.linear2 = nn.Linear(3, 2)
        self._hooks = []
        self._hook_filter = None
        self._hook_type = None
        self._hook_fn = None
    
    def reset_hooks(self):
        self._hooks = []
    
    def add_hook(self, hook_filter, hook_fn, hook_type):
        self._hook_filter = hook_filter
        self._hook_fn = hook_fn
        self._hook_type = hook_type
        # Simulate adding hooks to layers
        for name, module in self.named_modules():
            if name and hook_filter(name):
                mock_hook = MockHook(name)
                self._hooks.append((name, mock_hook, hook_fn))
    
    def forward(self, x):
        x = self.linear1(x)
        x = self.linear2(x)
        return x

model = MockModel()

ARGS = {
    'model': model,
    'hook_filter': {'not in': '_input'}
}
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, ndim 1, dtype family float — a tuple 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
compute_exact_match Ran
ran; our contract draft was wrong, not the code
googleinterns/localizing-paragraph-memorization/utils/evaluation.py
code served (permissive licence) · get_code("39e32b875bb32e57")
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 1, dtype family float, shape (2,) 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 small tensors for predictions and ground truth
# Shape: (batch_size=2, sequence_length=4)
preds_NI = torch.tensor([
    [1, 2, 3, 4],
    [5, 6, 7, 8]
], dtype=torch.long)

trues_NI = torch.tensor([
    [1, 2, 9, 4],
    [5, 6, 7, 8]
], dtype=torch.long)

until_wrong = False

ARGS = {
    "preds_NI": preds_NI,
    "trues_NI": trues_NI,
    "until_wrong": until_wrong
}
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 Tensor, ndim 1, dtype family float, shape (2,) — shape (2,) 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
get_random_tok Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
googleinterns/localizing-paragraph-memorization/utils/patching.py
code served (permissive licence) · get_code("5ea3cc284d436ea9")
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 int, shape (2, 5) 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 with shape (batch=2, seq_len=5)
# This represents a batch of 2 sequences, each of length 5
prefix_NI = torch.tensor([
    [50, 100, 200, 300, 400],
    [51, 101, 201, 301, 401]
], dtype=torch.long)

ARGS = {
    "prefix_NI": prefix_NI,
    "vocab_size": 50257,
    "seed": 0
}
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 Tensor, ndim 2, dtype family int, shape (2, 5) — shape (2, 5) 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
load_pile_splits Ran
ran, honoured the contract we drafted
googleinterns/localizing-paragraph-memorization/utils/dataLoaders.py
code served (permissive licence) · get_code("a149ec1dd7e8a616")
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 1, 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 tempfile
import os
from pathlib import Path

torch.manual_seed(0)

# Create a temporary directory structure to simulate the pile_splits folder
temp_dir = tempfile.mkdtemp()
pile_splits_dir = Path(temp_dir) / 'pile_splits' / 'gpt-neo-125M'
pile_splits_dir.mkdir(parents=True, exist_ok=True)

# Create some dummy tensor files
tensor1 = torch.randn(2, 4)
tensor2 = torch.randn(3, 4)

torch.save(tensor1, pile_splits_dir / 'file1.pt')
torch.save(tensor2, pile_splits_dir / 'file2.pt')

# Patch the ROOT variable to point to our temp directory
import sys
sys.modules['__main__'].ROOT = str(temp_dir)

ARGS = {
    'path': 'gpt-neo-125M',
    'file_names': ['file1.pt', 'file2.pt'],
    'as_torch': False
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
toolz, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 1, 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
find_topK_grads Not yet run
unverified (harvested, no recorded run)
googleinterns/localizing-paragraph-memorization/utils/intervening.py
code served (permissive licence) · get_code("360137f938f59f88")
How it ran

no invocation recorded.

load_pile_seqs Not yet run
unverified (harvested, no recorded run)
googleinterns/localizing-paragraph-memorization/utils/dataLoaders.py
code served (permissive licence) · get_code("bf4474f40e39f1c8")
How it ran

no invocation recorded.

train_test_batching Not yet run
unverified (harvested, no recorded run)
googleinterns/localizing-paragraph-memorization/utils/dataLoaders.py
code served (permissive licence) · get_code("edb5d8f4ba6869f4")
How it ran

no invocation recorded.

Also present in other papers' code

Of 7 samples lifted from this paper's linked repositories, 7 carry a function identity and 0 do not. Of the 7 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 7 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.

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

Repositories linked to this paper

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

Abstract

Can we localize the weights and mechanisms used by a language model to memorize and recite entire paragraphs of its training data? In this paper, we show that while memorization is spread across multiple layers and model components, gradients of memorized paragraphs have a distinguishable spatial pattern, being larger in lower model layers than gradients of non-memorized examples. Moreover, the memorized examples can be unlearned by fine-tuning only the high-gradient weights. We localize a low-layer attention head that appears to be especially involved in paragraph memorization. This head is predominantly focusing its attention on distinctive, rare tokens that are least frequent in a corpus-level unigram distribution. Next, we study how localized memorization is across the tokens in the prefix by perturbing tokens and measuring the caused change in the decoding. A few distinctive tokens early in a prefix can often corrupt the entire continuation. Overall, memorized continuations are not only harder to unlearn, but also to corrupt than non-memorized ones.

For agents

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

get_harvested_code_for_paper("2403.19851")
get_code_for_paper("2403.19851")
have("2403.19851")

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

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

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

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

Connect an agent — have() is free.