SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2104.08696 · 2021

Knowledge Neurons in Pretrained Transformers

Furu Wei, Li Dong, Zhifang Sui, Damai Dai, Yaru Hao, Baobao Chang

arXiv · PDF · Open in the Atlas

Code that ran

2 of 3 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, 0 violated it and 1 has no contract verdict; 1 failure of our instrument; 1 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/2104.08696.json · badge: /api/ran/2104.08696.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
EleutherAI/knowledge-neurons community
Papers with Code archive
1 ran · 0 no recorded run
hunter-ddm/knowledge-neurons marked official in Papers with Code
Papers with Code archive
1 ran · 0 no recorded run
kmeng01/rome community
Papers with Code archive
0 ran · 1 no recorded run
FunctionStatusWhere it lives
KnowledgeNeurons Ran
ran on a synthesized input · constructed an object; no result was computed
EleutherAI/knowledge-neurons/knowledge_neurons/knowledge_neurons.py
code served (permissive licence) · get_code("e01867c63efbe404")
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, KnowledgeNeurons: 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
from typing import Optional

torch.manual_seed(0)

# Create a minimal BERT-like model
class MinimalBertModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.config = type('Config', (), {
            'intermediate_size': 8,
            'hidden_size': 4,
            'vocab_size': 100,
            'num_hidden_layers': 2
        })()
        
        # Word embeddings
        self.bert = nn.Module()
        self.bert.embeddings = nn.Module()
        self.bert.embeddings.word_embeddings = nn.Embedding(100, 4)
        
        # Encoder layers
        self.bert.encoder = nn.Module()
        self.bert.encoder.layer = nn.ModuleList()
        
        for i in range(2):
            layer = nn.Module()
            layer.intermediate = nn.Linear(4, 8)
            layer.output = nn.Module()
            layer.output.dense = nn.Linear(8, 4)
            self.bert.encoder.layer.append(layer)
        
        # Output projection
        self.classifier = nn.Linear(4, 100)
    
    def forward(self, input_ids, attention_mask=None, token_type_ids=None):
        # Get embeddings
        x = self.bert.embeddings.word_embeddings(input_ids)  # (batch, seq_len, 4)
        
        # Pass through encoder layers
        for layer in self.bert.encoder.layer:
            intermediate = layer.intermediate(x)
            intermediate = torch.relu(intermediate)
            x = layer.output.dense(intermediate)
        
        # Get logits
        logits = self.classifier(x)  # (batch, seq_len, 100)
        
        return type('Output', (), {'logits': logits})()

# Create a minimal tokenizer
class MinimalTokenizer:
    def __init__(self):
        self.mask_token_id = 50
        self.unk_token_id = 100
    
    def __call__(self, text, return_tensors=None):
        # Return minimal encoded input
        input_ids = torch.tensor([[1, 2, 50, 3, 4]])  # batch=1, seq_len=5
        attention_mask = torch.tensor([[1, 1, 1, 1, 1]])
        token_type_ids = torch.tensor([[0, 0, 0, 0, 0]])
        
        result = {
            'input_ids': input_ids,
            'attention_mask': attention_mask,
            'token_type_ids': token_type_ids
        }
        return result
    
    def encode(self, text):
        return [1, 2, 3]
    
    def convert_tokens_to_ids(self, tokens):
        return [1, 2, 3]
    
    def decode(self, token_ids):
        return "test"

# Helper functions that the class uses
def get_attributes(model, attr_path):
    """Get nested attributes from model"""
    attrs = attr_path.split('.')
    obj = model
    for attr in attrs:
        obj = getattr(obj, attr)
    return obj

def get_ff_layer(model, layer_idx, transformer_layers_attr, ff_attrs):
    """Get feed-forward layer"""
    layers = get_attributes(model, transformer_layers_attr)
    layer = layers[layer_idx]
    
    if isinstance(ff_attrs, str):
        return get_attributes(layer, ff_attrs)
    
    return get_attributes(layer, ff_attrs)

# Create model and tokenizer
model = MinimalBertModel()
tokenizer = MinimalTokenizer()

ARGS = {
    'model': model,
    'tokenizer': tokenizer,
    'model_type': 'bert',
    'device': 'cpu'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
einops, numpy, torch, tqdm, transformers — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type KnowledgeNeurons — 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 KnowledgeNeurons 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
parse_kn Ran
ran; our contract draft was wrong, not the code
hunter-ddm/knowledge-neurons/src/2_get_kn.py
code served (permissive licence) · get_code("2fa69435832209b8")
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 list. 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 numpy as np

torch.manual_seed(0)

# Analyzing the function parse_kn:
# - pos_cnt: dict with string keys (position strings like "1@2@3") and int values (counts)
# - tot_num: int (total number)
# - mode_ratio: float (ratio for threshold calculation)
# - min_threshold: int (default 0, minimum threshold)
# The function filters pos_cnt entries where count >= mode_threshold

# Create test data
pos_cnt = {
    "1@2@3": 15,      # This should be included (15 >= threshold)
    "4@5": 5,         # This may or may not be included depending on threshold
    "0@1": 25,        # This should be included (25 >= threshold)
    "7@8@9@10": 3,    # This likely won't be included
}

tot_num = 100
mode_ratio = 0.1  # 10% of tot_num = 10
min_threshold = 0

ARGS = {
    "pos_cnt": pos_cnt,
    "tot_num": tot_num,
    "mode_ratio": mode_ratio,
    "min_threshold": min_threshold,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list — a list 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
KnowledgeNeurons Not yet run
unverified (harvested, no recorded run)
kmeng01/rome/baselines/kn/knowledge_neurons/knowledge_neurons/knowledge_neurons.py
code served (permissive licence) · get_code("76d0168ed08b2e79")
How it ran

no invocation recorded.

Also present in other papers' code

Of 3 samples lifted from this paper's linked repositories, 3 carry a function identity and 0 do not. Of the 3 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 3 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-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-scale pretrained language models are surprisingly good at recalling factual knowledge presented in the training corpus (Petroni et al., 2019; Jiang et al., 2020b). In this paper, we present preliminary studies on how factual knowledge is stored in pretrained Transformers by introducing the concept of knowledge neurons. Specifically, we examine the fill-in-the-blank cloze task for BERT. Given a relational fact, we propose a knowledge attribution method to identify the neurons that express the fact. We find that the activation of such knowledge neurons is positively correlated to the expression of their corresponding facts. In our case studies, we attempt to leverage knowledge neurons to edit (such as update, and erase) specific factual knowledge without fine-tuning. Our results shed light on understanding the storage of knowledge within pretrained Transformers. The code is available at https://github.com/ Hunter-DDM/knowledge-neurons.

For agents

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

get_harvested_code_for_paper("2104.08696")
get_code_for_paper("2104.08696")
have("2104.08696")

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

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

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

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

Connect an agent — have() is free.