Transformers
The transformer is the neural network architecture behind essentially all modern AI: its breakthrough, attention, lets every word look directly at every other word, and its parallel-friendly design let models scale to the trillions of words that made LLMs possible.
Learning Objectives
- Explain what the transformer architecture is and why it won.
- Describe the core innovation — attention — at intuition level.
- Understand why transformers unlocked massive parallel training.
- Trace a sentence through a transformer's main stages.
- Recognize the transformer inside every modern AI system you meet.
Why This Matters
One 2017 paper, "Attention Is All You Need," introduced the architecture that now powers GPT (the T is for Transformer), Claude, Gemini, image generators, speech systems, and protein folders. Understanding transformers at intuition level (no math needed) explains where context windows come from, why GPUs matter, why models handle long-range meaning so well. It's the architecture literacy that everything in Levels 2–6 assumes.
Everyday Analogy
A meeting where notes pass down a line of people, each summarizing for the next: by person ten, the first person's nuance is gone. That was the old architecture (RNNs): words processed one by one, meaning fading over distance.
The transformer is a roundtable: everyone hears everyone directly. When it is your turn to interpret your word, you look around the whole table and decide whose words matter to yours — near or far, equally reachable. That direct, distance-free access is attention.
The Problem Transformers Solved
Consider: "The trophy didn't fit in the suitcase because it was too big."
What does "it" refer to? You resolved that instantly using the meaning of the whole sentence. Pre-2017 architectures read left to right, compressing everything seen so far into one running summary — long sentences overflowed the summary, and relationships between distant words blurred. Worse, sequential reading meant sequential training: word 500 had to wait for words 1–499, making web-scale training impractically slow.
The transformer fixed both at once.
Attention, Intuitively
For each word, attention asks: "Which other words in this text should influence my interpretation, and how much?" Every word computes a relevance score against every other word, then blends their information in proportion.
For "it" in the trophy sentence, attention learns to score "trophy" high (large things don't fit) and "suitcase" lower, so the blended representation of "it" now means trophy. Multiply this: dozens of attention "heads" per layer, each free to track a different relationship (grammar, coreference, tone), stacked across dozens of layers (AI-003's hierarchy). Early layers link neighbors; deep layers connect themes across whole documents.
The context window (AI-061) is simply the size of this roundtable — how many tokens can attend to each other at once. And attention's cost grows fast with table size, which is why long context is expensive.
The Other Half: Parallelism
Attention gets the fame; parallelism built the empire. Because every word attends to every word simultaneously, with no waiting for a left-to-right chain, an entire document trains in one parallel step. That maps perfectly onto GPUs (thousands of small cores doing simultaneous math, AI-003), which meant training could scale from millions of words to trillions (AI-067). No parallelism, no LLMs. The scaling laws of AI-009 were unlocked by this property.
A Sentence's Journey Through a Transformer
- Tokenize — text becomes tokens (AI-059), each mapped to a number-vector (an embedding, AI-014).
- Position tags — since all words are processed at once, each carries a marker of where it sits.
- Attention layers × N — each layer: every token gathers context from all others (attention), then processes what it gathered (a small neural network per token). Repeat ~30–100 times, meaning enriching at each floor.
- Output — probabilities for the next token (AI-009), or a classification, or an embedding — the same trunk serves many heads.
Real-World Showcase
- Every frontier LLM, from GPT to Claude, Gemini, Llama, and DeepSeek, is a transformer; differences are scale, data, and refinements, not architecture.
- Beyond language: Vision Transformers read images as patch-sequences; Whisper transcribes speech; AlphaFold 2's core is attention over protein sequences — one architecture, generalizing across science.
- The paper's authors left Google to found companies now worth billions collectively (Cohere, Character.AI, Adept...), a measure of the idea's gravity.
Try It Yourself
- Do attention by hand: in "The chef, who had trained in Paris for years, burned the toast," — for the word "burned," which words matter most? You'll pick "chef" and "toast," skipping the Paris clause. You just computed an attention pattern; the model learns to do exactly this from data.
- Probe long-range skill: give a chatbot a 3-paragraph story where a detail in paragraph 1 contradicts paragraph 3, and ask what's inconsistent. Its success is attention connecting distant tokens: the trophy problem at scale.
- Feel the context limit: the roundtable analogy predicts that what's not at the table can't be attended to. Confirm with AI-061's experiment — details pushed out of context are simply gone.
Common Mistakes
- Thinking attention is consciousness or focus in the human sense. It's learned relevance-weighted averaging, nothing more mystical.
- Crediting only attention. Parallel training on GPUs is the equal co-star; the architecture won on both.
- Assuming transformers are only for text — they process any sequence: pixels-as-patches, audio, proteins, moves.
- Believing the context window is memory — it is the size of one roundtable sitting; nothing persists after (AI-061).
- Skipping this lesson's intuition: attention explains context limits, "lost in the middle," and token costs downstream. It repays the time.
Key Takeaways
- The transformer (2017) is the architecture behind essentially all modern AI.
- Attention = every token directly weighing every other token's relevance, with long-range meaning and no decay.
- Parallelism made web-scale training possible; GPUs + transformers unlocked the scaling laws.
- Layers of attention build meaning hierarchically, like vision layers built shapes (AI-003).
- Context windows, long-context costs, and multimodal reach all follow from this design.
Glossary
- Transformer
- The 2017 architecture behind essentially all modern AI. GPT's T stands for it. Its two winning properties are attention (distance-free access between words) and parallel-friendly training that scales to trillions of words.
- Attention
- The mechanism where each token asks "which other words should influence my interpretation, and how much?", computing a relevance score against every other token and blending their information in proportion. For "it" in the trophy sentence, attention scores "trophy" high, so the blended representation of "it" now means trophy. (see AI-013)
- Attention Head
- One of dozens of parallel attention patterns per layer, each free to track a different relationship: grammar, coreference, tone. Heads stack across dozens of layers, with early layers linking neighbors and deep layers connecting whole-document themes.
- RNN (Recurrent Neural Network)
- The pre-2017 approach that read text left to right, compressing everything into one running summary, like meeting notes passed down a line of people, with nuance fading over distance. Its sequential reading also made web-scale training impractically slow.
- Parallelism
- The transformer's other half: every word attends to every word simultaneously, so an entire document trains in one parallel step, mapping perfectly onto GPUs. No parallelism, no LLMs: it unlocked the scaling laws. (see AI-009)
- Positional Encoding
- The position marker each token carries, needed because all words are processed at once rather than in order. Without it the model could not tell "dog bites man" from "man bites dog."
- Context Window
- The size of the roundtable: how many tokens can attend to each other at once. Attention's cost grows fast with table size, which is why long context is expensive. (see AI-061)
- Embedding
- The number-vector each token is mapped to before entering the attention layers, capturing meaning in a form the network can process. (see AI-014)
References
Diagram
Knowledge Check
6 questions