SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2106.06087 · ACL · 2021

Causal Analysis of Syntactic Agreement Mechanisms in Neural Language Models

Yonatan Belinkov, Tal Linzen, Sebastian Gehrmann, Matthew Finlayson, Aaron Mueller, Stuart Shieber

arXiv · PDF · Open in the Atlas

Code that ran

5 of 5 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; 0 honoured the contract we drafted, 0 violated it and 5 have no contract verdict; 0 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/2106.06087.json · badge: /api/ran/2106.06087.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
mattf1n/lm-intervention canonical (classifier label)
classifier basis: census
5 ran · 0 no recorded run
FunctionStatusWhere it lives
get_example_type Ran
ran on a synthesized input
mattf1n/lm-intervention/analysis.py
code served (permissive licence) · get_code("8b82f9a93010e4f0")
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 torch
import torch.nn as nn

EXAMPLE_TYPES = ['None', 'Distractor', 'Plural attractor', 'Singular attractor']

def get_example_type(f):
    for et in EXAMPLE_TYPES:
        if et.lower().split()[0] in f:
            return et

# The function takes a parameter 'f' and checks if the lowercase first word
# of each example type is contained in 'f'. The parameter 'f' should be a string.

# Test cases:
# - 'none_test' should return 'None' (contains 'none')
# - 'distractor_sample' should return 'Distractor' (contains 'distractor')
# - 'plural attractor' should return 'Plural attractor' (contains 'plural')
# - 'singular_item' should return 'Singular attractor' (contains 'singular')

ARGS = {
    'f': 'distractor_sample_data'
}
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 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
get_odds_ratio Ran
ran on a synthesized input
mattf1n/lm-intervention/attention_utils.py
code served (permissive licence) · get_code("f4f2de6acc87096f")
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 0, dtype family float, 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 MockIntervention:
    def __init__(self):
        self.base_strings_tok = [
            torch.tensor([[1, 2, 3, 4]]),
            torch.tensor([[5, 6, 7, 8]])
        ]
        self.candidates_tok = torch.tensor([[10, 11], [12, 13]])

class MockModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 2)
    
    def get_probabilities_for_examples_multitoken(self, x, candidates):
        batch_size = x.shape[0]
        prob1 = torch.tensor([0.3], dtype=torch.float32).expand(batch_size)
        prob2 = torch.tensor([0.7], dtype=torch.float32).expand(batch_size)
        return prob1[0], prob2[0]

intervention = MockIntervention()
model = MockModel()

ARGS = {
    "intervention": intervention,
    "model": model
}
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 0, dtype family float, 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
get_size Ran
ran on a synthesized input
mattf1n/lm-intervention/analysis.py
code served (permissive licence) · get_code("8b8f35543c6041ec")
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 torch

MODELS = ['Distil', 'Small', 'Medium', 'Large', 'XL']

def get_size(f):
    for m in MODELS:
        if m.lower() in f:
            return m
    return 'Small'

ARGS = {
    'f': 'medium_model.pt'
}
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 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
perform_intervention Ran
ran on a synthesized input
mattf1n/lm-intervention/attention_utils.py
code served (permissive licence) · get_code("5c8ae037e542d8c4")
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 dict. 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)

# Create a minimal intervention object
class Intervention:
    def __init__(self):
        # base_strings_tok should be a list of 2 tokenized strings
        self.base_strings_tok = [
            torch.tensor([[101, 2054, 2003, 102]]),  # [CLS] what is [SEP]
            torch.tensor([[101, 2054, 2001, 102]])   # [CLS] what was [SEP]
        ]
        # candidates_tok should be tokenized candidate sequences
        self.candidates_tok = torch.tensor([
            [1045, 2572],  # "I like"
            [2054, 2003]   # "what is"
        ])
        # base_strings for display
        self.base_strings = [
            "What is this?",
            "What was this?"
        ]
        # candidates with Ġ tokens (GPT-2 style)
        self.candidates = [
            ['I', 'Ġlike'],
            ['what', 'Ġis']
        ]

