Inside a language model, as it writes.
A real neural network is running in this tab. Give it a prompt and follow every step it takes to choose each next word: the tokens it reads, where its attention goes, and the odds it gives every word it knows. Every number on this page is computed live, on your device.
Six layers, unrolled over the text
One column per token. Information climbs through six layers; each cell shows the model's best guess so far, and the curves show which earlier tokens it read. Click any cell to take it apart below.
The weights download once; after that everything runs locally, in a background thread. No server does any of the thinking.
One token, step by step
The machine above does ten things to produce each token. Each gets its own instrument below, showing the real numbers for whichever token you select, in the bar or by clicking the machine.
Text becomes tokens
It starts from single characters, then keeps merging the adjacent pair that forms the most common known piece. That order was learned in advance from a large body of text: ␣t was the very first merge learned, ␣upon the 2,242nd.
Common words end up as one token. Rarer ones are spelled from parts, which is why this model sees the name “Lily” as ␣L + ily. A space belongs to the word after it (shown as ␣).
Every text also starts with a special <s> token that marks the beginning of a document.
Each token becomes 288 numbers
Nobody wrote these numbers. They started random and were nudged, billions of times during training, until the model predicted text well. Tokens used in similar ways drifted toward similar rows.
So meaning becomes geometry. The neighbours listed here are computed right now: the cosine similarity of this row against all 32,000 others.
The galaxy squeezes the 288 dimensions down to 3 (a UMAP projection), so distances are only roughly kept. Drag it to turn it; click a point to inspect that token.
Where each token sits
Each head works on 48 numbers, taken as 24 pairs. Pair 1 turns a full radian per position; each later pair turns more slowly, down to about one ten-thousandth of a radian for pair 24. Fast pairs track nearby order, slow pairs track long distances.
The trick (rotary position embedding, used by Llama and most modern models) is that when two rotated vectors are compared, only the difference of their angles survives. So attention sees how far apart two tokens are, not where they are in absolute terms.
Tokens look back at each other
Match = dot product of query and key, divided by √48. A softmax turns the matches into weights that add up to 100%, and the token receives the weighted mix of values. A token can only look backward: the future does not exist yet.
Each layer runs 6 of these heads side by side, each with its own learned questions. Below are all 36 of them on your text. Some settle into clear jobs, like always looking at the previous token; many park unused attention on <s>, a well-known habit called an attention sink.
Then each token thinks alone
Every neuron computes two things from the token's vector: a gate and a value. The gate goes through a curve called SiLU that is close to zero for negative inputs and passes positive ones almost unchanged; the neuron's output is gate × value. This design (SwiGLU) is what Llama uses.
Researchers find that individual neurons often respond to recognizable things: a word, a grammatical role, a topic. Pick any neuron to see where in your text it fires.
Six layers, one running sum
Because the stream keeps the same 288-number shape all the way up, you can stop it after any layer and ask the final read-out “what would you predict from this?”. That trick is the logit lens, and it is what the cells of the machine above show.
Straight after the embedding the stream still mostly says “I am this token”. Layer by layer it turns into “the next token is probably…”.
A score for every token it knows
A softmax turns logits into probabilities: raise e to each score and divide by the total. Big scores win by a lot, because the exponential stretches differences.
Temperature divides every logit before the softmax. Below 1 the leader pulls further ahead (more predictable text); above 1 the field flattens (more surprising text). Move the slider and watch the curve bend; nothing is re-run, it is the same 32,000 scores.
Rolling the dice
First, top-p keeps only the most likely tokens until their probabilities add up to p (here 0.95), which removes the long tail of nonsense. The survivors are rescaled to add up to 100% and laid end to end on a line from 0 to 1.
Then a random number between 0 and 1 is drawn, and whichever token's stretch of the line it lands on is written. Temperature 0 skips the dice and always takes the top token (“greedy”), which tends to loop and repeat.
And again, one token at a time
Rerunning everything for every new token would be wasteful, so the model keeps each earlier token's keys and values in a KV cache. A new token only computes its own query, key and value, then reads the cache. The two panels show that cache for layer 1: one row per token, growing as the story does.
The cost numbers are measured on your device, per token. Notice what dominates in a model this small: scoring the whole vocabulary at the end.
The same machine, much bigger
Bigger models have more layers, wider vectors, more heads, bigger vocabularies and far longer memories. Those numbers multiply: every token costs roughly two operations per parameter used.
The largest commercial models do not publish their sizes, so the comparison uses open models whose makers did. Everything they add (chat training, tools, agents) is built on top of this same next-token step. Much of that chat training is human work: people are paid to rate and compare model answers so the model learns which is better, and AITraining.jobs, which we also own, explains it in a plain-language guide to AI evaluation and rating.
| Model | Params | Layers | Width | Heads | Vocab | Context |
|---|---|---|---|---|---|---|
This model (stories15M) 2023 | 15.2M | 6 | 288 | 6 | 32,000 | 256 |
GPT-2 small 2019 | 124M | 12 | 768 | 12 | 50,257 | 1K |
GPT-2 XL 2019 | 1.6B | 48 | 1,600 | 25 | 50,257 | 1K |
Llama 3.1 8B 2024 | 8.0B | 32 | 4,096 | 32 | 128,256 | 128K |
Llama 3.1 70B 2024 | 70.6B | 80 | 8,192 | 64 | 128,256 | 128K |
Llama 3.1 405B 2024 | 405B | 126 | 16,384 | 128 | 128,256 | 128K |
DeepSeek-V3 2024 · mixture of experts: each token only runs 37B of the 671B | 671B | 61 | 7,168 | 128 | 129,280 | 128K |