Zixuan WangBlogs

Polynomial transformer program

· About 16 min read

TL;DR

  1. We introduce the polynomial transformer program, which gives each intermediate variable its own slot. We can read a head’s attention score as a polynomial formula in those variables directly from its learned parameters.
  2. We use several examples to show how to read the programs. For reversal and global maximum, we recognized the rule in the formula. For modular addition, we had to plot the functions (substitute possible inputs and inspect the results) to see the wraparound. For histogram, even the plots left the counting rule unclear to us.
  3. We discuss where does the interpretability come from in our experiments, and whether it's worth the loss on the network capacity.

The mirror operator, read from the learned query and key matrices

16 positions
Sij ≈ −789(xj + 0.996xi)2 + C(xi)

The negative square peaks at xj ≈ −xi. Each position reads its mirror.

For each query position i, the peak is nearest to key position 15 − i.
The formula gives the mirror rule. Both plots evaluate it across possible key positions. The quadratic score is shifted to peak at 0, so its exponential peaks at 1. To compute attention weights, the model applies softmax to its full scores across the 16 key positions.

Motivation

Interpretability matters for algorithmic understanding and for AI safety. We want to know how a network turns an input into an answer. For a model that reverses a sequence, that means tracing each output token back to its source and explaining why the same rule works at every position.

To describe the network as a program, we ask two questions.

  1. Which intermediate variables does the network use? A program might store a source index in a variable. Distributed representations and superposition can make individual intermediate variables hard to inspect and isolate in a neural network.[1]

  2. What operations act on those variables? We can write down every linear map and activation function in a network and still struggle to recognize “read the token at the mirror position” in their composition.

Where does the c in the output come from?

Neural network

  1. abca
  2. ?
  3. acba

Readable program

  1. abca
  2. y[i] = x[L − 1 − i]
  3. acba

Here L is the input length and indices start at 0. With L = 4, the rule gives y[1] = x[2]. The second output copies the third input, c.

Researchers take two broad approaches to address these difficulties.

  1. Interpret a network after training. A probe tests whether a quantity can be decoded from an activation. A sparse autoencoder decomposes activations into candidate features. In circuit tracing, a replacement model approximates the MLPs. For a given prompt, researchers can then trace the linear contributions between active features.[3]

  2. Design the model around readable operations. Friedman and colleagues’ transformer programs compile to equivalent Python code. Its if/else branches let us follow which keys match a query and which values a head copies or sums.[4]

    Both transformer programs and our polynomial transformer programs keep intermediate variables in separate slots in the residual stream. Friedman and colleagues use binary match decisions to route attention. Our heads use polynomial operators to assign continuous attention scores to token pairs. For each input, softmax turns the scores into attention weights that specify how much each value contributes.

The method

Like a transformer, a polynomial transformer program takes a sequence as input and produces a sequence as output. Its residual stream has separate slots for different variables. Each layer lifts selected variables into a feature basis at each position. Softmax attention then combines values across positions. Together these operations can reverse a sequence, select a maximum, or count repeated symbols.

The residual stream

The input sequence typically supplies content tᵢ and position xᵢ for each token position i. Each variable occupies its own slot across the sequence. A layer reads existing slots and writes each new result into a fresh one. Earlier variables persist, so the number of available slots grows from layer to layer.

Separate variable residual stream

At input, each vector stores content t and position x in two scalar slots.

Position 0
t−1x−1
Position 1
t1x0
Position 2
t0x1
Position 2 after layer 1
0t
1x
111φ(x)
−0.76h₁

The input slots stay in place. The layer appends the vector φ(x) = (1, x, x²) and a scalar head output h₁. See how attention computes −0.76.

Lifting at each position

A lift selects one incoming slot and applies the same fixed function φ to each entry. For example, if the slot holds positions xᵢ, a quadratic lift writes uᵢ = (1, xᵢ, xᵢ²) into a new slot. Changing one position changes only its own feature vector. Lifting lets the attention score inside softmax depend nonlinearly on the original slot values.

A feature vector for each token

The same lift maps each position coordinate to its own 1 × 3 vector. The formula gives the order of the three components.

