tiny-gpt: a transformer written from scratch
A decoder-only transformer in numpy with hand-written backpropagation, trained on a laptop-class CPU. This page runs the same weights in plain JavaScript so you can watch what it attends to and try to break it.
Loading model...
01Generate and see how sure the model was
Each token is shaded by the probability the model gave it: pale means it expected it, strong colour means it was surprised. Hover a token to see where it looked; click to pin it.
02Inside the model
Left: the attention pattern of one head. Arcs show where the hovered token reads from; the grey triangle is the causal mask, the part of the sequence a token is never allowed to see. Right: what the model predicted at that position.
03Try to break it
The model learned positions 0 to 127 and nothing else. Ask it to go further and choose what the code does. Then compare temperature 0 with a hot sampler on the same prompt and seed.
Same prompt, same seed, same 60 tokens. Only the sampler changes.
04Evidence
Every number here is read from docs/results.json, written by python -m tiny_gpt.train, or computed live in this page.