SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2106.06981 · ICML · 2021

Thinking Like Transformers

Eran Yahav, Yoav Goldberg, Gail Weiss

arXiv · PDF · Open in the Atlas

Code that ran

11 of 18 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; 2 honoured the contract we drafted, 1 violated it and 4 have no contract verdict; 4 failures of our instrument; 7 no recorded run); 1 of them was also run on the host, not in the jail, by the peer-agreement lane that set its level, 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/2106.06981.json · badge: /api/ran/2106.06981.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
tech-srl/RASP canonical (classifier label)
classifier basis: classifier_2025
5 ran · 5 no recorded run
princeton-nlp/transformerprograms community
Papers with Code archive
4 ran · 1 no recorded run
deepmind/tracr community
Papers with Code archive
2 ran · 1 no recorded run
FunctionStatusWhere it lives
is_comment Ran
ran, violated the contract we drafted
tech-srl/RASP/RASP_support/REPL.py
code served (permissive licence) · get_code("527cffd82932410e")
How it ran

Ran in Syntology's jail on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned bool, ndim 0, dtype family float, shape () as a later run recorded it. The image it ran in was not recorded. The comparison behind this sample's level is a different run: the peer-agreement lane ran it again on the host, not in the jail (report dated 2026-09-04T23:47:08Z). If your copy returns the same type, ndim and shape 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.

# Setup code for is_comment function

ARGS = {
    "line": "# This is a comment"
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type bool, ndim 0, dtype family float, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
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
AlreadyPrintedTheException Ran
ran on a synthesized input · constructed an object; no result was computed
tech-srl/RASP/RASP_support/FunctionalSupport.py
code served (permissive licence) · get_code("189b4e46925ee573")
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, AlreadyPrintedTheException: 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)

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 AlreadyPrintedTheException — 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 AlreadyPrintedTheException 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
NextId Ran
ran on a synthesized input · constructed an object; no result was computed
tech-srl/RASP/RASP_support/FunctionalSupport.py
code served (permissive licence) · get_code("d10a4856884491c5")
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, NextId: 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

torch.manual_seed(0)

# NextId.__init__ takes no parameters other than self
# The class initializes self.i = 0
# get_next() increments self.i and returns it

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 NextId — 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 NextId 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
_Annotations Ran
ran on a synthesized input · constructed an object; no result was computed
deepmind/tracr/tracr/rasp/rasp.py
code served (permissive licence) · get_code("4088156aa095d937")
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, _Annotations: 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 collections.abc
from typing import Any, Callable, Dict, Generic, List, Mapping, Optional, Sequence, TypeVar, Union

# Mock DEFAULT_ANNOTATORS since it's referenced but not provided
DEFAULT_ANNOTATORS = {
    "test_key": lambda expr: "default_value"
}

# Create a mock expression object
class MockExpr:
    def __init__(self):
        self.value = 42

# Construct valid arguments for _Annotations
mock_expr = MockExpr()

