Language models Working model Intermediate 129 parts 15 Oct 2026

Anatomy of GPT-2

A real GPT-2, scaled down to 0.94 million parameters, running in your browser. Type anything and watch it think.

This is not an animation of GPT-2; it is GPT-2. The tokenizer is byte-level BPE with GPT-2's own pre-tokenisation pattern, the network is GPT-2's block (pre-LayerNorm, causal multi-head attention, a 4x GELU MLP, residual adds, a tied read-out), and the forward pass runs in your browser on whatever you type. Only the sizes changed: 4 blocks instead of 12, 128 wide instead of 768, 1,024 tokens instead of 50,257, trained on children's stories so that a model this small can still write. Six panels follow one token through tokenisation, embedding, attention, the MLP, the logit lens and sampling, each with the theory and links into the library.

The machine

A type press. The newest slug on the rail is the token being computed; on each of four stepped tiers (the four blocks) threads tighten from earlier slugs to it as hard as that block attends to them, a dial reads how much the block's MLP rewrites it, and five plungers in a gantry rise to the five most likely next tokens. The drawn cap flies onto the rail and the press runs again.

What is real. Every number is computed in the page from the trained weights: a 940,800-parameter GPT-2 (int8, one scale per row) whose JavaScript forward pass is checked against PyTorch's logits to within 1e-5 before the page is built. Attention threads, dial readings, plunger heights, the logit lens and the sampling draw all come from that pass.

What to take away

  • A language model is one function applied over and over: tokens in, one probability for every token in the vocabulary out, draw one, append, repeat.
  • Tokens are vocabulary rows, not words: the merges are learned from data, applied lowest rank first, and fall back to bytes, so nothing is ever out of vocabulary.
  • Attention moves information between positions and the MLP transforms each position on its own; both only ever add to the residual stream.
  • Reading the stream after every block (the logit lens) shows the prediction forming with depth rather than appearing at the end.
  • GPT-2 small to XL differ from this miniature only in four sizes; the parameter formula in the page reproduces 124M and 1.56B from them.

Sources