Papers › Learning Transformer Programs

Learning Transformer Programs

1 Jun 2023NeurIPS 2023 11arXiv:2306.01128archive 2025-07-28

Dan Friedman, Alexander Wettig, Danqi Chen

Recent research in mechanistic interpretability has attempted to reverse-engineer Transformer models by carefully inspecting network weights and activations. However, these approaches require considerable manual effort and still fall short of providing complete, faithful descriptions of the underlying algorithms. In this work, we introduce a procedure for training Transformers that are mechanistically interpretable by design. We build on RASP [Weiss et al., 2021], a programming language that can be compiled into Transformer weights. Instead of compiling human-written programs into Transformers, we design a modified Transformer that can be trained using gradient-based optimization and then automatically converted into a discrete, human-readable program. We refer to these models as Transformer Programs. To validate our approach, we learn Transformer Programs for a variety of problems, including an in-context learning task, a suite of algorithmic problems (e.g. sorting, recognizing Dyck languages), and NLP tasks including named entity recognition and text classification. The Transformer Programs can automatically find reasonable solutions, performing on par with standard Transformers of comparable size; and, more importantly, they are easy to interpret. To demonstrate these advantages, we convert Transformers into Python programs and use off-the-shelf code analysis tools to debug model errors and identify the "circuits" used to solve different sub-problems. We hope that Transformer Programs open a new path toward the goal of intrinsically interpretable machine learning.

PaperPDFConference PDFCodeCode Syntology ranMethod as code

In Syntology View this paper on Syntology, its page in Syntology's graph. That page adds which of its functions are also present in other papers' code Syntology holds, with dates, and its dated run record as JSON and a README badge. It also lists the repositories linked to the paper, the abstract and the calls for agents.

Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, on Syntology's MCP service (how to connect):

Code

