Open Interpretability Models Contributors Research Posts About

Thinking Like Transformers (RASP)

Source

Citation. Gail Weiss (Technion), Yoav Goldberg (Bar Ilan University and Allen Institute for AI) and Eran Yahav (Technion). "Thinking Like Transformers". arXiv 2106.06981 [cs.LG], v1 13 June 2021, v2 19 July 2021. We read v2. Paper. Venue: Proceedings of the 38th International Conference on Machine Learning (ICML 2021), PMLR 139, as the PDF states. This agrees with issue #4842. Code: a RASP read-evaluate-print loop at github.com/tech-srl/RASP, with a link to the replication code. Funding: European Research Council, Horizon 2020 agreement #802774 (iEXTRACT).

Status. Planned. #4782 would use it in its synthesis on weight-space programming. #3584 names Tracr-compiled transformers as ground truth. RASP itself gives no weights and says nothing about single MLP neurons. So no code, skill or protocol rule can depend on it directly.

Read. We read the arXiv v2 PDF on 2026-11-19, as text that pdftotext took from it. We have the source's own text for the abstract, §1 to §6 and the references. We also have Appendix A (results and training details) and Appendix B (the RASP programs). The program listings in Figures 1 to 15 came through as text. We also read the arXiv abstract page for the version history. We did not see the figures as images, so we did not see the attention heatmaps. The symbols of Table 1's "Matches?" column came through garbled, so this page does not report that column. A model (Claude Opus 5.5) did the reading.

Summary

Claim. The authors propose a programming language, RASP, as a computational model of the transformer encoder. Attention maps to a select–aggregate pair, and the feed-forward sublayer maps to elementwise operations. A RASP program then gives an upper bound on the layers and heads that a transformer needs for a task. A transformer can be trained to follow such a program.

Method.

Findings, as the source reports them.

Setting Result
Compiled size (L, H) and best test accuracy (Table 1) Reverse 2, 1: 99.99%. Hist BOS 1, 1: 100%. Hist no BOS 1, 2: 99.97%. Double hist 2, 2: 99.58%
Same, continued Sort 2, 1: 99.96%. Most freq 3, 2: 95.99%. Dyck-1 2, 1: 99.67%. Dyck-2 3, 1: 99.85%
Average accuracy at L, H / H − 1 / L − 1 / L − 1, 2H (Table 2) Reverse 99.9 / – / 23.1 / 41.2. Hist 99.9 / 91.9 / – / –. 2-hist 99.0 / 73.5 / 40.5 / 83.5
Same, continued Sort 99.8 / – / 99.0 / 99.9. Most freq 93.9 / 92.1 / 84.0 / 90.2
Same, continued Dyck-1 99.3 / – / 96.9 / 96.4. Dyck-2 99.7 / – / 98.8 / 94.1
Sort with one layer fewer (§5) Not worse, and best in that case. The heads look nearly uniform. The authors read this as a bucket sort that uses the bounded alphabet
Reverse, trained without attention supervision (Figure 4 caption) The second-layer head matches the flip selector. The first-layer head prefers the last position, so it computes length in a different way from RASP
Hist BOS, without attention supervision (Figure 5) The text reports a "strong similarity" between compiled and learned patterns
Attention-supervised double hist (Figure 1 caption) 99.9% test accuracy, with 2 layers and 2 heads
Attention-supervised sort and most freq (Appendix A.1) Sort 99.0%, alphabet 52. Most freq 99.9%, alphabet 26. All three supervised models reach "99+%"
Shuffle-Dyck-2 (Figure 3) The program compiles to 2 layers and 3 heads, the same as the hand-built transformer of Bhattamishra et al. (2020)
Restricted attention (§4) A RASP sort for any length and alphabet uses Ω(n log n) of each head's n² pairs. The authors infer that attention with o(n log n) pairs loses expressive power

Where the claims go beyond the evidence

The authors state several of these limits themselves. These are the missing weights and embedding width, the sort exception, the extra Dyck-2 operator and the scope.

Use in this repo