2026-11-25 (3) · Claude and MJC
A transformer, worked through one byte at a time
tt-2 is a small transformer: 115,008 learned numbers, trained on the first 107 bytes of enwik9. It reads up to 128 bytes and gives a probability to each of the 256 values of the next byte. The whole model is running in this page. Pick a text, then click a byte: everything below is how the model gets from the bytes up to that one to its prediction of the next. For the shape of the model and the names of its parts, see the map (section 9).
1. What goes in, what comes out
In: the outlined byte and everything before it. Out: a probability for each possible next byte. The cost of a byte is −log2 of the probability it was given; the orange shading in the text shows that cost, from none (0 bits) to heavy (8 bits or more), for each byte given the ones before it.
2. Every position carries a vector
The model gives each position a vector of 64 numbers, its running vector. It starts as one column of a 64×256 table, picked by the byte there. So at the start, a position knows its own byte and nothing else. Two things are then added to it, twice over:
- heads bring in information from earlier positions. They are the only part that looks sideways along the text.
- neurons look at one position's vector and add something to it. They never look at any other position.
A layer is four heads, then 256 neurons. tt-2 has two layers. Nothing is ever overwritten: the final vector is a sum, and the next byte is read off from that sum, as a score per byte:
x is the final vector (each coordinate times a learned gain), eb is the same column used for byte b at the start, and rt is one over the size (root mean square) of x: it sets how sharp the distribution is.
Because it is a sum, we can stop part-way and ask what the vector says so far. Each row adds one stage. The 64 cells are the running vector (blue positive, orange negative, grey zero), the guess is the three most probable bytes if we stopped there, read with the same rt as the end.
3. A head: look back and copy a weighted average
A head asks a question of the positions behind it. Each position sends out a query q (what I am looking for), a key k (what I have) and a value v (what I will hand over), all linear functions of its vector. Position t gives position s the weight
The weights are a probability distribution over the positions s ≤ t, so a head is an event space whose events are “I read from position s”.
A toy with three positions
Here q and k have two numbers each and v has one. Move q. With q = (0, 0) all weights are equal. Point q towards a key and that position gets more; make q long and one position takes nearly all the weight, so the average becomes a choice.
The real eight
The heads of tt-2 at the outlined position. L0 is the first layer, L1 the second; the shading is each earlier byte's weight (the outlined byte itself is the last one). Click a head for its arithmetic. Heads of layer 1 read vectors that layer 0 has already filled in, so a position behind can hand over more than its own byte.
4. A neuron: a threshold that fires on a direction
Neuron i of a layer has a vector wi of 64 numbers and a vector ui. At a position with vector h it computes
h is the running vector after the layer's heads, divided by its root mean square, each coordinate times a learned gain.
So it is off on one side of a plane, and on the other it grows with distance. Where the heads moved information, the neuron can test for combinations. Adding mi ui to the vector shifts every byte's score by mi times a fixed number for that byte: the neuron is a vote. The neurons at the outlined position that matter most to the odds of the two bytes you pick:
5. Adding it up
The difference of the two scores, ln p()/p(), is a sum with one term for each part of the model, and nothing left over. Each bar starts where the last one ended. Blue pushes to the first byte, orange to the second.
6. Switch parts off
A switched-off part adds nothing, and everything after it is worked out again from what is left. With every head off, no position can see another, so the prediction depends on the outlined byte alone. Try it, then click another byte with the same letter: the prediction does not move.
7. Things to try
Each button loads a text; what to look at is beside it.
| The same five last bytes. With an open link the probability of ] is 0.37, without it 0.03. In section 3, L1H1 is the head that differs: it puts 0.58 of its weight on the two [, 5 and 6 back. | |
| Seeing both bytes, the model gives e 0.75. With heads off it sees only h, as at any other h, and e is not even first (section 6). | |
| The heads still look back, but the best guess is h, the outlined byte itself: a byte’s own column is also its output vector, so a vector that has not been changed much predicts its own byte. The neurons turn “which bytes are here” into “which byte comes next”. | |
| You would say k. tt-2 gives it 0.0007: it has no way to find an earlier copy and continue it. Larger transformers do this with a pair of heads; tt-2 did not learn it. | |
| A gets 0.87. In the first 107 bytes, which tt-2 was trained on, 1,251 of 1,326 titles start with A. In all of enwik9 it is 14,668 of 243,426. A pattern true of that text and not of the rest. | |
| t gets 0.999, the start of ". Compare section 2: at which stage does it become certain? |
8. In UM terms
| Part | Reading |
|---|---|
| byte in, byte out | the input and output event spaces, 256 events each; the scores are log support, softmax gives the probabilities |
| a head at a position | an event space over the earlier positions: “I read from s” |
| a neuron | a binary event space, on or off, with an amount of support when on |
| the running vector | where every part's support is added; it is not an event space itself |
| rt (and the scales inside) | changes how sharp an event space is, not the order of its events; it has no counterpart in fp |
| the head's average | an expectation under its event space; as q grows it becomes the choice in section 3, which is what max does |
Papers on this model: the literature review, what tt-2 does, the plan for rebuilding it as a UM.
9. Map: every learned number, and its name
All 115,008 numbers of tt-2, as shapes, without their values. Each matrix is drawn to scale, one unit per number along each side (the gains, which are one number wide, are drawn five wide). The colour of an edge says what it counts. A matrix takes a vector in along its top edge, one number per column, and gives one out with one number per row, counted on its left edge. So what comes out of one part can go into the next where those two colours match. The running vector x, 64 numbers (blue), is what every layer reads and adds to.
The same learned numbers are used at every position of every text. What differs from text to text is dashed: x, q, k, v, a, m, the scores. Point at the drawing to name a single number; click to keep what it belongs to.
The computation, with the names
Point at a name to see it in the drawing. Each layer has its own g1, WQ, WK, WV, WO, g2, W1, W2; the layer number is left off. ⊙ multiplies two vectors coordinate by coordinate; rms is the root mean square of a vector.
| start | xt = column bt of E | bt is the byte at position t |
| heads | ht = g1 ⊙ xt / rms(xt) | brings every position to the same size |
| qt = WQ ht kt = WK ht vt = WV ht | 64 numbers each: 16 for each of the 4 heads. q and k are then turned by an angle fixed by t (not learned) | |
| ats = exp(qt·ks/4) / Σs′≤t exp(qt·ks′/4) | in each head, with its own 16 numbers; s ≤ t | |
| xt ← xt + WO (Σs ats vs, the 4 heads stacked) | each head uses its own 16 columns of WO, so this is a sum of four terms | |
| neurons | ht = g2 ⊙ xt / rms(xt) | as before |
| mi = max(0, wi·ht) | wi is row i of W1, i = 0…255 | |
| xt ← xt + Σi mi ui | ui is column i of W2. Neuron i is the pair (wi, ui) | |
| end | scoreb = eb · (gf ⊙ xt) / rms(xt) | eb is column b of E; 1/rms(xt) is the rt of section 2. Then p = exp(score) / sum |
The learned numbers
The subscripts
| letter | runs over | where it appears |
|---|---|---|
| t, s | positions in the text, 0 to 127; s is the one read from | xt, qt, ks, vs, ats: never on a learned number |
| b | byte values, 0 to 255 | eb, scoreb |
| i | neurons of a layer, 0 to 255 | wi, ui, mi |
| Q, K, V, O, 1, 2, f | nothing: they are part of the name | query, key, value, output of the heads; first and second matrix of the neurons, first and second gain of the layer; final gain |
| LlHj, LlNi | layer l, head j or neuron i | L0H3 is the last head of the first layer; L1N228 is neuron 228 of the second |