Back to Learning Area

The Breakthrough — Transformers & Attention

What "Attention Is All You Need" (2017) actually changed — and why the world hasn't gone back.

  • Architectures
  • 12 min
  • Expert

Plain Language

This preview is in Plain Language. The whole portal is also available in Plain Language. You can change the language at the top. Or use the button below. Our Plain Language texts are AI-assisted and editorially reviewed. They follow the core principles of easy-to-read language, but they are not certified Easy Read: a review panel of people with learning difficulties does not test them.

Preview: The transformer architecture

What are transformers?

Transformers are a type of AI model. These models are behind ChatGPT and many other AI systems. They process language very fast. They can be trained with very many data.

Self-attention

In the past, an AI read words individually. That was slow. Transformers look at all words at once. Each word looks directly at every other word. This is called self-attention. Self-attention means: the model pays attention to connections.

Why transformers are important

Due to self-attention, no word loses its meaning. This works well even in very long texts. Transformers are the basis for almost all large AI systems for language today.

RNNs process language one word at a time. For a 500-word paragraph, word 1 must survive 499 steps of compression before influencing the output — often, it does not survive. In 2017, Vaswani et al. proposed a radical alternative: what if every word could directly attend to every other word, all at once?

That idea — Self-Attention alone, with no RNN at all — eliminated the sequential bottleneck and unleashed a wave of scaling that produced GPT, BERT, and virtually every major AI system in use today.

Self-Attention — Every Token Sees Every Other Token

The central innovation of Transformers: parallel processing, direct connections, dynamic weights. Why this solves the RNN problems:

Definition

Self-Attention

Analogy

Imagine a classroom discussion. In the RNN approach, students sit in a long line and can only whisper to their immediate neighbor — a message from student 1 must pass through students 2, 3, 4, ... before reaching student 30. Information gets lost. In the Self-Attention approach, every student can see and hear every other student directly. Each student decides independently how much attention to pay to each speaker based on what is currently being discussed.

Example

In a real classroom, students have limited cognitive bandwidth and cannot truly attend to 30 speakers simultaneously. Self-Attention computes attention to ALL tokens mechanically and in parallel — there is no cognitive limit, only computational cost.
RNN (sequential)

Tokens are processed one by one. Information from token 1 must pass through 499 hidden states to reach token 500. The vanishing gradient problem causes long-range dependencies to disappear.

Transformer (parallel)

Every token has direct access to every other — the distance is always exactly one step. No information lost by passing it along through many steps. Massive GPU parallelization possible.

Note

The word "bank" in two sentences: "The bank is by the river" vs. "The bank is bankrupt." Without attention, "bank" has the same representation in both. With Self-Attention: in sentence 1, "bank" attends strongly to "river" — its representation shifts toward "bench/seat." In sentence 2, "bank" attends strongly to "bankrupt" — representation shifts toward "financial institution." Same word, different meaning — computed automatically. That is how it works in models like BERT, which see the whole sentence. In GPT-style models, attention is causally masked: each token sees only itself and the tokens before it. There, "bank" cannot yet look at the later "river" or "bankrupt"; the meaning is resolved only at later positions, which see both words.

The attention weights are dynamic: they are computed fresh for each input — unlike static CNN filters or fixed dense layer weights.

Caution

Watch Out: Transformers Don't "Understand" Language

Transformers compute statistical patterns, not meaning. The attention weights show correlations, not real comprehension. The impressive results come from pattern recognition on massive datasets — not from cognition.

Try It Out: Self-Attention Step by Step

See how Self-Attention computes attention weights for the token "Fuchs" in the example sentence "Der schlaue Fuchs":

DerschlaueFuchs
Step 1 / 6Tokens ready

Three tokens are in the sequence. Self-Attention will now compute how much attention each token pays to each other — all at once, in parallel.

Controls
Steps

Query, Key, Value — The Mechanics of Attention

How attention is actually computed — step by step:

Definition

Query, Key, Value

Analogy

Think of a library search. You walk in with a specific research question (your Query). Every book has an index card describing its content (its Key). You compare your question against every index card — some match well (high dot product), others don't. For the matching books, you read the relevant passages (their Values). The final answer is a blend of information from all relevant books, weighted by how well each card matched your question.

Example

In a real library, you typically pick one or two best-matching books. Self-Attention computes a weighted combination of ALL values — every token contributes something, though most contributions are near-zero after softmax.
Attention(Q, K, V) = softmax(Q · KT / √dk) · V
Attention Formula