φ(x) = (1, x, x²)
Position 0 −1
Position 1 0
Position 2 1

Attention across positions

A head chooses three slots to read. At position i, it reads a query input qᵢ. At each allowed source position j, it reads a key input kⱼ and a value input vⱼ. Each input can come from a raw variable, an earlier result, or a lift. The same slot can serve more than one role.

To write the head in standard transformer form, stack the query, key, and value inputs as rows of XQ, XK, and XV. For example, row i of XQ is qᵢ⊤. The learned matrices WQ, WK, and WV stay fixed after training. For a given input, QK⊤/√d gives a score for each query–key pair. Softmax normalizes each query row over its allowed keys. The resulting attention weights sum to one and multiply the projected values in V.[5]

Standard attention
Q=XQWQ⊤ K=XKWK⊤ V=XVWV
H=softmaxrows(QK⊤d)V
Rewrite in terms of M
M=WQ⊤WKd
H=softmaxrows(XQMXK⊤)XVWV
Visualization of a two-layer polynomial transformer program

Read down a column for one token’s vector. The first two slots hold content t and position x. The panels show the formulas evaluated on this three-token input. Each colored wire reads or writes a whole variable across the positions. Hatched slots have yet to be written.

Three snapshots of the residual stream, each with token positions 0, 1, and 2 as columns. Head 1 reads the position lift for queries and keys and content for values, writing h₁ = (0.12, 0.68, −0.76) across the positions. Head 2 reads the same position lift for queries and keys and the lift of h₁ for values. It writes a pair of class scores at each position. The output classes are 1, 1, and 0. Three successive snapshots of the residual stream, each with token positions 0, 1, and 2 as columns. Head 1 reads the position lift for queries and keys and content for values, writing h₁ = (0.12, 0.68, −0.76) across the positions. Head 2 reads the same position lift for queries and keys and the lift of h₁ for values. It writes a pair of class scores at each position. The output classes are 1, 1, and 0.

* The input already includes the position lift φ(x) when head 1 reads it. The layer 1 panel likewise shows φ(h₁) ready for head 2.

Head 1 Sᵢⱼ = −2(xᵢ + xⱼ)². Position 2 reads mostly from its mirror, position 0. Applying the three softmax attention weights to the content values gives h₁ ≈ 0.881(−1) + 0.119(1) + 0.0003(0) ≈ −0.76.

Head 2 Sᵢⱼ = −2(xᵢ − xⱼ)². Its value projection reads φ(h₁) and returns (−h₁, h₁). At position 2 the weighted sum gives (0.59, −0.59). The first logit wins, so the output is class 0.

Illustrative projection parameters. Layout inspired by Figure 2 of Friedman et al.[4]

Model training

We train on input sequences paired with target outputs. Evolution searches over the slots each lift and attention head reads. For each candidate wiring, Adam fits the continuous parameters by minimizing cross-entropy at the positions with target labels.

What is searched or trained
H=softmaxrows(XQMXK⊤)XVWV M=WQ⊤WKd

Evolution searches

Choose the source slot and basis for each lift. Choose which slots supply XQ, XK, and XV to each head.

Adam trains

Fit each head’s three projection matrices WQ, WK, and WV. On some tasks, Adam also fits learnable input embeddings.

Before training, we fix the number of layers, heads and lifts, the permitted feature bases, the polynomial degree, and the attention mask. Softmax and the lift functions have no fitted coefficients.

Training pipeline

After search

  1. Post-train

    Keep each surviving wiring fixed and continue training its parameters with Adam.

  2. Select and evaluate

    Select the program with the highest token accuracy on fresh training examples, then measure its accuracy on held-out inputs.

Examples

For each trained program we ask how an input becomes an output. Can we read the algorithm directly from its formulas? If we need to plot the functions, does that reveal the whole rule? We count a numerical check as evaluation, whether we show the values in a plot or a table. The distinction is what it took to recognize the algorithm.

Reversing a sequence

Reverse 16 tokens. Output position 0 copies input position 15, position 1 copies position 14, and so on.

An illustrative input and the trained program’s output
Position i0123456789101112131415
Input cᵢ4102357810111213141569
Output ŷᵢ9615141312111087532014

