Attention & Transformers
The word "bank" means something totally different next to "river" than next to "money". Attention is how words shine spotlights on each other to figure out what they mean right now.
The Problem With Frozen Word Meanings
In the previous chapter, we placed every word at a cozy home address on a giant Meaning Map — king near queen, river near water, coin near vault. That map is a brilliant start, but pause and picture a sneaky problem.
Where on that map should you park the word "bank"? If you put it in the nature neighborhood next to river, you will confuse every sentence about savings accounts. If you put it in the finance neighborhood next to money, you will ruin every sentence about sitting by the water.
And it gets even trickier with tiny words like "it". By itself, the word "it" is almost a blank sticky note. It could mean a tired animal, a wide street, a broken bicycle, or a thunderstorm. A single frozen location on the map can never capture what "it" means — because its meaning is borrowed from the company it keeps.
Shining Spotlights Across a Sentence
To solve this, modern AI uses an astonishingly simple visual idea called Attention. Instead of reading a word in isolation, every word in a sentence gets to look around at all the other words and ask: "Who here helps explain what I mean right now?"
Picture each word holding a glowing theater spotlight. When it spots another word that holds a crucial clue, it pours a bright, thick beam onto that word. Words that don't help much only get a faint whisper of light. Then, the word blends those lit-up clues into its own meaning — literally sliding its point on the Meaning Map toward the exact sense it has in this sentence.
Try it yourself right now. Click or hover over any word in the sentence below and watch where its spotlight lands — especially the word "it" and the word "bank".
Click Preset 1 ("...too tired") and keep your eyes glued to the word "it". Notice how 68% of the spotlight shoots backward across six words straight onto "animal". Now click Preset 2 ("...too wide"). We changed only the very last word — yet the spotlight snaps cleanly onto "street" instead! That single clue at the end of the sentence completely rewired what "it" means.
How Does a Word Know Where to Aim?
You might wonder: how does "it" magically know to aim at "animal" in one sentence and "street" in the next, without a human hand-coding grammar rules?
Imagine every word in the sentence walks into a dimly lit room carrying three simple things:
- A Question Lantern: What kind of clue am I hunting for? (For example, "it" holds up a lantern asking: "Who is the noun I'm standing in for?")
- A Name Tag: What kind of clue can I offer to others? ("animal" wears a tag saying: "I'm a living creature that can get tired." "street" wears a tag saying: "I'm a physical path that can be wide.")
- A Gift of Meaning: If someone's spotlight lands on me, here is the piece of my meaning I'll share with them.
When a word's Question Lantern matches another word's Name Tag, the spotlight locks on brighter and stronger. If they barely match, the spotlight dims to almost zero. Every word does this simultaneously — listening to the whole sentence, pulling in a tailored blend of context, and stepping out of the room with a freshly sharpened meaning.
Why One Spotlight Isn't Enough: Multi-Head Attention
Now pause and picture a richer sentence: "The quick fox quietly jumped over the sleepy brown dog."
A single spotlight trying to track everything at once would get hopelessly blurry. Who did the jumping? Which adjectives belong to the fox, and which belong to the dog? How was the jumping performed?
The breakthrough inside a Transformer is wonderfully straightforward: don't use one spotlight — run many spotlights in parallel! Each spotlight is called an Attention Head, and during training, each head naturally specializes in a different kind of relationship:
- One head becomes a Blue Who-Did-What Detector, linking actions to actors and targets.
- Another becomes a Gold Description Matcher, snapping adjectives onto the exact nouns they paint.
- A third becomes a Violet Action & Style Tracker, tying adverbs and prepositions to the verb they shape.
Switch between the three heads below — and then turn on All Heads Together to see how a Transformer sees an entire web of meaning all at once.
From Spotlights to Transformers
Before Transformers arrived, language models had to read like someone looking through a tiny keyhole — plodding strictly one word at a time from left to right. By the time they reached the end of a long paragraph, the memory of the opening sentence had faded to a blur.
A Transformer throws away the keyhole. Every word in the entire passage stands on the stage at the same time, and dozens of attention heads flash across the stage in parallel. A word at the end of a page can lock a bright beam onto a word at the very beginning in a single hop — just as easily as onto its immediate neighbor.
Even better, a Transformer doesn't stop after one round of spotlights. It stacks many layers of attention one after another. In early layers, words figure out simple local clues ("quick" describes "fox"). In middle layers, whole phrases connect ("it" is the exhausted animal). By the deepest layers, the network grasps tone, sarcasm, plot twists, and subtle chains of reasoning.
If Chapter 8 gave every word a starting point on the Meaning Map, Chapter 9 lets the words talk to each other. Attention is simply a weighted conversation: every word listens 5× or 10× louder to the clues that matter most, blends them in, and updates its meaning. Stack enough of these parallel spotlight layers together, and you have the engine powering modern AI.