Transformer
An AI design where every word in a sentence looks at all the others
- A transformer stops lining words up in a queue and gathers them at one table to look at each other at once. Almost every conversational AI sits on this design.
- Every word holds a question, a name tag and a folder. Pulling more from the folders of words whose tags match your question is what attention means.
- The meeting runs in several parallel versions and repeats through dozens of stacked layers. Lower layers catch nearby links, upper ones the drift of the whole text.
- Facing each other all at once erases order, so every word is also handed a seat number.
- All that machinery ends in one small act: choosing the next word, repeated a few hundred times.
Contents
1The analogy
"The bank was closed, so I sat on the bank and fished." Put that sentence on a round table. Instead of standing in a queue waiting their turn, four words sit facing one another. Neighbor or across the table, a glance reaches anyone.
There is one item on the agenda: who do I need to hear from before I know what I mean? The second bank studies fished and settles into being the edge of a river. The first bank leans on closed and stays a place that keeps money. That measured glance, deciding who to watch and how closely, is attention.
Nobody waits for a turn. All four words look around at the same moment, and when the round ends each carries a sharper sense of itself. The "bank" that leaves the table is no longer the blank, two-meaning word that arrived.
2In detail
No queue
The older approach lined words up and read them one at a time, each passing what it had gathered to the next. Long sentences faded at the front: after twenty handoffs, almost nothing of the opening survived. And since each step waited for the one before it, the whole thing crawled.
The round table fixes both problems. The last word sees the first directly, so distance costs nothing. In "I left the umbrella I bought yesterday on the train," the phrase about leaving reaches straight back and grabs the umbrella. Because every word scores every other simultaneously, the arithmetic splits across thousands of graphics chips. Training on enormous piles of text became practical because of this seating plan.
Matching questions against name tags
Each word at the table carries three things: a question in hand, a name tag on its chest, and a folder in front of it. The question says what it is looking for. The tag advertises what it can offer. The folder holds what it would actually hand over.
The second bank is holding a question about the verb that would explain it. It carries that question around the table and compares it with every tag. The tag on fished matches well and scores high. The tag on closed matches poorly and scores low. Scoring is not an election with one winner. It is a split: seventy to one word, twenty to another, the rest scattered.
Once the split is fixed, the folders are collected in those proportions. A generous helping from the high scorer, a spoonful from the low one, all blended into a fresh sense of itself. The question is the query, the tag is the key, the folder is the value.
Every word does this at the same instant. Four words, four simultaneous rounds of comparison, and a thousand words work exactly the same way.
More than one meeting
Several meetings run in parallel with the same words in the same seats. Each version cares about something different. One tracks which word pairs with which. Another follows what modifies what. A third keeps chasing a name mentioned two sentences back.
A single meeting sees too little. Watch grammar and you miss meaning; watch meaning and you miss grammar. Run eight or twelve versions, let each look somewhere else, then pool the results, and one word holds several relationships at once. If one version wanders off, the others cover for it. Each parallel meeting is called a head.
Without seat numbers, everything scrambles
Facing each other simultaneously also means losing track of order. A round table has no front and no back. "Dog bites man" and "man bites dog" use the same bag of words and mean opposite things. Strip order away and the two look identical.
So before the words take their seats, each is handed a seat number. The number is not a sticker on the outside. It is blended lightly into the word's own sense, which is why the same word registers a little differently depending on where it sits. This step is called positional encoding.
Stacking layers, ending in one word
One meeting settles very little. The words carry their revised senses upstairs and hold the identical meeting again, through dozens of floors. Downstairs the focus is close at hand, links to neighboring words. Upstairs it widens to the argument of a paragraph and the tone of a document. Nobody assigns those jobs. The division emerges during training.
What comes out of the top floor is surprisingly plain: a list of candidate next words, each with a score. After "so I sat on the bank and," the word "fished" scores high and "sprinted" scores low. One candidate is chosen, pinned to the end of the sentence, and the now-longer sentence goes back to the table from scratch. A few hundred rounds of that produce one long answer.
This is also why a name mentioned early in a chat can still be used much later. Every time a new word is chosen, the entire text so far returns to the table. Nothing is memorized along the way; it is all reread each time.
3More precisely
There is no table and there are no folders. Words are first converted into lists of numbers called embeddings, and attention is multiplication and addition over those numbers. Question, tag and folder are bundles of numbers named query, key and value. Because words consult others inside their own text rather than a separate one, this is called self-attention. A layer is not attention alone, either: a small calculation stage follows, where each word chews over what it collected.
The previous design, RNN (Recurrent Neural Network), processed tokens in order, which made the work hard to divide up and left long-range links weak. The transformer solved both, though not for free. Scoring every pair of words means doubling the length quadruples the arithmetic, which is exactly why there is a ceiling on how much text fits at once.
The original design was built for translation, pairing an encoder that reads the input with a decoder that writes the answer. An encoder sees the whole sentence in both directions, while a decoder cannot peek at the part not yet written. Most conversational models today stack decoders only, predicting the next token from the words already in place.
4Try it yourself
- Transformer Explainer (how it works) ailearn.space Type a sentence and see how much each word leans on the others, drawn as line thickness
- Attention Viz (the whole attention map) ailearn.space Compare what every attention head is watching, many meetings side by side in one view
- LLM Visualization (a 3D dissection) ailearn.space Spin a stack of transformer layers in 3D and follow one token all the way through
5Common misconceptions
It's easy to think the model reads a sentence one word at a time from the left, but actually it spreads the whole input out at once and computes the relationships together. Words appear one at a time when it writes, not when it reads.
It's easy to think a transformer is one company's chatbot, but actually it is a blueprint shared across many systems. A translation tool and a chat assistant can stand on the same plan.
It's easy to think this design only handles language, but actually patches of an image and slices of sound become tokens too and pass through the same machinery. The same round table sits inside tools that draw pictures and hear speech.
7One-line summary
In shortA transformer seats words at a round table, has them score how much to look at each other, and repeats that meeting through dozens of layers to pick the next single word.
Spotted an error or have a better analogy? Suggest an edit · Last updated2026-09-02