Skip to content

Model Explorer

A real, tiny decoder-only transformer, run in your browser. Type a prompt and see which word it predicts next, then follow any word through the 26 steps of the forward pass that produced that prediction. Every number on this page is computed live by a JavaScript port of the NumPy reference implementation, which you can download and run. The two agree to within 1e-9 on every attention weight, final hidden state and logit, and the canonical traces are available as a golden fixture. The trained weights are downloadable too.

The model has 2 layers, 2 attention heads, a 16-dimensional residual stream and a 25-entry vocabulary (23 words, a period and a start token). It was trained for 4,000 steps on a tiny synthetic grammar (subjects, verbs, objects, places and “then it …” follow-ups) using the Adam optimizer, so its predictions are grammatical for that toy language, but it knows nothing else. The Weights switch (Trained or Untrained) runs the identical computation with random weights: the arithmetic is the same, the predictions are not. The training script (tools/train_model.py), weights and checksum are all in the project, and every value can be reproduced independently, by hand or in code with Lab 10.

ChoiceThis modelA typical production LLM
Tokenizer25 entries: 23 whole words, a period and <bos>Subwords (BPE), 30k to 200k entries
PositionsFixed sinusoidal, added onceOften rotary (RoPE), applied inside attention
NormalizationRMSNorm before each sub-block, no learned scaleSame pre-norm pattern
MLPGELU, no biasesOften gated (SwiGLU)
OutputWeights tied to the embeddingTied or separate

To see how this model relates to real ones, read Compare with the toy model. Read the chapters for the full story: attention, the transformer block and tokens and embeddings.

  1. Follow sat and open step 7, Hide the future. Every token after it is blocked.
  2. Move to step 8, Turn scores into attention, and switch to Numbers. Check that the weights sum to 1 and that the blocked tokens get exactly 0.
  3. On step 6, Score every pair, open Numbers and recompute one score yourself from the displayed q and k.
  4. Switch between head 0 and head 1 at the same step. Heads are free to attend to different places.
  5. Try the example “the cat sat on the” and flip Weights between Trained and Untrained. Only the trained model puts almost all of its probability on mat and bed.
  6. Follow an earlier word to the last step. The model makes a prediction at every position; the Notice tells you whether it guessed the word that actually comes next.
  7. Shorten the prompt and compare: earlier tokens’ outputs do not change, because a token never reads the tokens after it.

Inspect specific calculations from the model, with computed results and explanations.

Spotted a mistake, a confusing explanation or a broken widget? Report a problem with this page

Methods & evidence · Run locally

Free for noncommercial use. Text CC BY-NC-SA 4.0, code PolyForm Noncommercial. Source on GitHub · How to contribute