Skip to main content
Explainers · Transformers
A Visual Primer

How a transformer
actually thinks.

Eight stages. The whole loop, one screen at a time.

Scroll
01

Text becomes tokens.

The model does not read words. It reads pieces (engineers call them tokens), drawn from a fixed set of about a hundred thousand, rather like Scrabble tiles that can be joined to build any word, including one it has never seen.

Why it mattersThis is why a model can misspell a name or miscount the letters in a word. It never saw the word whole.

“The barrister cross-examined unhappily.”
→
Thebarristercross-examinedunhappily.

11 pieces for 39 characters and 4 words.

Ordinary words the model has seen often are one piece each; longer or rarer ones are built from parts.

Genuine splits, computed in advance with a widely used tokeniser (OpenAI’s o200k vocabulary). Other models split differently, but the pattern is the same. A faint dot marks a piece that begins with a space.

02

Each token is a point in space.

Every piece is given a position on a map of meaning. Pieces used in similar ways end up close together, so “judge” sits near “barrister” and far from “horse”. Nobody drew the map; it formed as the model read. A dimension is simply one direction on that map. An ordinary map has two. This one has thousands, which lets it keep many kinds of similarity apart at once.

Why it mattersThe model works by nearness of meaning, not by definition. Similar is not the same, and that is one root of confusing one authority with another that sounds alike.

Closest to barrister: judge, advocate and solicitor. Farthest: horse.

Illustrative map. A real embedding has thousands of dimensions and no one has drawn it; this is a flattened sketch of how the neighbourhoods fall.

03

Every token looks at every previous token.

Before deciding what a piece means here, the model checks which earlier pieces it should pay attention to. In “the barrister opened her brief”, “her” matters because of “barrister”. Each row in the grid is one piece; the bright cells are the earlier pieces it is drawing on. Nobody programmed those links. They were learned from patterns in text.

Attention weights for the sentence “The barrister opened her brief because she needed notes”. Each row is the word being read; each cell is how much it draws on an earlier word. Values are illustrative.
ReadingThebarristeropenedherbriefbecausesheneedednotes
The1.00not yet seennot yet seennot yet seennot yet seennot yet seennot yet seennot yet seennot yet seen
barrister0.400.60not yet seennot yet seennot yet seennot yet seennot yet seennot yet seennot yet seen
opened0.200.550.25not yet seennot yet seennot yet seennot yet seennot yet seennot yet seen
her0.050.750.100.10not yet seennot yet seennot yet seennot yet seennot yet seen
brief0.030.300.400.100.20not yet seennot yet seennot yet seennot yet seen
because0.030.200.400.030.200.20not yet seennot yet seennot yet seen
she0.030.700.030.100.030.100.10not yet seennot yet seen
needed0.030.150.030.030.300.030.400.15not yet seen
notes0.030.100.030.030.450.030.030.300.15

Reading her, the model draws most on barrister (0.75), opened (0.10) and her itself (0.10).

Brighter cells = stronger attention. Tap any word, in the sentence or down the side, to see what it is drawing on. The model learns these links from data alone; the values here are illustrative.
04

It does this many times in parallel.

It runs that lookup several times at once, each copy hunting for something different. One tracks who is doing the action, one what belongs to whom, one grammar. These copies are called heads: several angles on the same sentence, then combined.

Head 1
previous token
Head 2
subject of clause
Head 3
coreference
Head 4
punctuation
05

Then each token is processed independently.

With context gathered, each piece is worked over on its own through a vast bank of learned associations, roughly “a barrister who has opened a brief is about to read papers”. This is where the model’s general knowledge lives. Not a database it consults, but millions of tuned connections. The widen-then-narrow shape below is just how that bank is wired.

Why it mattersNothing here is looked up or checked against a source. The knowledge was fixed when training finished.

in
→
expand 4×
→
out

Where most of the model’s knowledge is stored.

06

All of that, stacked 80 times.

One pass of stages 03 to 05 is a layer. The model runs the same layer design again and again, each pass reading what the previous ones wrote and adding to it, the way a pupil rereads a brief and understands more each time.

1 of 80 · Word kinds
Thebarristerthingopenedactionherbriefthingbecausesheneededactionnotesthing

By layer 1: Pieces have been joined back into words, and each word has a rough kind: barrister and brief are things, opened and needed are actions. Nothing yet about how they relate.

Illustrative: real layers do not divide their work this neatly, but the direction of travel, surface to meaning to prediction, is what the research shows.

Doing this many times lets understanding build up gradually. Early layers catch simple things — grammar, which word goes with which. Later layers handle abstract meaning — tone, intent, reasoning. Less like 80 separate machines, more like 80 rounds of revision on the same draft.

L1
attention
feed-forward
L2
attention
feed-forward
L3
attention
feed-forward
· · ·
L78
attention
feed-forward
L79
attention
feed-forward
L80
attention
feed-forward
Each layer reads the running notes, adds its own contribution, and passes them on — like a shared notepad running down the spine of the model. Nothing gets overwritten, so a useful insight from layer 3 is still available at layer 79. Engineers call this shared notepad the residual stream.

80 layers is roughly the depth of a model like Llama 70B. Different models go deeper or shallower — the idea is what scales, not the figure.

07

Output is a probability over every word.

The model does not produce a word. It produces a score for every possible next piece: “papers” 21%, “first” 14%, and so on down a list a hundred thousand long. It ranks; it does not decide. Something outside the model then picks from the list, usually with a little randomness thrown in.

Why it mattersThis is why the same question gets different answers on different days, and why a fluent sentence is only a chain of high-scoring guesses. A confident tone is not a sign that anything was checked.

“The barrister opened her brief and began to read the
↓
papers
21%
first
14%
witness
11%
opening
9%
judgment
7%
transcript
5%
~100k more
33%
1.00 · Balanced

The top words share the picks. This is roughly how models are usually run.

Press it a few times. Same sentence, same scores, different picks.

Illustrative figures. Real models score a vocabulary of around a hundred thousand pieces, which makes the tail heavier still. Lower temperature makes an answer more predictable, not more true.

08

Pick one. Append. Repeat.

Take the chosen piece, add it to the end, and run the whole machine again from the top. Press the button to watch it happen.

Why it mattersThere is no plan and no going back. Every sentence you read from a model was built one piece at a time, each chosen only from what came before it.

The barrister opened her brief and
0 tokens
Scores for the first piece
began31%
started22%
read14%
turned9%
found5%

Press Play. The list refreshes for every piece.

That is the whole machine.

No memory between steps. No checking against a source. A machine that has read more than any person could and remembers none of it as fact, guessing the next piece of text extremely well. Everything else in this series follows from that. Next: what the machine can actually see.

Next: The Context Window →