Index i is encoded as xᵢ = 2i/15 − 1 and token ID cᵢ as tᵢ = 2cᵢ/15 − 1.

Wiring and learned projections

Head inputs
Reversal head
φ(x) = (1, x, x²)Position xQuadratic liftφ(t) = (1, t, t²)Token code tQuadratic liftQueryKeyValue

Both lifts use the basis (1, z, z²). For output position i and source position j, the selected feature rows are

XQ[i, :] = (1, xᵢ, xᵢ²)
XK[j, :] = (1, xⱼ, xⱼ²).

The learned projections and their product M use those three features in that order. Entries are rounded to two decimals.

19.62−27.20−0.13
19.4126.69−0.09
19.3426.71−0.19
−19.5727.590.16
7.3328.87−20.13
7.66−29.16−20.48
8.34−29.27−20.54
−7.27−28.9219.85
298.110.19−789.20
13.67−1571.86−0.11
−2.18−0.095.73
attn_scoreij = (XQ M XK⊤)ij
≈ 298.11 + 0.19xⱼ − 789.20xⱼ²
+ 13.67xᵢ − 1571.86xᵢxⱼ − 0.11xᵢxⱼ²
− 2.18xᵢ² − 0.09xᵢ²xⱼ + 5.73xᵢ²xⱼ².

For a fixed query, the terms involving only xᵢ shift every key’s score equally. Complete the square in the two dominant key-dependent terms, −789.20xⱼ² and −1571.86xᵢxⱼ, and collect the query-only offset in C(xᵢ).

attn_scoreij ≈ −789.20 (xⱼ + 0.996xᵢ)² + C(xᵢ).

The square is smallest near xⱼ = −xᵢ. On the 16-position grid, that gives the address j = 15 − i. Since the value comes from the token slot, the formula suggests copying the token at the mirror address.

Three downward parabolas. The highest-scoring integer keys for queries 2, 7 and 12 are 13, 8 and 3 respectively.
The curves use all coefficients from the learned query and key matrices, including the small terms omitted above. Dots mark the highest-scoring integer keys.

Plotting the full score confirms the mirror address for all 16 queries. Applying softmax on the integer keys gives the mirror more than 99.9998% of each row’s attention. Evaluating the value projection on all 16 token codes shows that each token gives its own class the largest vote, and that lead survives the weighted sum. The first output is 9 because the last input is 9.

Value projection for the 16 output classes

Each row below is one column of WV. For class c, its three coefficients multiply 1, t, and t² to give the class vote for that token.

Class1tt²
0−67.71−44.4998.61
1−36.09−44.3962.58
2−16.60−46.0430.12
3−3.71−48.92−2.94
44.73−53.99−41.86
512.20−51.01−80.30
618.00−40.56−120.30
721.78−15.03−138.95
Class1tt²
821.8015.45−139.88
918.0040.78−120.30
1012.2451.08−80.01
114.8054.04−41.61
12−3.7449.22−3.03
13−16.5746.2630.16
14−36.0244.5262.64
15−67.5044.5998.52

Copying the token at the global maximum

Each input position holds a token and a distinct rank from 0 to 15. Every output must copy the token paired with rank 15. In this sequence, that token is 4.

An illustrative input and the trained program’s output
Position i0123456789101112131415
Rank Rᵢ3158213701151461104912
Token cᵢ7492135814011631210151
Output ŷᵢ4444444444444444

Rank Rᵢ is encoded as rᵢ = Rᵢ/15 and token ID cᵢ as tᵢ = 2cᵢ/15 − 1.

Head inputs
Maximum head
φ(t) = (1, t, t², t³)Token code tCubic liftr ↦ r (identity)Rank rScaled rank slotQueryKeyValue

The query reads four features of the output token. The key reads a single number from each candidate source. Their feature rows are

XQ[i, :] = (1, tᵢ, tᵢ², tᵢ³)
XK[j, :] = (rⱼ).
−11.1720.0110.086−0.018
11.217−0.0290.063−0.034
11.1990.0240.0590.087
11.1220.029−0.027−0.053
−11.102
11.160
11.058
11.145
248.507
0.072
0.046
0.097
attn_scoreij = (XQ M XK⊤)ij
≈ (248.507 + 0.072tᵢ + 0.046tᵢ² + 0.097tᵢ³) rⱼ.

