Process vs outcome supervision
Two hand-written programs, one Transformer
Letter counting: we write the exact weights for a step-by-step solution and an all-at-once solution, in the same small network.
Running example on every slide: \(s_0 = 1,\ q = \mathtt{a},\ \text{word} = \mathtt{b\,a\,d\,a}\). Only basic linear algebra is needed. Every figure is computed live from the weights.
1 · Task
Count the query letter, mod \(m\)
| step \(t\) | 0 | 1 | 2 | 3 | 4 |
|---|---|---|---|---|---|
| letter \(w_t\) | b | a | d | a | |
| mark: is it a? | 0 | 1 | 0 | 1 | |
| state \(s_t\) | 1 | 1 | 0 | 0 | 1 |
- Process supervision: the model is trained to write every state \(s_1, \dots, s_4\), then the answer.
- Outcome supervision: the model is trained to write only the answer \(s_4\).
2 · The two programs in words
Step by step vs all at once
- Process (top row): write \(1, 0, 0, 1\). Each new state needs only the previous state and one mark: \(s_4 = (0 + 1) \bmod 2 = 1\).
- Outcome (bottom row): write only the answer. It must count all the marks at once: \(c = 2\), so \((1 + 2) \bmod 2 = 1\).
- Both get the same prompt and the same network. We write the exact weights for each by hand.
3 · Toolkit
Three facts from linear algebra
Every weight in this deck is built from these three facts.
1. One-hot vectors. Letter c of a, b, c, d is \(e_{\mathtt c} = (0, 0, 1, 0)\). Dot products test equality: \(e_i \cdot e_j = [i = j]\), i.e. 1 if equal and 0 if not.
2. ReLU makes an AND gate. \(\mathrm{ReLU}(x) = \max(0, x)\). For bits \(x, y \in \{0, 1\}\):
3. Softmax with one big score picks one entry. \(\mathrm{softmax}(z)_j = e^{z_j} / \sum_k e^{z_k}\):
One winner gives a lookup of one row. Several tied winners give their average.
4 · Sizes
Symbols and sizes
| Symbol | Meaning | Example | Default run |
|---|---|---|---|
| \(A\) | number of letters (a, b, c, d) | 4 | 4 |
| \(n\) | word length = number of steps | 4 | 12 |
| \(m\) | modulus, states are \(0, \dots, m{-}1\) | 2 | 2 |
| \(q,\ s_0\) | query letter, start state | a, 1 | random |
| \(|\mathcal V| = A + m + 3\) | token types: letters, state values, SEP, :, EOS | 9 | 9 |
| \(P = 2n + 6\) | longest row of tokens | 14 | 30 |
| \(W = 2A + 4m + 2n + 9\) | length of each token's vector | 33 | 49 |
| \(F = \max\{A,\ 3m(n{+}1),\ 2n{+}1\}\) | number of ReLU units per MLP | 30 | 78 |
5 · The network
A table of vectors, updated twice
- Attention + MLP is one block. There are 2 blocks.
- Each block has 3 heads, i.e. 3 independent copy operations \(h\).
- A row may only read rows at or before it (causal mask).
| Matrix | Shape | Example |
|---|---|---|
| \(E_{\mathrm{tok}}, R\) | \(|\mathcal V| \times W\) | 9 × 33 |
| \(E_{\mathrm{pos}}\) | \(P \times W\) | 14 × 33 |
| \(W^Q_h, W^K_h\) | \(P \times W\) | 14 × 33 |
| \(W^V_h\) | \(W \times W\) | 33 × 33 |
| \(W_{\mathrm{in}}, W_{\mathrm{out}}^{\top}\) | \(F \times W\) | 30 × 33 |
| Parameters | 17,154 |
6 · Inside each row
Each vector is split into named slots
| TL | the letter, one-hot | PREV | previous state \(s_{t-1}\) |
| TV | a state value, one-hot | MT | copy of the mark (process) |
| POS | the position, one-hot | CNT | the count \(c\) (outcome) |
| QRY | copy of the query \(q\) | S0 | start state \(s_0\) (outcome) |
| MATCH | the mark \([w_t = q]\) | OUT | the value to print |
7 · Who writes each slot
Given by the tokens vs written by the network
| Slot | Written by | Which rows |
|---|---|---|
| TL, TV, POS | input: \(E_{\mathrm{tok}}[\mathrm{ids}] + E_{\mathrm{pos}}\) | TL at letters, TV at state tokens, POS everywhere |
| QRY | block 0, head 0 | letters \(w_1..w_n\) |
| MATCH | block 0, MLP | letters equal to \(q\) |
| PREV, MT | process block 1, heads 0, 1 | rows that predict \(s_t\) |
| CNT, S0 | outcome block 1, heads 0, 1 | the row that predicts \(s_n\) |
| OUT | block 1 MLP (process head 2 for the copy) | rows that predict a state |
- TV is never computed. It is part of the input: the one-hot value of a state token.
- Row 0 holds \(s_0\), from the prompt.
- Process: rows \(s_1..s_n\) are tokens the model printed in earlier passes, fed back. Their TV is the model's own output, not a new slot.
- Outcome: no such rows. TV is set only at \(s_0\) and the final answer.
- Every other slot starts at 0 and is filled by one hand-written head or MLP.
- The map is free run: row \(i\) only sees rows \(\le i\), so one pass over the generated row gives the same rows as pass-by-pass generation. EOS is greyed out because no pass computes it.
8 · Inference
At inference: one token at a time
9 · Process program, every matrix
Producing row 8: every matrix
10 · Outcome program, every matrix
Producing row 8, outcome weights
11 · Playground
Run both programs
Change the query, start state or letters. Both programs should match the correct row for every input.
- The matrix \(X\): rows = tokens, columns = slots
- Blue \(\gt 0\), red \(\lt 0\); hover for values
12 · Summary
Same answer, very different programs
| Process | Outcome | |
|---|---|---|
| Embeddings + block 0 | identical weights (0 entries differ) | |
| Block 1 + readout | different weights (readout: just 4 entries, for ':' and EOS) | |
| Marks read per output | 1 | all \(n\) |
| Block-1 heads used | 3 | 2 |
| Block-1 ReLU units | \(2m\) (example: 4) | \(3m(n{+}1)\) (example: 30) |
| Grows with \(n\)? | no | yes |
| Supervised tokens | \(n + 3\) | 3 |
- Both programs are exact and live in the same network.
- Process: a small rule applied \(n\) times. Outcome: one large lookup over every possible count.
- Next: train one random starting point under each loss and compare it with these two programs.
Appendix
Each part as a picture
The same computations as slides 8–9, drawn as token diagrams instead of matrices.
A1 · Attention
Each head looks up one row
- By fact 3, softmax puts weight \(\gt 0.99999\) on row 5
- The value matrix copies one slot, e.g. MATCH of row 5 into MT of row 9
- Click the buttons to see the other heads
A2 · Block 0 (same for both)
Mark each letter: is it \(q\)?
A3 · Block 0 · inside the MLP
One AND gate per letter
| \(\mathrm{TL}_a\) | \(\mathrm{QRY}_a\) | inside ReLU | output |
|---|---|---|---|
| 1 | 1 | \(+0.5\) | 1 |
| 1 | 0 | \(-0.5\) | 0 |
| 0 | 1 | \(-0.5\) | 0 |
| 0 | 0 | \(-1.5\) | 0 |
- In general only gate \(a = w_t = q\) can fire
- Weights: \(W_{\mathrm{in}}\) has 1 on TL\(_a\) and QRY\(_a\), bias \(-1.5\), \(W_{\mathrm{out}} = 2\)
A4 · Process · block 1
Each step: last state + one mark
A5 · Process · inside the MLP
Two AND gates per state value
| \(\mathrm{PREV}_j\) | MT | no-match gate | match gate | writes |
|---|---|---|---|---|
| 1 | 0 | 0.5 | 0 | \(\mathrm{OUT}_j\) |
| 1 | 1 | 0 | 0.5 | \(\mathrm{OUT}_{j+1}\) |
| 0 | 0 or 1 | 0 | 0 | nothing |
- In general exactly one gate fires; \(W_{\mathrm{out}} = 2\) turns 0.5 into 1
- \(\Rightarrow \mathrm{OUT} = e_{s_t}\), and the readout prints \(s_t\)
A6 · Outcome · block 1
One row reads all \(n\) marks at once
A7 · Outcome · inside the MLP
A spike detector for each count
| count \(x\) | \(r(x{-}c'{+}1)\) | \(r(x{-}c')\) | \(r(x{-}c'{-}1)\) | \(\beta_{c'}\) |
|---|---|---|---|---|
| below \(c'\) | 0 | 0 | 0 | 0 |
| \(c'\) | 1 | 0 | 0 | 1 |
| \(c'{+}d\), \(d \ge 1\) | \(d{+}1\) | \(d\) | \(d{-}1\) | 0 |
- In general 3 ReLUs make one spike, one spike per \((s_0, c')\)
- A large negative bias switches off every \(s_0\) group but the true one
- Spike \((s_0, c)\) writes OUT\(_{(s_0 + c) \bmod m} \Rightarrow\) prints \(s_n\)