← back to blog
JUN 25, 2026 · 12 MIN READ · PAPER NOTES

Attention Is All You Need — Notes from a Slow Read

#deep-learning #transformers #nlp #paper-notes
TL;DR — In 2017, a Google Brain team replaced the recurrent backbone of sequence models with pure attention. The result — the Transformer — trained faster, learned longer dependencies, and quietly became the substrate for almost every interesting model that followed: BERT, GPT, ViT, AlphaFold's Evoformer. This post walks through what the paper actually says, why it worked, and what surprised me on a careful read.

The problem in 2017

If you wanted to model a sequence in 2016, you reached for an RNN. LSTMs and GRUs had patched the worst of the vanishing-gradient problem, and Bahdanau-style attention had partly fixed the bottleneck where an entire source sentence got compressed into a single thought vector. But two stubborn issues remained.

The first was sequential computation. RNNs process tokens one at a time, because the hidden state at position t depends on the hidden state at t-1. You cannot use the GPU you paid for. Training was slow, and it got slower the longer your sequences became.

The second was path length for long-range dependencies. For an RNN, the signal from token 1 has to travel through every intervening hidden state to reach token 100. Each hop is a chance for the gradient to die or the information to get overwritten. Attention helped, but attention was still bolted on top of recurrence — the recurrence itself was load-bearing.

ConvS2S (Facebook, 2017) showed you could swap recurrence for convolutions and get parallelism. But convolutional receptive fields grow only with depth, so the path length between distant tokens still scales with the network depth. The recurrence was gone; the fundamental issue was not.

Then came a paper with a title that read like a manifesto: Attention Is All You Need.

The central claim

The paper's argument is almost cheeky in how directly it states things. You do not need recurrence. You do not need convolutions. Self-attention, stacked deep enough, with a few engineering touches, is sufficient — and it is also dramatically more parallel and has constant path length between any two positions.

Read Table 1 of the paper, and the argument becomes mechanical. For a sequence of length n and representation dimension d:

Layer typeComplexity / layerSequential opsMax path length
Self-attentionO(n² · d)O(1)O(1)
Recurrent (RNN)O(n · d²)O(n)O(n)
ConvolutionalO(k · n · d²)O(1)O(log_k n)

Self-attention is more expensive per layer when n > d, but it is fully parallel and any token can attend to any other token in one hop. For typical sentence-length sequences and the d the paper uses, the tradeoff is wildly favourable.

The core idea: scaled dot-product attention

Forget the architecture diagram for a moment. The single idea that makes the Transformer work is this:

For each position, produce a query. For every position (including the same one), produce a key and a value. The output at the query position is a weighted sum of values, where the weight on each value is the similarity between the query and that position's key.

In math, with Q, K, V as matrices stacking queries, keys, and values across all positions:

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

A few things to notice:

  1. The dot product Q Kᵀ is the similarity matrix. Row i, column j is how much position i wants to listen to position j.
  2. The softmax turns similarities into a distribution. Every row sums to one, so the output at each position is a convex combination of the value vectors.
  3. The √dₖ scaling is not cosmetic. In high dimensions, random dot products have large variance. Without the scaling, the softmax saturates — one value gets ~1 and the rest get ~0, and the gradient through softmax vanishes. Divide by √dₖ and you keep the pre-softmax logits in a sane range.

That is the whole mechanism. Everything else in the paper is plumbing around this idea.

Multi-head attention

One attention computation gives you a single "lens" — one way of relating positions to each other. But a sentence has many simultaneous relationships: syntactic ("who is the subject of this verb"), referential ("which noun does this pronoun point to"), positional ("what is the previous word"), semantic ("what is the topic"). One soft alignment cannot capture all of these.

Multi-head attention runs h parallel attention operations on different learned projections of Q, K, V, then concatenates the outputs and projects them back to the model dimension. The paper uses h = 8. Each head can specialise. When you visualise the attention matrices of a trained Transformer, you actually see different heads doing different things — one head attends to the previous token, another to syntactically related words, another to the start-of-sequence token (a useful "null" pointer).

The architecture, briefly

The full Transformer is an encoder-decoder. The encoder is a stack of N=6 identical layers, each containing one multi-head self-attention sublayer followed by a position-wise feed-forward sublayer, with residual connections and layer normalisation around each.

The decoder mirrors the encoder, but with two changes:

Two more details that are easy to gloss over:

Why it won

The empirical results are almost a footnote — but they are striking. On WMT14 English-to-German, the Transformer beats every prior result on BLEU, at a fraction of the training cost. On English-to-French it sets a new state of the art. The "base" model trains in 12 hours on 8 GPUs.

But the long-run story is not BLEU on WMT. The long-run story is that this architecture turned out to be a substrate. The same encoder, slightly modified, became BERT. The same decoder, slightly modified, became GPT. Strip the encoder-decoder distinction and feed in image patches instead of tokens, and you get a Vision Transformer. The Transformer is general in a way that RNNs and CNNs are not, and once people realised that, the rest was scaling.

What surprised me on a careful read

What I want to dig into next

References

← back to all posts