Open Interpretability Models Contributors Research Posts About

Learning Transformer Programs

Source

Citation. Dan Friedman, Alexander Wettig and Danqi Chen, Department of Computer Science and Princeton Language and Intelligence, Princeton University. "Learning Transformer Programs". arXiv 2306.01128 [cs.LG]. Versions: v1 1 June 2023, v2 31 October 2023. We read v2. Paper. Code and example programs. The v2 PDF says "37th Conference on Neural Information Processing Systems (NeurIPS 2023)". Issue #4844 says the paper was an oral, and the PDF does not say this, so we did not check it. The data are public sets: CoNLL-2003 through Hugging Face Datasets, TREC, MR, Subj and AG News. Funding: the National Science Foundation (IIS-2211779) and a Sloan Research Fellowship.

Status. Not applicable. The paper trains a changed architecture whose units are discrete modules, not MLP neurons, and the harness can't load it. Its evidence goes to open issues as comments: #5149 and #3584 on positive controls, #5144 on token-set rules, and #3446 on reading weights.

Read. We read the arXiv v2 PDF on 2026-11-19, as text that pdftotext took from it. We also read the arXiv abstract page for the version history. We have the source's own text for the abstract, §1 to §6, the references and Appendices A to C. We did not see the figures as images. The bars of Figure 10 and the plots in Figures 6 to 8 and 13 came through only as axis labels. So the only numbers from them here are numbers that the text states. The code listings in Figures 4, 6, 7, 8, 9 and 13 came through as text. We did not read the code or the released programs. A model (Claude Opus 5.5) did the reading.

Summary

Claim. The authors constrain a transformer and train it by gradient descent. Then a fixed procedure turns its weights into an equivalent Python program in the style of RASP. They call these models Transformer Programs. They say the programs perform "on par with standard Transformers of comparable size" and are easy to interpret.

Method.

Findings, as the source reports them.

Setting Result
In-context learning, 2 layers, 1 head each (§4.1) "Perfect accuracy on a held-out test set". Head 1 copies the previous token. Head 2 is an induction head that matches a letter to the number after it
RASP tasks, best of grid (Table 1) Reverse 99.79, Histogram 100.0, Double histogram 98.40, Sort 99.83, Most-Freq 75.69, Dyck-1 99.30, Dyck-2 99.09 (token-level accuracy)
Model size on RASP (§4.2) Weiss et al. solve Sort and Reverse with two layers and one head. The best learned models use three layers and eight heads
Sort program (§4.2) A two-layer, four-head model above 99% compiles to about 300 lines without the classifier. One head looks for a 1 at early positions and a 4 at later ones
Longer inputs and larger vocabulary (Figure 10 caption) Both model types degrade. Transformer Programs degrade more, with "over a 50% accuracy gap" to the standard transformer in the hardest setting
Only categorical variables (Table 3) Reverse 99.75, Hist 83.20, 2-Hist 55.89, Sort 99.99, Most Freq 64.13, Dyck-1 99.43, Dyck-2 99.17
Program length, full and pruned (Table 4) From 324 and 160 lines (Hist) to 9,975 and 892 lines (Dyck-1)
NER, CoNLL-2003 (Table 2) F1: unigram 66.2, standard transformer 70.5, Transformer Program 76.1
Text classification (Table 6) TREC 85.6 against 88.6 for the standard transformer. MR 77.9 against 77.2, Subj 93.0 against 92.3, AG 90.8 against 91.7
Reverse with hand-set components, 3 seeds (Table 5) All random: 23.2, 23.6, 24.1. Attention reads, predicates and MLP reads set: 99.9, 99.9, 80.8. Only the MLP read random: 95.1, 94.1, 95.3. Layer-1 predicate random: 99.1, 83.9, 78.2. Each other attention component random: 13.7 to 44.1

The authors state the limits themselves (§6, C.3):

Where the claims go beyond the evidence

Use in this repo