Attention Is All You Need
Vaswani et al. in Architectures
Drop recurrence entirely. Attention alone translates better and trains faster.
Attention Is All You Need
Sequence models were stuck reading one token at a time
Each hidden state waits on the previous one. Training cannot parallelize across a sentence, and signals between distant words must survive many sequential steps.
Every token attends to every other token in one matrix multiply. Any two positions are a single step apart, and the whole sequence trains in parallel.
Path length between any two words drops from O(n) to O(1).
Encoder and decoder, built only from attention and MLPs

Left stack encodes the source; right stack generates the target. Each layer repeats attention, then a feed-forward block, each wrapped in a residual connection and layer norm.
Scaled dot-product attention in one line
Each query scores every key, softmax turns scores into weights, and the output mixes the values. Dividing by dk keeps softmax from saturating.
- Q
- Queries: what each token is looking for
- K
- Keys: what each token offers to be matched on
- V
- Values: the content that actually gets mixed
- dk
- Scale factor; keys are 64-dimensional per head
Eight heads attend in parallel, each in its own subspace

Left: a single attention head. Right: Q, K and V are projected eight times, attended separately, then concatenated, so each head can learn a different kind of relationship.
Order comes from sine waves, not recurrence
- 1
Embed tokens
Each token becomes a 512-dimensional vector, with weights shared between input embeddings and the output projection.
- 2
Add positional encodings
Sines and cosines of different frequencies are added, so relative offsets become functions the model can learn to attend by.
- 3
Stack six layers
Encoder and decoder each stack six layers; the decoder masks future positions so generation stays autoregressive.
New records at a fraction of the training cost
WMT 2014 newstest. The big model trained for 3.5 days on eight P100 GPUs.
Quadratic attention became the next bottleneck
Cost grows with length squared
Self-attention compares every pair of tokens, so memory and compute scale as n2. Long documents get expensive fast.
Tested on translation and parsing
Evidence covered WMT translation and English constituency parsing. Its reach into language modeling and vision came from later work.
Extrapolation was a hope
Sinusoidal encodings were chosen because they might extrapolate to longer sequences; the paper did not test that.
Why it matters
- Attention alone, with no recurrence or convolution, is enough for state-of-the-art sequence modeling.
- Parallel training across positions is what made scaling to today's model sizes practical.
- BERT, GPT and nearly every modern LLM descend directly from this block.
152 upvotes on Hugging Face 9 slides, 2 min
12 Jun 2017