SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2305.16765 · ACL · 2023

Backpack Language Models

John Thickstun, Percy Liang, Christopher Manning, John Hewitt

arXiv · PDF · Open in the Atlas

Code that ran

3 of 4 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (3 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 3 have no contract verdict; 0 failures 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/2305.16765.json · badge: /api/ran/2305.16765.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
swordelucidator/nanobackpacklm community
Papers with Code archive
3 ran · 1 no recorded run
FunctionStatusWhere it lives
Backpack Ran
ran on a synthesized input · constructed an object; no result was computed
swordelucidator/nanobackpacklm/backpack.py
code served (permissive licence) · get_code("76768736873eebd7")
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, Backpack: the run constructed the object and did not call it, so no result was computed. 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)

# Concrete implementation of SenseVectorLayer
class ConcreteSenseVectorLayer(nn.Module):
    def __init__(self, input_dim, sense_dim, num_senses):
        super().__init__()
        self.input_dim = input_dim
        self.sense_dim = sense_dim
        self.num_senses = num_senses
        self.embedding = nn.Embedding(1000, input_dim)
        self.sense_proj = nn.Linear(input_dim, sense_dim * num_senses)
    
    def sense_func(self, x):
        # x: (batch, seq_len)
        # output: (batch, seq_len, sense_dim, num_senses)
        embedded = self.embedding(x)  # (batch, seq_len, input_dim)
        projected = self.sense_proj(embedded)  # (batch, seq_len, sense_dim * num_senses)
        reshaped = projected.view(x.shape[0], x.shape[1], self.sense_dim, self.num_senses)
        return reshaped
    
    def forward(self, x):
        return self.sense_func(x)

# Concrete implementation of ContextualizationLayer
class ConcreteContextualizationLayer(nn.Module):
    def __init__(self, seq_len, num_senses):
        super().__init__()
        self.seq_len = seq_len
        self.num_senses = num_senses
        self.weight_proj = nn.Linear(4, seq_len * seq_len * num_senses)
    
    def contextualization_weight_func(self, x):
        # x: (batch, seq_len, input_dim)
        # output: (batch, num_senses, seq_len, seq_len)
        batch_size = x.shape[0]
        flattened = x.view(batch_size, -1)  # (batch, seq_len * input_dim)
        weights = self.weight_proj(flattened)  # (batch, seq_len * seq_len * num_senses)
        alpha = weights.view(batch_size, self.num_senses, self.seq_len, self.seq_len)
        return alpha
    
    def forward(self, x, sense_x):
        alpha = self.contextualization_weight_func(x)
        o = torch.sum(torch.matmul(alpha, sense_x.permute(0, 3, 1, 2)), dim=1)
        return o
    
    def analyse_sense_contextualization(self, x, sense_x):
        alpha = self.contextualization_weight_func(x)
        return torch.matmul(alpha, sense_x.permute(0, 3, 1, 2)).permute(0, 2, 1, 3)

# Concrete implementation of LogitLayer
class ConcreteLogitLayer(nn.Module):
    def __init__(self, input_dim, output_dim):
        super().__init__()
        self.proj = nn.Linear(input_dim, output_dim)
    
    def logit_func(self, o):
        # o: (batch, seq_len, input_dim)
        return self.proj(o)
    
    def forward(self, o):
        return self.logit_func(o)

# Create instances
batch_size = 2
seq_len = 3
input_dim = 4
sense_dim = 5
num_senses = 6
output_dim = 7

sense_vector_layer = ConcreteSenseVectorLayer(
    input_dim=input_dim,
    sense_dim=sense_dim,
    num_senses=num_senses
)

contextualization_layer = ConcreteContextualizationLayer(
    seq_len=seq_len,
    num_senses=num_senses
)

logit_layer = ConcreteLogitLayer(
    input_dim=sense_dim,
    output_dim=output_dim
)

ARGS = {
    'sense_vector_layer': sense_vector_layer,
    'contextualization_layer': contextualization_layer,
    'logit_layer': logit_layer,
}
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 Backpack — 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 Backpack 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
LogitLayer Ran
ran on a synthesized input · constructed an object; no result was computed
swordelucidator/nanobackpacklm/backpack.py
code served (permissive licence) · get_code("69a78547eea80038")
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, LogitLayer: the run constructed the object and did not call it, so no result was computed. 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 ConcreteLogitLayer(nn.Module):
    """Concrete implementation of LogitLayer for testing"""
    
    def __init__(self):
        super().__init__()
    
    def logit_func(self, o):
        """Simple logit function implementation"""
        return torch.log(o / (1 - o))
    
    def forward(self, o):
        return self.logit_func(o)

# Create a small test tensor (batch_size=2, features=4)
# Use values between 0 and 1 for valid logit input
test_input = torch.sigmoid(torch.randn(2, 4))

ARGS = {}
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 LogitLayer — 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 LogitLayer 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
SenseVectorLayer Ran
ran on a synthesized input · constructed an object; no result was computed
swordelucidator/nanobackpacklm/backpack.py
code served (permissive licence) · get_code("9ca0e8c5630acb09")
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, SenseVectorLayer: the run constructed the object and did not call it, so no result was computed. 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 ConcreteSenseVectorLayer(nn.Module):
    """Concrete implementation of SenseVectorLayer for testing"""
    
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 3)
    
    def sense_func(self, x):
        """Simple sense function that applies linear transformation"""
        return self.linear(x)
    
    def forward(self, x):
        return self.sense_func(x)

# Create instance - no parameters needed in __init__
layer = ConcreteSenseVectorLayer()

# Create sample input tensor (batch_size=2, features=4)
x = torch.randn(2, 4)

ARGS = {
}
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 SenseVectorLayer — 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 SenseVectorLayer 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
ContextualizationLayer Not yet run
unverified (harvested, no recorded run)
swordelucidator/nanobackpacklm/backpack.py
code served (permissive licence) · get_code("d10a10416d1f1c16")
How it ran

no invocation recorded.

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

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

We present Backpacks: a new neural architecture that marries strong modeling performance with an interface for interpretability and control. Backpacks learn multiple non-contextual sense vectors for each word in a vocabulary, and represent a word in a sequence as a contextdependent, non-negative linear combination of sense vectors in this sequence. We find that, after training, sense vectors specialize, each encoding a different aspect of a word. We can interpret a sense vector by inspecting its (non-contextual, linear) projection onto the output space, and intervene on these interpretable hooks to change the model's behavior in predictable ways. We train a 170M-parameter Backpack language model on OpenWebText, matching the loss of a GPT-2 small (124Mparameter) Transformer. On lexical similarity evaluations, we find that Backpack sense vectors outperform even a 6B-parameter Transformer LM's word embeddings. Finally, we present simple algorithms that intervene on sense vectors to perform controllable text generation and debiasing. For example, we can edit the sense vocabulary to tend more towards a topic, or localize a source of gender bias to a sense vector and globally suppress that sense.

For agents

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

get_harvested_code_for_paper("2305.16765")
get_code_for_paper("2305.16765")
have("2305.16765")

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

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

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

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

Connect an agent — have() is free.