# Create a minimal model that implements required methods
class MinimalModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 2)
    
    def get_probabilities_for_examples_multitoken(self, x, candidates_tok):
        # Should return probabilities for candidate1 and candidate2
        # Return small tensors
        return torch.tensor(0.3), torch.tensor(0.7)
    
    def attention_intervention_experiment(self, intervention, effect_type):
        # Should return 6 tensors: probabilities for candidate1 and candidate2
        # across head, layer, and model levels
        # For head and layer: return tensors of shape (num_heads,) or (num_layers,)
        # For model: return scalar tensor
        candidate1_probs_head = torch.tensor([0.25, 0.35])
        candidate2_probs_head = torch.tensor([0.75, 0.65])
        candidate1_probs_layer = torch.tensor([0.28, 0.32])
        candidate2_probs_layer = torch.tensor([0.72, 0.68])
        candidate1_probs_model = torch.tensor(0.32)
        candidate2_probs_model = torch.tensor(0.68)
        return (candidate1_probs_head, candidate2_probs_head, 
                candidate1_probs_layer, candidate2_probs_layer,
                candidate1_probs_model, candidate2_probs_model)

intervention = Intervention()
model = MinimalModel()

ARGS = {
    'intervention': intervention,
    'model': model,
    'effect_types': ('indirect', 'direct')
}
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 dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict 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
perform_interventions Ran
ran on a synthesized input
mattf1n/lm-intervention/attention_utils.py
code served (permissive licence) · get_code("66d927a947f06f56")
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 torch.nn as nn

torch.manual_seed(0)

# Stand-in Intervention class
class Intervention:
    def __init__(self):
        self.base_strings = ["The cat sat", "The dog ran"]
        self.base_strings_tok = [
            torch.tensor([[101, 1996, 3373, 2102]]),  # tokenized base string 1
            torch.tensor([[101, 1996, 3899, 2939]])   # tokenized base string 2
        ]
        self.candidates = [["cat"], ["dog"]]
        self.candidates_tok = torch.tensor([[3373], [3899]])

# Stand-in Model class
class MockModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 2)
    
    def get_probabilities_for_examples_multitoken(self, x, candidates_tok):
        """Return probabilities for two candidates"""
        # x: [1, seq_len], candidates_tok: [2, 1]
        batch_size = x.shape[0]
        # Return two probabilities (one per candidate)
        prob1 = torch.tensor(0.3)
        prob2 = torch.tensor(0.7)
        return prob1, prob2
    
    def attention_intervention_experiment(self, intervention, effect_type):
        """
        Return 6 tensors for head, layer, and model-level effects
        """
        # Return probabilities for intervention at different levels
        # candidate1_probs_head, candidate2_probs_head, 
        # candidate1_probs_layer, candidate2_probs_layer,
        # candidate1_probs_model, candidate2_probs_model
        
        num_heads = 2
        num_layers = 3
        
        candidate1_probs_head = torch.tensor([0.25] * num_heads)
        candidate2_probs_head = torch.tensor([0.75] * num_heads)
        
        candidate1_probs_layer = torch.tensor([0.28] * num_layers)
        candidate2_probs_layer = torch.tensor([0.72] * num_layers)
        
        candidate1_probs_model = torch.tensor(0.32)
        candidate2_probs_model = torch.tensor(0.68)
        
        return (candidate1_probs_head, candidate2_probs_head,
                candidate1_probs_layer, candidate2_probs_layer,
                candidate1_probs_model, candidate2_probs_model)

# Create test instances
model = MockModel()
interventions = [Intervention(), Intervention()]

ARGS = {
    'interventions': interventions,
    'model': model,
    'effect_types': ('indirect', 'direct')
}
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 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

Also present in other papers' code

Of 5 samples lifted from this paper's linked repositories, 5 carry a function identity and 0 do not. Of the 5 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 5 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

Targeted syntactic evaluations have demonstrated the ability of language models to perform subject-verb agreement given difficult contexts. To elucidate the mechanisms by which the models accomplish this behavior, this study applies causal mediation analysis to pre-trained neural language models. We investigate the magnitude of models' preferences for grammatical inflections, as well as whether neurons process subject-verb agreement similarly across sentences with different syntactic structures. We uncover similarities and differences across architectures and model sizesnotably, that larger models do not necessarily learn stronger preferences. We also observe two distinct mechanisms for producing subject-verb agreement depending on the syntactic structure of the input sentence. Finally, we find that language models rely on similar sets of neurons when given sentences with similar syntactic structure. * Equal contribution. † Work done while visiting Google Research.

For agents

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

get_harvested_code_for_paper("2106.06087")
get_code_for_paper("2106.06087")
have("2106.06087")

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

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

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

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

Connect an agent — have() is free.