Almost every AI system you’ve heard of — ChatGPT, Claude, Gemini, Llama — is built on the same architecture: the transformer. It was introduced in a single 2017 paper, “Attention Is All You Need”, and it reshaped the entire field. Here’s how it actually works, in plain English.
The problem it solved
Before transformers, the best language models were recurrent networks (RNNs and LSTMs) that read text one word at a time, carrying a memory forward. Two problems: they were slow to train (each step waits for the previous one), and they struggled with long-range connections — by the end of a long paragraph they’d effectively forgotten the start.
The transformer’s insight was to drop recurrence entirely and process every token at once, letting each token look directly at every other token. That’s the “attention” in the title.
Self-attention: the core idea
Self-attention lets each token decide how much to “pay attention” to every other token when building its own representation. Mechanically, each token produces three vectors: a query, a key, and a value. To figure out what a token should become, its query is compared against every other token’s key to produce attention weights, which then blend the values together.
A classic example: in “the animal didn’t cross the street because it was tired,” attention helps the word “it” link back to “animal” rather than “street.” The model learns these associations from data, not from rules.
Multi-head attention
One attention mechanism has to squeeze every kind of relationship — grammar, meaning, reference — into a single set of weights. That’s a bottleneck. Multi-head attention runs several attention operations in parallel, each with its own learned projections, so one head can track syntax, another can track long-distance references, another local patterns.
Cleverly, this costs about the same as a single head, because each head works in a smaller subspace (the model dimension split into pieces). You get representational richness almost for free.
Positional encoding: teaching order
Here’s a subtlety: self-attention is permutation-invariant — it treats the input as a set, so without extra information “dog bites man” and “man bites dog” look identical. Transformers fix this by adding positional encodings to the token embeddings.
The original paper used fixed sinusoidal patterns. Later models learned position vectors directly. Most modern LLMs (Llama and others) use Rotary Position Embedding (RoPE), introduced in RoFormer, which rotates the query and key vectors by an angle proportional to position — so relative distance falls out of the math naturally and long contexts extend more gracefully.
Putting it together
A transformer stacks many layers, each containing multi-head attention followed by a small feed-forward network, with residual connections and normalization to keep training stable. Decoder-only models (GPT, Llama, Claude) use causal attention — each token can only see earlier tokens — which makes them natural next-token generators. That single design, scaled up with more data and parameters, is what modern LLMs are.
Why it actually mattered
The deepest reason transformers won isn’t that attention is uniquely brilliant — it’s that the architecture is parallelizable and scalable. You can train it on enormous datasets across thousands of GPUs efficiently, and it keeps improving as you add data and parameters. The breakthrough was trainability at scale. Everything from context windows to per-token pricing to the “lost in the middle” problem traces back to how attention works.
Want the interview-ready version of these concepts? See our LLMs & transformers interview questions, and if you’re choosing between models built on this architecture, our AI tools comparison ranks them on merit.