The parenthesis is positive for every token. Since |tᵢ| ≤ 1, its three token-dependent terms change 248.507 by less than 0.22. Multiplying the rank by a positive number preserves its order. The formula therefore tells every query to read from the position with rank 15.

All 16 query curves rise nearly identically from zero to about 248 as key value increases from zero to one.
One score curve per query token. The curves nearly coincide, and all select the rightmost key value.

The plot checks the positive slope at all 16 token codes. On the 16 ranks, the softmax weight on rank 15 exceeds 0.9999999 for every query. Evaluating the class votes confirms that the selected token keeps its own class after averaging. Here the winning token is 4, so every position outputs 4.

Adding two tokens modulo 13

Add the first two tokens, a and b, and report the remainder modulo 13 at every position. The tables give digit IDs dᵢ at indices i, so a = d₀ and b = d₁. Each of the other 14 digits can take any value from 0 to 12.

7 + 5 = 12, so every output is 12.
Position i0123456789101112131415
Input dᵢ7566666666666666
Output ŷᵢ12121212121212121212121212121212

Index i is encoded as xᵢ = 2i/15 − 1 and digit dᵢ as tᵢ = dᵢ/6 − 1.

7 + 6 = 13, so every output is 0 modulo 13.
Position i0123456789101112131415
Input dᵢ7666666666666666
Output ŷᵢ0000000000000000

Index i is encoded as xᵢ = 2i/15 − 1 and digit dᵢ as tᵢ = dᵢ/6 − 1.

Which positions supply the operands?

Head inputs across two layers
Layer 1
φ(x) = (1, sin(πx), cos(πx))Position xPeriodic liftφ(x) = (1, x, x², x³)Position xCubic liftt ↦ t (identity)Token code tContent slotQueryKeyValue
Layer 2
φ(x) = (1, x, x², x³)Position xLayer 1 cubic liftφ(h) = (1, h, h², h³)Head 1 output hCubic liftQueryKeyValue

The first head reads two lifts of position. Its query features are (1, sᵢ, cᵢ), where sᵢ = sin(πxᵢ) and cᵢ = cos(πxᵢ). Its key features are (1, y, y², y³) with y = xⱼ. Its value is 9.615 times the digit code tⱼ.

Learned query and key projections and their coefficient matrix M

Each block shows the active features in basis order, rounded to two decimals.

Layer 1

23.870.25−1.99
−19.930.171.63
12.91−0.01−1.33
−21.430.11−1.40
1.53−2.470.511.34
−1.812.49−0.38−1.29
−0.22−2.460.531.15
−3.542.53−0.51−1.31
72.83−97.3218.6850.44
−0.150.060.00−0.02
−0.374.35−0.81−2.24

Layer 2

0.78−0.080.300.16
1.49−0.020.66−0.52
−1.330.04−0.52−0.48
1.970.000.810.15
1.561.172.410.50
2.07−1.733.56−0.37
0.930.36−3.010.79
−0.361.273.780.59
1.180.199.33−0.01
−0.06−0.02−0.190.00
0.530.023.85−0.01
−0.660.550.29−0.01
attn_scoreij = [XQ M XK⊤]ij ≈ Cᵢ
+ (−97.316 + 0.059sᵢ + 4.349cᵢ) y
+ (18.683 − 0.811cᵢ) y²
+ (50.437 − 0.022sᵢ − 2.235cᵢ) y³.

The query-only term Cᵢ cancels in softmax. The remaining coefficients do not give an obvious address. Plot the attention weights at all 16 × 16 query–key pairs and two columns stand out.

Sixteen rows of softmax attention weights. Every query has two dark cells at source positions 0 and 1. All other cells are near zero.
Each row is one query. Dark blue corresponds to an attention weight near 0.50, and the lightest cells are near zero.

Every query assigns about 0.50 to position 0 and 0.49 to position 1. All other positions together receive at most 1.06%. The head nearly averages the two operand codes, then scales that average by 9.615. This leaves a small range of hidden values for each sum, centered approximately at