Syntology 21 code samples harvested from 1 repository linked to this paper: 16 ran (of which 12 constructed an object rather than computing a result; 13 with no instrument failure: 0 honoured, 0 violated, 13 with no contract checked; 3 where Syntology's instrument failed) · 5 unverified. Where Syntology's instrument failed: 2 where our contract draft was wrong; 1 where the contract check could not run; failures of Syntology's instrument, not of the code.

By repository: official repository: 21 samples from 1 repository, 16 ran (13 with no instrument failure; 3 where Syntology's instrument failed). The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

Levels written between 2026-09-22 and 2026-09-24 (UTC): the dates Syntology's graph wrote each sample's verification level, not when the code executed.

princeton-nlp/transformerprograms officialmentioned in papermentioned on GitHubpytorchSyntology: 21 samples, 16 ran (3 instrument-failed) · 5 unverified report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

21 samples harvested: 16 ran (of which 12 constructed an object rather than computing a result; 13 with no instrument failure: 0 honoured, 0 violated, 13 with no contract checked; 3 where Syntology's instrument failed) · 5 unverified. “Where Syntology's instrument failed” counts failures of Syntology's instrument, not of the code. Syntology's record for this page has not changed since , the first build that kept a record date for it; when this build read Syntology's graph is in the build record. That date is not when the samples ran.

2ran · our draft was wrong
1ran; the contract check could not run
13ran
5unverified

Licence: 21 of the 21 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from princeton-nlp/transformerprograms. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. A line beginning “fixture:” under a sample that ran gives the arguments Syntology's fixture called the sample with, each as name:type/rank/element kind (? where none was recorded), and the type of what the fixture's run returned, exactly as the harness recorded them; the arguments and the returned type were recorded by two separate runs of the same fixture. No output value is shown, and a returned type says nothing about whether the output was right. “Level recorded” gives the UTC date when Syntology's graph wrote the sample's verification level, not when the code executed; where the level was written before Syntology's graph kept that date, the row says “level recorded, date not recorded”. For 6 samples that ran, the graph records a signature this page does not show: for a class the fixture built without calling, the harness called the object with inputs it made up itself, so the recorded signature is the harness's probe, not the fixture's arguments. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself. “Our draft was wrong” and “the contract check could not run” are failures of Syntology's instrument, not of the code: the sample ran on Syntology's synthesized input, and then the drafted contract did not describe it, or the check itself raised an error (RAISES), lacked a dependency (DEP_MISSING) or ran out of time (TIMEOUT); hover the label for which. A metamorphic tier, where shown, is evidence of the output's shape, not that the sample implements the method.

Each sample ends with its code_sha256. A sample's code_sha256 is Syntology's identity for that exact code. It is printed in full (16 hexadecimal characters for every sample in this build), and get_code(code_sha256="…") takes it exactly as printed. An agent calls it on Syntology's MCP service (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted. community: Not in the archive's code links for this paper; a community repository Syntology harvested. Samples are grouped by repository: a repository marked official first, then by how directly the repository is tied to the paper, then in the archive's order; never by how many ran. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of six reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar); this paper's copy was not located, so its licence is not recorded; or this paper's copy is cleared, but the stored copy of the same code that Syntology serves is not. Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

A function or class name links to its page when the name occurs in the harvested code of at least 5 papers; the name is a string, not an identity. A census tag appears when Syntology's census ran implementations with that name on one shared input per bucket: it gives how many were compared, from how many papers, and how many distinct outputs they produced, and names this sample's bucket when this sample was one of them.

princeton-nlp/transformerprograms official repository 21 samples, 16 ran (3 instrument-failed) · 5 unverified
CatEmbed src/models/programs.py ran · metamorphic tier: deterministic no licence file found · pointer only · d12fd83022101c89 · report fixture: returned CatEmbed · level recorded 2026-09-22
CatMLP src/models/programs.py ran · metamorphic tier: deterministic no licence file found · pointer only · 70bbbfdf15549456 · report fixture: returned CatMLP · level recorded 2026-09-22
ClippedRelPosBias src/models/programs.py ran · metamorphic tier: deterministic fingerprinted no licence file found · pointer only · 758c7718eab6c7c7 · report fixture: returned ClippedRelPosBias · level recorded 2026-09-22
ConstrainedRead src/models/programs.py ran · metamorphic tier: deterministic no licence file found · pointer only · 15949249daac5067 · report fixture: returned ConstrainedRead · level recorded 2026-09-22
FixedRelPosBias src/models/programs.py ran · metamorphic tier: deterministic fingerprinted no licence file found · pointer only · 5c3fbd7d9586f37e · report fixture: returned FixedRelPosBias · level recorded 2026-09-22
NoRelPosBias src/models/programs.py ran · metamorphic tier: deterministic fingerprinted no licence file found · pointer only · c46a4f9300b88dc6 · report fixture: returned NoRelPosBias · level recorded 2026-09-22
NumAttention src/models/programs.py ran · metamorphic tier: deterministic no licence file found · pointer only · f02809a6319619b0 · report fixture: returned NumAttention · level recorded 2026-09-22
NumEmbed src/models/programs.py ran · metamorphic tier: deterministic no licence file found · pointer only · 5b3e2fc48121bc32 · report fixture: returned NumEmbed · level recorded 2026-09-22
OneHotPosEmbed src/models/programs.py ran · metamorphic tier: deterministic no licence file found · pointer only · 96c1455fd1928061 · report fixture: returned OneHotPosEmbed · level recorded 2026-09-22
ScoreAttention src/models/programs.py ran · metamorphic tier: deterministic no licence file found · pointer only · 3af625298c24b59b · report fixture: returned ScoreAttention · level recorded 2026-09-22
Unembed src/models/programs.py ran · metamorphic tier: deterministic no licence file found · pointer only · f6f581a88d741f08 · report fixture: returned Unembed · level recorded 2026-09-22
WPred src/models/programs.py ran · metamorphic tier: deterministic no licence file found · pointer only · 2792e151572ee1ec · report fixture: returned WPred · level recorded 2026-09-22
WScore src/models/programs.py ran no licence file found · pointer only · db92ccece8dc55e0 · report fixture: signature W_Q:Tensor/3/float · returned Tensor · level recorded 2026-09-24
softmax in 240 papers
census: 53 implementations from 63 papers, 16 distinct outputs across 8 buckets, one shared input per bucket this sample: bucket 1 of 8, arg 1: rank 2, kind float, dtype float32
src/models/programs.py ran · our draft was wrong fingerprinted no licence file found · pointer only · e3599c195e20c0fc · report fixture: signature X:Tensor/2/float, dim:int/0/int, tau:float/0/float · returned Tensor · level recorded 2026-09-22
softmax_no_temp src/models/programs.py ran · our draft was wrong fingerprinted no licence file found · pointer only · e35b60a92f2a52b5 · report fixture: signature X:Tensor/2/float, dim:int/0/int · returned Tensor · level recorded 2026-09-22
subsoftmax src/models/programs.py ran; the contract check could not run (RAISES) · metamorphic tier: invariant no licence file found · pointer only · 1316961252e8ad54 · report fixture: signature X:Tensor/2/float, dim:int/0/int, k:int/0/int, tau:float/0/float, f:callable/0/? · returned Tensor · level recorded 2026-09-22
CatAttention src/models/programs.py unverified no licence file found · pointer only · becdbd159c1bead4 · report
CatMLPs src/models/programs.py unverified no licence file found · pointer only · 82fcb68539de38cb · report
HookPoint src/models/programs.py unverified no licence file found · pointer only · ee5e8b570159bbdd · report
TransformerProgramBlock src/models/programs.py unverified no licence file found · pointer only · 4a864ddf34dc9452 · report
TransformerProgramModel src/models/programs.py unverified no licence file found · pointer only · d39196027884c33b · report

Method as code Syntology

What Syntology's graph records as this paper's claimed method, lifted into code: each assembly names its bricks (functions and classes), each with its own role and its own verification level. An assembly is not a check that the code implements the method correctly or reproduces the paper's results. Levels are each brick's own verification level in Syntology's graph (level 0: no recorded run), listed brick by brick and never combined into one level; “ran” means the brick executed on a synthesized input, not that its output is correct, and the instrument figure counts failures of Syntology's instrument, not of the code. Where a model read the code against the paper's claim, each assembly's label verdict is one model's judgement, kept in this page's JSON twin; it is not calibrated, so no card prints it.

1 assembly on this paper: 1 harvested, 0 generated.

harvested Assembly for Transformer Programs (graph method: Transformer Programs). 21 bricks; individually on a fixture: 16 ran (of which 12 constructed an object rather than computing a result; 13 with no instrument failure: 0 honoured, 0 violated, 13 with no contract checked; 3 where Syntology's instrument failed) · 5 unverified. The assembly has not been run end-to-end.

  1. TransformerProgramModel entry · level 0 · unverified · d39196027884c33b
  2. CatEmbed model · level 1 · ran · d12fd83022101c89
  3. HookPoint helper · level 0 · unverified · ee5e8b570159bbdd
  4. NumEmbed model · level 1 · ran · 5b3e2fc48121bc32
  5. OneHotPosEmbed model · level 1 · ran · 96c1455fd1928061
  6. TransformerProgramBlock model · level 0 · unverified · 4a864ddf34dc9452
  7. Unembed model · level 1 · ran · f6f581a88d741f08
  8. softmax helper · level 1 · ran · our draft was wrong · e3599c195e20c0fc
  9. subsoftmax helper · level 1 · ran; the contract check could not run (RAISES) · 1316961252e8ad54
  10. CatAttention model · level 0 · unverified · becdbd159c1bead4
  11. CatMLPs helper · level 0 · unverified · 82fcb68539de38cb
  12. NumAttention model · level 1 · ran · f02809a6319619b0
  13. ScoreAttention model · level 1 · ran · 3af625298c24b59b
  14. ClippedRelPosBias model · level 1 · ran · 758c7718eab6c7c7
  15. ConstrainedRead model · level 1 · ran · 15949249daac5067
  16. FixedRelPosBias helper · level 1 · ran · 5c3fbd7d9586f37e
  17. NoRelPosBias helper · level 1 · ran · c46a4f9300b88dc6
  18. WPred model · level 1 · ran · 2792e151572ee1ec
  19. CatMLP model · level 1 · ran · 70bbbfdf15549456
  20. WScore model · level 1 · ran · db92ccece8dc55e0
  21. softmax_no_temp helper · level 1 · ran · our draft was wrong · e35b60a92f2a52b5

Each brick ends with its code_sha256, Syntology's identity for that exact code; click one to copy the get_code call that returns it. For agents, on Syntology's MCP service: assembly(arxiv_id="2306.01128") returns these assemblies with each brick's role and wiring (how to connect).

Tasks

In-Context LearningInterpretable Machine LearningNamed Entity RecognitionText Classificationnamed-entity-recognitiontext-classification

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Methods

Absolute Position EncodingsAdamAttentionBPEDense ConnectionsDropoutLabel SmoothingLayer NormalizationLinear LayerMulti-Head AttentionPosition-Wise Feed-Forward LayerResidual ConnectionSoftmaxTransformer

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections