Build the context from tiles
Start with a marker, two color labels, and first or last. Every tile has an exact ID in a seven-token vocabulary. The model predicts a next token from those IDs; it does not receive a hidden English interpretation.
Open a genuinely trained miniature Transformer. Change token tiles, inspect real attention and vector calculations, sample a continuation, and test the limits of a confident prediction.
Enable JavaScript to change the conditions and run the interactive experiment.
A fixed model computes a distribution from its current context. Attention mixes vectors, later transformations produce token scores, and sampling chooses an output. Changing context, changing sampling and changing trained parameters are different interventions.
The model predicts red, but its largest attention weight belongs to first. What should the visualization do?
Attention mixes vectors before further transformations. Preserving a surprising result is essential to an accurate explanation.
Start with a marker, two color labels, and first or last. Every tile has an exact ID in a seven-token vocabulary. The model predicts a next token from those IDs; it does not receive a hidden English interpretation.
Each ID selects an eight-number embedding row. A learned vector for that input position is added. Replacing a token changes its embedding; moving it also changes the position contribution.
Query and key vectors produce scaled dot-product scores. Causal masking forbids later positions. Softmax normalizes the allowed scores, and those weights mix value vectors rather than token IDs.
The mixed value is projected, added through a residual path, transformed by a ReLU feed-forward network, added through another residual and projected into seven output logits. A second softmax normalizes candidate tokens.
For red–blue–first, the next-token winner is red although the final attention row mostly weights first. The display retains those actual values. Inspect the full computation instead of replacing the attention pattern with a convenient story.
A categorical sample chooses a token from the output distribution. Append it, then recompute from the extended context. Stop at the end marker or when another inference would exceed five input positions; no tokens are silently discarded.
Give the model first without any color. It still places high probability on red. The output exists, but that format has no established color-selection answer in the training task.
This original decoder has one block, one head, width 8, feed-forward width 16, 695 parameter slots, learned positions, separate input/output matrices and no normalization or dropout. It is a symbolic color-selection model, not an English chatbot or a replica of a modern large model.
IDs 0–6 mean <bos>, <eos>, red, blue, green, first and last. The editor canonicalizes whitespace and rejects unknown labels. An ID is a row selector; its numeric magnitude is not its meaning or probability. The checkpoint and vocabulary must stay matched.
The optional red redder exercise begins with characters and retains the space. Four chosen merges produce red, space, red, der. This demonstrates that tokens need not equal words. Its hand-constructed vocabulary and ranks are not used by the neural checkpoint.
For row vectors x, the model forms q=xWq, k=xWk and v=xWv. Each allowed attention score is q·k/√8. A stable softmax subtracts the maximum allowed score before exponentiating. Future positions have score −∞ and weight exactly zero.
Attention softmax distributes mass over allowed context positions. Output softmax distributes mass over seven candidate next-token IDs. A 0.9 attention weight on first does not mean a 0.9 probability of emitting first.
Attention’s weighted value sum passes through Wo and adds to x. A position-wise ReLU network and a second residual produce z. Output logits are zU+b. The exploded stack shows actual vectors at one selected position; cell height is a declared compressed visual scale, not a physical dimension.
For <bos> red blue first, the final attention weights are approximately 0.000858485, 0.003125844, 0.096708236 and 0.899307436. Multiplying them by value-coordinate-0 entries and summing gives approximately −1.957841407. Full-precision values drive the visualization.
Connection removal sets one allowed attention entry to zero, renormalizes the remaining row, and recomputes downstream layers with the original queries, keys, values and parameters. Removing the only remaining allowed connection is undefined. Replacing a token changes its vectors and normalization, so it tests a different intervention.
Published work debates which explanatory claims attention supports and how to test them. A heatmap alone, or one ablation, does not establish a complete mechanism. This workbench shows measured intermediates and specific changed calculations without inventing a natural-language inner monologue.
All 18 six-token sequences supply five input–next-target pairs. At input position i, the current token is known, so attention to itself is allowed. Inputs at positions later than i cannot influence its logits. Showing a full training worksheet does not grant the model access to those future answers.
Training uses the ground-truth preceding tokens while computing 90 next-token targets per full batch. Generation instead appends its selected output before the next forward pass. Ordinary inference neither computes a gradient update nor changes the checkpoint.
For positive temperature τ, output probabilities are proportional to exp((logit−maximum)/τ). Changing τ leaves current logits and attention fixed. Greedy choice is a separate operation, with exact ties resolved by lowest token ID. A different sampled token can change later context and therefore later attention.
The educational 32-bit LCG advances state once for each random draw, then u=state/2³². Choose the first cumulative probability strictly greater than u. Seed 49 begins with 0.2550580417737365 and 0.7230514015536755. It is a classroom generator, not cryptography.
For the separate logits [ln 6, ln 3, 0], temperature 1 gives [0.6,0.3,0.1]. Temperature 0.5 gives [36/46,9/46,1/46]. This card is intentionally distinct from the trained model’s often much sharper distributions.
The corpus enumerates three first colors, three second colors and two queries: 18 sequences. All are used in training, without a held-out split. The 18/18 answer-position result is a training-task check, not evidence of generalization or a reasoning benchmark.
Earlier identical prefixes genuinely admit several next targets: three first colors, three second colors and two queries. The empirical conditional loss floor is (ln 3+ln 3+ln 2)/5≈0.578074352 nats per target. Near-perfect answer selection does not make mean loss over all five targets zero.
The downloadable original code initializes from NumPy PCG64 seed 49 and performs 2000 full-batch Adam updates in float64. The final loss is approximately 0.578083150. The ledger’s points are recorded values, not live training. The exact checkpoint and corpus have separately recorded SHA-256 hashes.
Larger systems can have different architectures, richer pretraining, post-training, reasoning behavior, tools and context handling. A next-token interface does not settle what algorithms a learned computation implements. This tiny experiment neither demonstrates nor rules out those larger capabilities.
Ask whether arrows show measured attention, a proposed explanation or actual intervention results. Follow the values and later computations; do not assume the prettiest arrow identifies a cause.
A prompt edit changes context computation; temperature changes selection from fixed logits; training changes parameters. Keeping these separate helps design an interpretable comparison.
A categorical model probability is not a verified probability that an independent claim is true. Use appropriate external evidence and task evaluation, especially for formats outside the model’s demonstrated data.
For the separate arithmetic card at temperature 1, draw red [0,0.6), blue [0.6,0.9), green [0.9,1). At a boundary choose the interval starting there.
Use 0.12, 0.72, 0.94, 0.31, 0.58, 0.88, 0.03, 0.65, 0.47, 0.99. Write labels before checking. They give 5 red, 3 blue, 2 green; expected counts for ten draws are 6,3,1.
Use the same values at temperature 0.5, with boundaries 0,36/46,45/46,1. Counts become 7,2,1. Explain why a finite supplied sequence need not match the expected counts.
In a separate exercise choose two colors uniformly, then first or last equally. Append the indicated color and the end marker. There are 18 equally likely full rule-based sequences.
Your paper sequence samples the exact empirical corpus rule. The browser checkpoint computes a learned approximation. A hand-written answer rule must not be presented as neural inference.
Record the probabilities, draw values, chosen intervals, context and stop condition. Explain which action changes sampling and which action changes the next context.
Can another person reproduce your token using the same row and draw?
No personal text, account, powered equipment or external inference is needed. The paper exercise is probability arithmetic and a conditional rule, not a model of brain training or a full language system.
Four: red, space, red, der The chosen merges combine characters while retaining the space. This result belongs to that tokenizer, not every model.
Remain unchanged Causal computation uses only the relevant prefix, including its current input.
−1.957841407 Multiply each attention weight by the corresponding learned value coordinate and sum all allowed contributions.
Neither; inspect the full path and defined interventions Connection removal and token replacement alter different computations. A heatmap alone does not establish a complete mechanism.
[36/46,9/46,1/46] with unchanged parameters Dividing logits by 0.5 sharpens their output softmax. It does not modify the current attention or checkpoint.
Blue because u lies in [0.6,0.9) Categorical sampling can select a lower-probability token. Real autoregressive generation then appends it and recomputes.
Earlier prefixes have multiple possible next targets The answer-position count and mean loss over all five targets measure different things. Ambiguous prefixes create a nonzero conditional entropy floor.
A confident continuation outside the trained grammar The output has no established color-selection answer on this unsupported format. This miniature cannot settle larger systems’ abilities.
Vaswani and colleagues, original Transformer paper. Our reduced decoder differs substantially; all product diagrams are original, not redistributed paper figures.
Vaswani et al. · Attention Is All You NeedSennrich, Haddow and Birch, ACL 2016. Our optional ordered-merge arithmetic card is hand constructed and separate from the checkpoint vocabulary.
Sennrich et al. · subword unitsKudo and Richardson, EMNLP 2018. No SentencePiece model or external vocabulary is used in this seven-token lesson.
Kudo & Richardson · SentencePieceJain and Wallace, NAACL 2019. Supports testing explanatory claims; not a theorem that all attention displays are useless.
Jain & Wallace · attention and explanationWiegreffe and Pinter, EMNLP 2019. Their proposed tests motivate explicit interventions and qualified interpretation.
Wiegreffe & Pinter · attention interpretationKingma and Ba, Adam. The corpus, seed, learning rate and finite run here are explicitly authored choices.
Kingma & Ba · AdamHoltzman and colleagues: autoregressive decoding and sampling. No paper-specific performance claims are transferred to the miniature.
Holtzman et al. · neural text degenerationLin, Hilton and Evans, ACL 2022. Historical TruthfulQA results do not rate current systems or calibrate this color model.
Lin et al. · TruthfulQAWei and colleagues study intermediate-step prompting in larger models. This miniature does not reproduce their training or results.
Wei et al. · chain-of-thought promptingNumPy qualifies cross-version random-stream guarantees. The exact checkpoint and complete corpus are supplied with hashes rather than relying on a seed alone.
NumPy · random compatibility policyIndependent subject review is pending.
Read the sources and model assumptions