hᵢ ≈ 0.8013 (a + b − 12).

Decoding the remainder

The second head reads cubic position features for its query. Its key and value both read (1, hⱼ, hⱼ², hⱼ³). Each column of its value projection gives one class a cubic vote. The two votes at the wraparound are

g12(h) ≈ 28.822 + 0.410h − 18.874h² − 0.322h³
g0(h) ≈ 23.188 + 7.763h − 5.291h² − 1.140h³.

The two cubics alone leave the remainder rule unclear. To find the winning class, compare all 13 votes at the same hidden value. The top plot shows the winning class. In the lower plot, each line is one class’s raw vote, and the highest line wins. Across the attainable sums the winner rises from 0 to 12, wraps to 0 at sum 13, then rises to 11 at sum 24. That wrap explains why changing the second operand from 5 to 6 changes every output from 12 to 0.

Winning class across sums 0 through 24. It climbs to class 12, wraps back to class 0 at sum 13 and ends at class 11. All 13 raw class votes on one plot from sum 0 to 24. The vertical scale expands votes near zero. At the center, the class 12 and class 0 curves cross, changing the winner between sums 12 and 13.
The horizontal axis expresses the hidden value in operand-sum units, 12 + 12h/9.615. In the top plot, blue segments mark the range reachable for each sum. The lower plot uses the scale asinh(v/16) to spread out curves near zero and compress the extremes. Tick labels give the raw vote v. At each integer sum, a dot marks the winning curve.

Checking the vote curves over each reachable interval gives a minimum lead of 0.61 for the correct class. The second head takes a weighted average of these vectors, so the same class wins at every position. The two heads together compute a code for the first two digits’ sum, then decode it modulo 13.

Counting the occurrences of each token

At each content position, return the number of times its symbol occurs in the sequence. There are six symbols and up to seven content tokens. The model reserves position 0 for the beginning of the sequence and pads each input to eight positions. Only the content positions have a target count.

The symbol 2 occurs three times and the symbol 4 occurs once.
Position i1234
Input sᵢ2422
Output ŷᵢ3133

Index i is encoded as xᵢ = 2i/7 − 1 and content symbol sᵢ as tᵢ = 2(sᵢ + 1)/7 − 1.

Reading the four-head program

How do the four heads turn a sequence into a count for each symbol? The heads run in parallel, just as they do in a standard transformer. At each query position, every head contributes a vote to each possible output class. The class with the largest total wins.

Head inputs in the counting layer
Head A
T(t) = (1, t, 2t² − 1, 4t³ − 3t, 8t⁴ − 8t² + 1, 16t⁵ − 20t³ + 5t)Token code tChebyshev lift 2x ↦ x (identity)Position xPosition slotQueryKeyValue
Head B
T(t) = (1, t, 2t² − 1, 4t³ − 3t, 8t⁴ − 8t² + 1, 16t⁵ − 20t³ + 5t)Token code tChebyshev lift 2T(t) = (1, t, 2t² − 1, 4t³ − 3t, 8t⁴ − 8t² + 1, 16t⁵ − 20t³ + 5t)Token code tChebyshev lift 1QueryKeyValue
Head C
T(t) = (1, t, 2t² − 1, 4t³ − 3t, 8t⁴ − 8t² + 1, 16t⁵ − 20t³ + 5t)Token code tChebyshev lift 2x ↦ x (identity)Position xPosition slotQueryKeyValue
Head D
x ↦ x (identity)Position xPosition slott ↦ t (identity)Token code tContent slotQueryKeyValue

In our attempt, the counting rule remained unclear after we read and plotted the score formulas. We could see how one head responds to repeated symbols. We found it hard to explain how its votes combine with the other three heads’ votes to give the output count on every input sequence.

A GPT 6.2 Astra attempted interpretation of the program

Let t = tᵢ be the query’s token code, u = tⱼ the source’s token code, and xᵢ, xⱼ their position coordinates. Each formula gives the raw attention score for that pair, before softmax. The model uses degree-five Chebyshev features for its token lifts. Here we expand the scores in ordinary powers, keeping six decimal places. For heads B and C, each line collects the terms with the same power of the source code u.

