If you've asked a chatbot to draft an email, generated an image from a text prompt, or watched an AI write code that runs, you've used a Transformer. The name never shows up in the product — you just see "AI." But nearly every headline generative AI system today runs on the same idea a team at Google introduced in 2017, in a paper confidently titled "Attention Is All You Need."

Transformers, in Plain English

Older AI systems read a sentence the way a nervous student reads aloud: one word at a time, left to right, trying to hold everything in memory as they go. By the end of a long sentence, a lot of the beginning had usually faded, the same way it's hard to repeat a long phone number back after hearing it once, digit by digit, with no chance to glance back.

A Transformer reads differently. It looks at the whole sentence at once and asks, for every word, "which other words here actually matter for understanding this one?" Take the sentence "The trophy didn't fit in the suitcase because it was too big." A person instantly knows "it" means the trophy, not the suitcase, because they're weighing the whole sentence together rather than reading left to right and guessing. A Transformer does essentially the same thing — every word gets to glance at every other word and decide how much attention to pay to each one, all in one pass. That's where the "attention" in the paper's title comes from.

Two things fall out of that. Because the model isn't stuck reading in order, it can do this looking-around process for every word at the same time instead of one step after another, which made it dramatically faster to train on modern computer chips — so researchers could feed it far more text than before. And the same trick, "compare everything to everything else and decide what's relevant," isn't specific to language at all. Chop a photo into a grid of tiles and a Transformer can figure out how those tiles relate to each other too, which is part of why the same basic idea now sits behind chatbots, AI image generators, and tools that mix text, pictures, and audio in one conversation.

The sections below go deeper into how that actually works, first conceptually and then down at the level of the underlying math.

The Problem

Before Transformers, the standard way to process a sentence was the recurrent neural network (RNN), and its cousin the long short-term memory (LSTM). These read one word at a time, left to right, carrying forward a running "memory" of everything seen so far — the way a person reads.

That intuition came at a cost. It was slow: word 10 couldn't be processed until word 9 had been, locking the model into sequential computation that GPUs, built to crunch huge batches of math at once, are a poor fit for. And it forgot: by word 50 of a paragraph, an RNN's memory of word 2 had usually faded to almost nothing, no matter how many gating tricks were bolted on to slow the decay. Anything needing long-range context — a pronoun late in a paragraph pointing back to a name introduced much earlier — was a genuine weak spot.

Researchers had already started patching this with a mechanism called "attention," letting a model glance back at earlier words instead of trusting a compressed memory trail alone. It helped, but it was still a patch on top of a sequential model.

The Solution

The Transformer's move was to make attention the entire architecture and throw out recurrence altogether. Take the sentence: "The trophy didn't fit in the suitcase because it was too big." What does "it" refer to? You resolve this instantly by weighing the whole sentence at once. Self-attention gives a model the same move — for every word, it scores how relevant every other word is, then blends in information from those words weighted by that score. "It" pulls from "trophy," "suitcase," and "big" simultaneously, rather than inheriting whatever's left of the sentence's meaning by the time the model reaches it.

Crucially, this happens for every word at the same time, not one after another. Swapping sequential memory for parallel comparison is what made Transformers so much faster to train, and it's also why they scale so well — no sequential bottleneck means you can keep feeding the model more data and more compute without training grinding to a halt.

Each layer actually runs this comparison several times side by side (multi-head attention), with different heads picking up on different kinds of relationships, then combines the results. And because comparing words to each other has no inherent sense of order — "dog bites man" and "man bites dog" would look identical to it — Transformers add positional encoding, extra information baked into each word telling the model where it sits in the sequence.

The left side shows what one layer of a Transformer does to a sequence, step by step. The right side zooms into the example above, showing how "it" gets resolved by weighing every other word at once instead of reading through the sentence in order.

Scalability with Transformers

RNNs had a hard ceiling: because each word depended on finishing the one before it, the work couldn't be spread across a GPU's cores, so throwing more hardware at the problem didn't help. Self-attention removes that ceiling — every word is compared at once, so training parallelizes cleanly, and performance kept improving as models and data got bigger, well past where researchers expected it to flatten out.

Inside the Architecture

Zoomed all the way in, here's what actually happens to the numbers. Every input token is first converted into a vector through an embedding lookup — commonly 512 to a few thousand dimensions, depending on model size — with the positional encoding added directly onto that vector before anything else happens.

Self-attention then projects each token's vector through three separate learned weight matrices, producing a Query, a Key, and a Value vector for that token. A token's Query is compared against every token's Key with a dot product, scaled down by the square root of the vector's dimension to keep the numbers stable, then run through softmax so the scores turn into weights that sum to one. Those weights blend the Value vectors together: Attention(Q, K, V) = softmax(QKᵀ / √d) · V. That single formula is the entire self-attention mechanism — everything else is bookkeeping around it.

Multi-head attention runs several of these Q/K/V projections in parallel with different learned weights, concatenates the results, and passes them through one more output matrix. What follows each attention step is a residual add (the block's input added back in), a layer-normalization pass to keep values in a stable range, then a small feed-forward network — two linear layers with a nonlinearity in between, applied identically to every position on its own. A second add-and-normalize step closes out the block, and that whole unit is what gets stacked N times, commonly a few dozen layers deep in large models.

One detail matters specifically for GenAI: models like GPT and Claude are decoder-only, meaning self-attention is masked so a token can only look at positions before it, never after. That constraint is what makes next-token prediction — and therefore generation — coherent rather than circular. The final layer's output vectors are projected through one more linear layer sized to the vocabulary and run through softmax, producing a probability distribution over every possible next token, one of which gets sampled to continue the text.

This one swap — comparison instead of memory, parallel instead of sequential — is why the architecture scaled the way it did. Train it on next-word prediction across enough raw text and it starts absorbing facts, reasoning patterns, and writing style as a byproduct, which is the recipe behind GPT, Claude, Gemini, and the rest of today's large language models. The same trick works on images chopped into patches (Vision Transformers) and inside most modern image generators, which is how one architectural idea ended up underneath most of GenAI. It isn't free of tradeoffs — attention's cost grows quadratically with sequence length, and the model still has no built-in notion of truth — but nothing has displaced it yet.

Keep Reading