Mini-attention for "Der schlaue Fuchs" (3 tokens, d_k = 4).

  1. 1. Dot ProductsQuery for "Fuchs": Q = [2, 0, 2, 0]. Keys: K_Der = [1, 0, 0, 0], K_schlaue = [2, 0, 2, 0], K_Fuchs = [1, 1, 0, 0]. Dot products: Q_Fuchs · K_Der = 2, Q_Fuchs · K_schlaue = 8, Q_Fuchs · K_Fuchs = 2
  2. 2. ScalingDivided by sqrt(d_k) = sqrt(4) = 2: Result [1, 4, 1]
  3. 3. SoftmaxSoftmax([1, 4, 1]) ≈ [0.05, 0.90, 0.05]
  4. 4. Weighted ValuesAssume the value vectors are: V_Der=[1,0], V_schlaue=[0,1], V_Fuchs=[1,1]. Weighted sum: 0.05·[1,0] + 0.90·[0,1] + 0.05·[1,1] ≈ [0.10, 0.95]
  5. 5. Result"Fuchs" (fox) attends mainly to "schlaue" (clever) — its new representation now carries the information that this fox is clever.

Without dividing by sqrt(d_k), dot products become very large in high dimensions. Large values push softmax to extreme values (near 0 or 1), causing vanishing gradients — so-called "softmax saturation." Dividing by sqrt(d_k) keeps values in a moderate range so softmax produces usable gradients and training remains stable.

Interactive: The Attention Formula

Click on Q, K, or V to understand what each vector does in the attention computation:

Attention Formula

QKᵀV
Q — Query

The Query vector encodes what information this token is looking for. Each token generates its own Query by multiplying its embedding with the learned weight matrix W_Q. The Query is then compared against all Keys to determine relevance.

Concrete Example

Formula: Attention(Q, K, V) = softmax(Q·Kᵀ/√dₖ) · V

Components: Q·Kᵀ (relevance scores) , / √dₖ (numerical stability)

1Q·Kᵀ: Dot products measure relevance → [2, 8, 2]
2Divide by √d_k to prevent softmax saturation → [1, 4, 1]
3Softmax normalizes to probabilities → [0.05, 0.90, 0.05]
4Weighted sum of V vectors → output [0.10, 0.95]

The Transformer Block — Assembling the Machine

The three components of a Transformer Block in detail:

Definition

Transformer Block

Analogy

Think of a Transformer Block as a committee meeting in three phases. Phase 1 (Multi-Head Attention): multiple expert panels discuss the input simultaneously — one analyzes grammar, another meaning, another tracks references. Phase 2 (Add & Norm): each participant writes a brief combining the new discussion insights with their original notes (residual connection = "don't forget what you already knew"). Phase 3 (Feed-Forward): each participant privately processes and consolidates their updated understanding before the next round.

Example

Committee members influence each other during discussion. In Multi-Head Attention, the heads operate completely independently in parallel — they do not exchange anything while computing; only afterwards are their results combined and processed further together.

Transformer Block: Data Flow

Multi-Head Attention

Multiple parallel attention computations — each head learns different patterns (grammar, semantics, references)

Add & Norm

Residual connection + Layer Normalization — stabilizes gradient flow in deep networks

Feed-Forward Network

Two dense layers with ReLU — processes the information gathered by attention, per token

Add & Norm

Second residual connection + normalization — output ready for the next block

Modern models stack dozens to over a hundred such blocks:

Transformer Blocks

96 blocks

GPT-3: 96 blocks, each with 96 attention heads

Parameters

175 billion

GPT-3: 175 billion trainable parameters

The Paper

2017

"Attention Is All You Need" — Vaswani et al.

Caution

Watch Out: More Attention Heads ≠ Automatically Better

More heads mean more parallel perspectives, but not necessarily better results. The heads share the total dimension — with the same model size, individual heads become smaller. The optimal number of heads depends on the task and model size.

Self-Attention compares every token with every other — that's n × n comparisons. Double the sequence length, quadruple the cost. At 1,000 tokens: 1 million comparisons. At 10,000 tokens: 100 million. This is why context length is a hard problem: GPT-3 was limited to 2,048 tokens. Modern models use various optimizations (Flash Attention, Sparse Attention) to enable longer contexts — but with full attention, the fundamental quadratic complexity remains. Some newer models therefore use full attention in only some of their layers and fill the rest with variants whose cost grows only linearly with length: Qwen3.5, for example, in every fourth layer, NVIDIA's Nemotron 3 in a few layers between Mamba layers. This lets such models reach contexts of up to about one million tokens.

Note

Key Takeaways

  • Self-Attention gives every token direct access to every other token — in parallel, without sequential bottleneck and without vanishing gradient over distance. The weights are dynamic (computed fresh for each input), not static like CNN filters.
  • The QKV mechanism structures attention as an information retrieval system: Query asks "what do I need?", Key offers "what do I have?", Value delivers the actual content. The dot product Q·K measures relevance, softmax normalizes to probabilities.
  • A Transformer Block combines Multi-Head Attention, residual connections with Layer Normalization, and a Feed-Forward Network. GPT-3 stacks 96 such blocks with 96 heads each — 175 billion parameters total.

Check

Checkpoint

Can you explain this in your own words? Tick what you've got.

0 of 3 done

Check

Quiz: Transformers & Attention

Not completed

What fundamental problem of RNNs does Self-Attention solve by giving every token direct access to every other token?

Select one answer

Answer Key: 1) B · 2) C · 3) C · 4) B