Head A · Read token values by position
Sᵢⱼ ≈ xⱼ (−20.723762 − 17.241826t − 34.980412t² + 73.075157t³ + 54.239199t⁴ − 57.849459t⁵)

The query token sets the slope of a straight line over source positions. At each source position, its value projection maps the token code to eight class votes, each a degree-five polynomial in u.

Head B · Read token values by token identity
Sᵢⱼ ≈ (6.594334 − 29.256749t − 48.448359t² + 89.907402t³ + 46.448645t⁴ − 62.225554t⁵)
+ u(1.597458 + 74.761196t − 10.352619t² − 198.463226t³ + 6.490395t⁴ + 126.951940t⁵)
+ u²(−32.142783 + 11.206678t + 189.568827t² − 40.828912t³ − 174.960529t⁴ + 30.279874t⁵)
+ u³(−13.630890 − 155.180189t + 74.306420t² + 437.452831t³ − 61.767046t⁴ − 289.570082t⁵)
+ u⁴(26.270588 − 7.595417t − 146.257289t² + 24.030473t³ + 134.328241t⁴ − 16.734488t⁵)
+ u⁵(11.261981 + 72.783090t − 69.709241t² − 213.233302t³ + 61.626504t⁴ + 143.975001t⁵)

Head B also computes eight value polynomials in u, with its own learned coefficients. For a fixed query, every copy of a symbol supplies the same score and the same value vector. For n copies of the query symbol, divide their total attention weight by the weight on BOS. The result is n times the single-copy ratio, which depends only on the symbol. This gives the head a signal proportional to the count.

Head C · Read positions by token identity
Sᵢⱼ ≈ (6.799562 + 0.362041t − 47.595404t² + 18.042653t³ + 45.104912t⁴ − 19.461812t⁵)
+ u(0.482454 + 55.663043t − 2.012709t² − 162.625231t³ − 0.309104t⁴ + 110.585774t⁵)
+ u²(−29.682059 + 19.501210t + 167.552579t² − 77.113658t³ − 154.505110t⁴ + 61.024370t⁵)
+ u³(−5.845834 − 146.536221t + 35.039232t² + 470.316261t³ − 27.615954t⁴ − 333.534944t⁵)
+ u⁴(27.996294 − 8.434673t − 142.827984t² + 30.361725t³ + 128.933849t⁴ − 23.687209t⁵)
+ u⁵(5.827184 + 85.374269t − 45.448011t² − 283.866906t³ + 41.132561t⁴ + 203.727870t⁵)

Head C weights source positions using its own token-pair polynomial. Its value at source j is xⱼ bC, where bC contains one learned coefficient per class. Each copy of a symbol therefore contributes its own position to the weighted sum.

Head D · Read token codes by position
Sᵢⱼ ≈ −0.282645 xᵢ xⱼ

The query position determines how much weight each source receives. The head averages the scalar token codes with those weights and multiplies the result by the eight-class vector bD.

Score and value coefficients for all four heads

The tables use the model’s original Chebyshev basis, in which Tₖ is the degree-k polynomial. The score coefficients are the active entries of WQ⊤WK/2. Each value table gives the active rows of the learned value projection, with one column per output class. Entries are rounded to six decimal places. In a score table, the row feature comes from the query and the column feature from the key.