ARGS = {
    "expr": mock_expr,
    "kwargs": {
        "annotation1": "value1",
        "annotation2": {"nested": "dict"},
        "annotation3": 123
    }
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type _Annotations — 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 _Annotations output the recorded ndim 1 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
aggregate Ran
ran, honoured the contract we drafted
princeton-nlp/transformerprograms/programs/rasp/double_hist/double_hist.py
pointer only (licence: NONE) · get_code("fec1c122bc1ffea7")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, princeton-nlp/transformerprograms when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

aggregate_sum Ran
ran, honoured the contract we drafted
princeton-nlp/transformerprograms/programs/rasp/double_hist/double_hist.py
pointer only (licence: NONE) · get_code("40e0b3f88e966813")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, princeton-nlp/transformerprograms when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

annotate Ran
ran; our contract draft was wrong, not the code
deepmind/tracr/tracr/rasp/rasp.py
code served (permissive licence) · get_code("dacd53883797b544")
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 RASPExpr. 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 copy

class RASPExpr:
    """Minimal RASPExpr implementation for testing annotate function."""
    def __init__(self, value=None, annotations=None):
        self.value = value
        self.annotations = annotations if annotations is not None else {}
    
    def copy(self):
        """Create a copy of this expression."""
        new_expr = RASPExpr(value=self.value)
        new_expr.annotations = dict(self.annotations)
        return new_expr

# Create a minimal RASPExpr instance
expr = RASPExpr(value="test_expr", annotations={"existing_key": "existing_value"})

# Define arguments for the annotate function
ARGS = {
    "expr": expr,
    "new_annotation_1": "value1",
    "new_annotation_2": 42,
    "another_key": {"nested": "dict"}
}
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 RASPExpr — a RASPExpr output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a RASPExpr 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
creation_order_id Ran
ran on a synthesized input
tech-srl/RASP/RASP_support/FunctionalSupport.py
code served (permissive licence) · get_code("643410128e16a94a")
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 int, ndim 0, dtype family int; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim 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 numpy as np

torch.manual_seed(0)

# The function creation_order_id() takes no parameters
# It simply calls unique_id_maker.get_next() which increments and returns an id

ARGS = {}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type int, ndim 0, dtype family int — no output shape is stated: observe_signature.py could not observe it (no_inputs)
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
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
formatstr Ran
ran; our contract draft was wrong, not the code
tech-srl/RASP/RASP_support/REPL.py
code served (permissive licence) · get_code("4bc47faa32e9cf7e")
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) and returned str. 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

torch.manual_seed(0)

# The function formatstr takes a single parameter 'res' which can be either a string or something else
# If it's a string, it wraps it in quotes; otherwise it converts to string

# Test with a string
ARGS = {
    "res": "hello"
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str 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
select Ran
ran; our contract draft was wrong, not the code
princeton-nlp/transformerprograms/programs/rasp/double_hist/double_hist.py
pointer only (licence: NONE) · get_code("51fc4ee5a5955f4c")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, princeton-nlp/transformerprograms when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

select_closest Ran
ran; our contract draft was wrong, not the code
princeton-nlp/transformerprograms/programs/rasp/double_hist/double_hist.py
pointer only (licence: NONE) · get_code("09c0dae7b0da54e5")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, princeton-nlp/transformerprograms when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

RASPError Not yet run
unverified (harvested, no recorded run)
tech-srl/RASP/RASP_support/FunctionalSupport.py
code served (permissive licence) · get_code("c4c570c5bafb4f46")
How it ran

no invocation recorded.

RASPExpr Not yet run
unverified (harvested, no recorded run)
deepmind/tracr/tracr/rasp/rasp.py
code served (permissive licence) · get_code("0093ebab55f0cb4b")
How it ran

no invocation recorded.

RASPTypeError Not yet run
unverified (harvested, no recorded run)
tech-srl/RASP/RASP_support/FunctionalSupport.py
code served (permissive licence) · get_code("4520cbdca778c43b")
How it ran

no invocation recorded.

UnfinishedSelect Not yet run
unverified (harvested, no recorded run)
tech-srl/RASP/RASP_support/FunctionalSupport.py
code served (permissive licence) · get_code("04bc286a17d1056c")
How it ran

no invocation recorded.

UnfinishedSequence Not yet run
unverified (harvested, no recorded run)
tech-srl/RASP/RASP_support/FunctionalSupport.py
code served (permissive licence) · get_code("e9e07cd03cf1da14")
How it ran

no invocation recorded.

is_real_unfinished Not yet run
unverified (harvested, no recorded run)
tech-srl/RASP/RASP_support/FunctionalSupport.py
code served (permissive licence) · get_code("95bb5c3597ddb64d")
How it ran

no invocation recorded.

run Not yet run
unverified (harvested, no recorded run)
princeton-nlp/transformerprograms/programs/rasp/double_hist/double_hist.py
pointer only (licence: NONE) · get_code("b99713c212d2c8f6")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, princeton-nlp/transformerprograms when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. No invocation recorded.

Also present in other papers' code

Of 18 samples lifted from this paper's linked repositories, 18 carry a function identity and 0 do not. Of the 18 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 18 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

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.

For agents

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

get_harvested_code_for_paper("2106.06981")
get_code_for_paper("2106.06981")
have("2106.06981")

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

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

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

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

Connect an agent — have() is free.