Papers › Thinking Like Transformers

Thinking Like Transformers

13 Jun 2021arXiv:2106.06981archive 2025-07-28

Gail Weiss, Yoav Goldberg, Eran Yahav

What is the computational model behind a Transformer? Where recurrent neural networks have direct parallels in finite state machines, allowing clear discussion and thought around architecture variants or trained models, Transformers have no such familiar parallel. In this paper we aim to change that, proposing a computational model for the transformer-encoder in the form of a programming language. We map the basic components of a transformer-encoder -- attention and feed-forward computation -- into simple primitives, around which we form a programming language: the Restricted Access Sequence Processing Language (RASP). We show how RASP can be used to program solutions to tasks that could conceivably be learned by a Transformer, and how a Transformer can be trained to mimic a RASP solution. In particular, we provide RASP programs for histograms, sorting, and Dyck-languages. We further use our model to relate their difficulty in terms of the number of required layers and attention heads: analyzing a RASP program implies a maximum number of heads and layers necessary to encode a task in a transformer. Finally, we see how insights gained from our abstraction might be used to explain phenomena seen in recent works.

PaperPDFConference PDFCodeCode Syntology ran

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

For agents, Syntology's MCP tool lists every function and class Syntology harvested from this paper and whether it ran (how to connect): get_harvested_code_for_paper(arxiv_id="2106.06981")

Code

Syntology Ran 11 of 18 code samples harvested from 3 repositories linked to this paper; 7 have no recorded run. Of those that ran: 1 ran · violated contract; 2 ran · our draft was wrong; 8 ran with no contract checked.

By repository: official repository: 10 samples from 1 repository, 5 ran; community (archive-listed): 8 samples from 2 repositories, 6 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

tech-srl/RASP officialmentioned in papermentioned on GitHub report
deepmind/tracr mentioned on GitHubjax report
google-deepmind/tracr mentioned on GitHubjaxApache-2.0 report
princeton-nlp/transformerprograms mentioned on GitHubpytorch report
tvergara/tracr-injection mentioned on GitHubjax 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

18 samples harvested; 11 ran; 0 honoured the contract we drafted; 7 have no recorded run. Read from Syntology's graph 2026-09-24; that is when this build read the record, not when the samples ran.

1ran · violated contract
2ran · our draft was wrong
8ran
7unverified

Licence: 5 of the 18 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 3 repositories linked to this paper, official or community; each sample names its own and says which. “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. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself; “our draft was wrong” and “fixture could not drive it” are failures of Syntology's instrument, not of the code.

Each sample ends with its code_sha256, Syntology's identity for that exact code. An agent fetches the stored sample with Syntology's MCP tool get_code(code_sha256="…") (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 from a repository marked official are listed first. 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 four 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; or the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar). 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.

is_comment tech-srl/RASP/RASP_support/REPL.py official repository ran · violated contract MIT (permissive) · 527cffd82932410e · report
AlreadyPrintedTheException tech-srl/RASP/RASP_support/FunctionalSupport.py official repository ran MIT (permissive) · 189b4e46925ee573 · report
NextId tech-srl/RASP/RASP_support/FunctionalSupport.py official repository ran MIT (permissive) · d10a4856884491c5 · report
creation_order_id tech-srl/RASP/RASP_support/FunctionalSupport.py official repository ran MIT (permissive) · 643410128e16a94a · report
formatstr tech-srl/RASP/RASP_support/REPL.py official repository ran · our draft was wrong fingerprinted MIT (permissive) · 4bc47faa32e9cf7e · report
RASPError tech-srl/RASP/RASP_support/FunctionalSupport.py official repository unverified MIT (permissive) · c4c570c5bafb4f46 · report
RASPTypeError tech-srl/RASP/RASP_support/FunctionalSupport.py official repository unverified MIT (permissive) · 4520cbdca778c43b · report
UnfinishedSelect tech-srl/RASP/RASP_support/FunctionalSupport.py official repository unverified MIT (permissive) · 04bc286a17d1056c · report
UnfinishedSequence tech-srl/RASP/RASP_support/FunctionalSupport.py official repository unverified MIT (permissive) · e9e07cd03cf1da14 · report
is_real_unfinished tech-srl/RASP/RASP_support/FunctionalSupport.py official repository unverified MIT (permissive) · 95bb5c3597ddb64d · report
_Annotations deepmind/tracr/tracr/rasp/rasp.py community (archive-listed) ran Apache-2.0 (permissive) · 4088156aa095d937 · report
aggregate princeton-nlp/transformerprograms/programs/rasp/double_hist/double_hist.py community (archive-listed) ran no licence file found · pointer only · fec1c122bc1ffea7 · report
aggregate_sum princeton-nlp/transformerprograms/programs/rasp/double_hist/double_hist.py community (archive-listed) ran no licence file found · pointer only · 40e0b3f88e966813 · report
annotate deepmind/tracr/tracr/rasp/rasp.py community (archive-listed) ran · our draft was wrong Apache-2.0 (permissive) · dacd53883797b544 · report
select princeton-nlp/transformerprograms/programs/rasp/double_hist/double_hist.py community (archive-listed) ran no licence file found · pointer only · 51fc4ee5a5955f4c · report
select_closest princeton-nlp/transformerprograms/programs/rasp/double_hist/double_hist.py community (archive-listed) ran no licence file found · pointer only · 09c0dae7b0da54e5 · report
RASPExpr deepmind/tracr/tracr/rasp/rasp.py community (archive-listed) unverified Apache-2.0 (permissive) · 0093ebab55f0cb4b · report
run princeton-nlp/transformerprograms/programs/rasp/double_hist/double_hist.py community (archive-listed) unverified no licence file found · pointer only · b99713c212d2c8f6 · report

Tasks

Question Answering

Results from the paper archive 2025-07-28

TaskDatasetModelMetricValueRank at snapshotLeaderboardReport
Question Answering NewsQA OpenAI/o4-mini-2025-05-01-high EM 88.24 #3 of 18 Archive leaderboard report
Question Answering NewsQA OpenAI/o4-mini-2025-05-01-high F1 91.31 #3 of 18 Archive leaderboard report

Ranks are positions in the archive's leaderboards as they stood at the 2025-07-28 snapshot. Results published since then are not among these rows, so a rank here is not a current standing.

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