Head A · Score coefficients
Featurexⱼ
T₀−17.874268
T₁1.408629
T₂9.629394
T₃0.190833
T₄6.779900
T₅−3.615591
Head A · Value coefficients by output class
Feature01234567
T₀−1.266799−0.715763−0.2695390.0734250.6753861.7114180.599589−1.253494
T₁1.6854301.0329790.063801−0.329016−0.941912−1.358643−0.5680771.660522
T₂−1.939411−1.394666−0.5824680.5118751.3351661.6629930.438805−1.985882
T₃1.0058261.9828930.548059−0.338053−1.522422−2.585057−1.4906161.117826
T₄−0.028964−2.859367−0.8954841.0097752.4753683.0901092.598721−0.038213
T₅0.2682133.4352261.068051−1.083112−2.645480−3.391627−2.7566390.302276
Head B · Score coefficients
FeatureT₀T₁T₂T₃T₄T₅
T₀−0.377750−1.1768830.273233−0.0609240.439379−0.030169
T₁−0.9740680.981394−0.260851−1.129689−0.0039520.177656
T₂0.4155210.2452980.6698130.304494−0.745566−0.252586
T₃2.950765−0.9864930.0166622.1193460.097261−0.519759
T₄1.167684−0.164791−2.5395180.4770652.0988790.481457
T₅−3.335066−0.0150780.423293−1.712521−0.1307380.562402
Head B · Value coefficients by output class
Feature01234567
T₀−1.377728−0.793564−0.1472360.2829520.7567071.6887310.673606−1.279839
T₁1.919712−6.464371−2.6894062.4123247.77638012.58772311.8950221.976304
T₂1.05242310.2851623.940093−4.967798−15.638450−21.593838−20.7525751.167390
T₃0.985409−4.810404−2.1276251.6256005.7033829.6695226.6061861.046247
T₄−0.3413685.6023502.072638−2.402263−7.601177−10.301762−7.382304−0.251042
T₅2.498945−5.855227−1.7341482.8186937.08675510.1000708.4983852.338538
Head C · Score coefficients
FeatureT₀T₁T₂T₃T₄T₅
T₀−0.156705−0.5715360.543654−0.1305850.616562−0.092007
T₁1.4580400.993960−0.330843−0.625839−0.058486−0.012249
T₂−0.5885290.274244−0.2116670.253621−0.868383−0.134858
T₃−1.604736−0.649811−0.0100601.0555470.023522−0.456360
T₄2.0253190.585848−1.5982040.7437422.0145910.321348
T₅0.135479−0.7647201.166786−1.232424−0.1850560.795812
Head C · Value coefficients by output class
Feature01234567
xⱼ1.427192−0.871040−0.1735810.4386761.4024332.1858912.6156471.297377
Head D · Score coefficients
Featurexⱼ
xᵢ−0.282645
Head D · Value coefficients by output class
Feature01234567
tⱼ1.407120−1.232039−0.420197−0.1469240.4902011.4816265.0756371.338192

To make a prediction, apply softmax to each head’s scores across its non-padding keys, including BOS. Let αHij be those attention weights for head H. Add the four weighted votes for each class and choose the class with the largest total.

ℓᵢ(c) = ∑H ∈ {A,B,C,D} ∑j αHij vHj(c),   ŷᵢ = argmaxc ℓᵢ(c).

Plotting the four score functions

For each head, evaluate its polynomial on the query and source values the task can supply. This shows how a head ranks possible sources before softmax. An individual sequence determines which of those sources appear and how often.

Head A. Every row slopes down from source position 0 to 7. BOS at position 0 scores highest for each of the six query symbols. Head B. BOS scores highest for each query. Among content sources, the matching symbol scores highest in every row. Head C. Head C also ranks BOS first and the matching symbol second. For query symbol 2, the scores are 15.3 for BOS and 6.1 for symbol 2. Head D. For query positions 1 through 3 the score rises with source position. For positions 4 through 7 it falls. All scores lie between −0.283 and 0.283.
Each cell gives a raw score Sᵢⱼ. The axes label the symbols or positions whose scalar codes enter the formula. The beginning-of-sequence token (BOS) at position 0 has a learned code of about −1.175 and is an allowed source. Padding has a learned code of about 0.054 and is masked. Use the color bar under each head to read its scale. B and C share a scale.

For every content symbol, head A gives the earliest source position the highest score. Head D’s slope changes sign with the query position, so its preference shifts from late to early sources. Heads B and C both give the matching symbol the highest score among the six content symbols. They use those scores to read different values. B reads a function of the source symbol, while C reads its position.

From a matching symbol to a count

Head B gives us one piece of a counting rule. Fix a query with token code t. Each of its n matching sources has score SB(t, t), and the single BOS token has score SB(t, b), where b is the BOS code. The softmax denominator is the same for all these sources and cancels in their ratio.

attention on all matches / attention on BOS
= n exp(SB(t, t) − SB(t, b)).

For query symbol 2, the unrounded scores give a single-copy ratio of 0.618. In the example above, its three copies together receive about 1.85 times as much attention as BOS. Each extra copy increases the ratio by another 0.618, whatever other symbols appear. This gives head B a signal proportional to the count. The program still has to turn that signal, the values of other symbols, and the positional reads into eight class totals.

The simple prediction min(n, 5) agrees with the checkpoint at 99.975% of content positions across all 335,922 valid sequences. This gives a close description of its behavior. After reading and plotting the scores, we still found it hard to derive one rule explaining how the four heads choose the winning class at every position.

Discussion

What made the reversal head readable? Once we completed the square, we recognized a fact from algebra. A negative square peaks when its argument is zero. Here that happens near xⱼ = −xᵢ, so we could predict which token the head would copy. Interpretability, in this sense, depends on whether the reader can recognize a familiar operation.

When do we recognize the rule?
  1. Level 1
    A familiar formula −789(xⱼ + 0.996xᵢ)² query 3 key 12 Reversal

    The square vanishes near the mirror position, predicting which token to copy.

  2. Level 2
    A familiar shape winning class 0 12 24 12 0 operand sum Modular addition

    Plot the 13 votes. Their winner rises to 12 and resets to 0 at sum 13.

  3. Level 3
    The whole rule stays unclear A B C D highest total wins Histogram

    Plots reveal head B’s count signal. How the four votes produce a count remains unclear to us.

ArchitectureLevel 1Level 2Level 3
Polynomial transformer programsExamples at all three levels
Ordinary neural networksRareUsually levels 2–3

The same three levels apply to an ordinary neural network: Its linear maps and activation functions may each be familiar, but reading their learned coefficients in combination rarely suggests a familiar algorithm for the whole task. On this criterion, we would usually expect an ordinary network to fall at level 2 or 3.

At level 2, we evaluate an unfamiliar expression and recognize the shape of the function. We can do that with either architecture. For example, Nanda and colleagues plotted activations in a one-layer transformer trained on modular addition and found periodic patterns. They traced those patterns through the network and tested an interpretation in which adding two numbers composes rotations around a circle.[6] At level 3, plots may reveal a useful component while the rule for the whole computation still eludes us.

Limitations

Our polynomial scores have an interpretability advantage over ordinary neural networks at level 1, and our programs leave that level quickly. In reversal, a negative square identified the mirror position. In global maximum, a positive slope told us to copy the token with the highest rank. Modular addition already took us beyond level 1. We could write down all 13 cubic votes, but we recognized the wraparound only when we plotted the winning class against the sum. For histogram, even plots of all four heads left the counting rule unclear to us.

On capacity, choosing a single source slot for each query, key and value and fixing the available feature bases imposes a strong inductive bias. It limits the computations a head can express and may make a good solution harder to find during training. In separate experiments beyond the four examples here, we found that our polynomial transformer programs had less capacity than ordinary neural networks on more difficult tasks. Besides, for the level 1 tasks here, one could just use a coding agent to write the programs -- reversing a sequence or selecting the token at the highest rank takes only a few lines of code

Separate slots give each variable a named place to read and write. How much of that structure do we actually need to impose? Goodfire found that many individual neurons in an ordinary language model had roles researchers could describe and use to predict activations on new text.[2] That suggests some useful variables can be found after training. We suspect the gain in readability is not large enough to justify sacrificing capacity to make a network look like a program, at least in our method and similar ones like transformer programs. Post-hoc interpretation starts with a network that already works. We can study its neurons directly or train a replacement model to approximate parts of its computation for circuit tracing.[3] Because both post-hoc approaches analyze the network after training, they have no or less capacity loss of restricting their architectures.

References

  1. Elhage et al. (2022). Toy Models of Superposition.
  2. Tigges, Kowal, McGrath, Lewis & Cammarata (2026). Neurons as an Interpretable Basis.
  3. Ameisen et al. (2025). Circuit Tracing: Revealing Computational Graphs in Language Models.
  4. Friedman, Wettig & Chen (2023). Learning transformer programs.
  5. Vaswani et al. (2017). Attention Is All You Need.
  6. Nanda et al. (2023). Progress measures for grokking via mechanistic interpretability.