Paper Deep Dive — Attention Is All You Need: What Dropping Recurrence Actually Proved
A close reading of the Transformer paper grounded strictly in its own text: the scaled dot-product equation, why the square root of d_k is there, what the ablations exposed, and the limits the authors themselves flagged.
Attention Is All You Need
Primary source — what this article is built on
undefined2017-06-12→undefined2026-08-039y 2mo later
Attention Is All You NeedAshish Vaswani, Noam Shazeer, Niki Parmar et al. · 2017-06-12 · v7arXiv:1706.03762Paper page·PDFundefined
The dominant sequence transduction models are based on complex recurrent or convolutional neural networks in an encoder-decoder configuration. The best performing models also connect the encoder and decoder through an attention mechanism. We propose a new simple network architecture, the Transformer, based solely on attention mechanisms, dispensing with recurrence and convolutions entirely. Experiments on two machine translation tasks show these models to be superior in quality while being more parallelizable and requiring significantly less time to train. Our model achieves 28.4 BLEU on the WMT 2014 English-to-German translation task, improving over the existing best results, including ensembles by over 2 BLEU. On the WMT 2014 English-to-French translation task, our model establishes a new single-model state-of-the-art BLEU score of 41.8 after training for 3.5 days on eight GPUs, a small fraction of the training costs of the best models from the literature. We show that the Transformer generalizes well to other tasks by applying it successfully to English constituency parsing both with large and limited training data.
From a game of telephone to a round table
"Attention Is All You Need" (Vaswani et al., eight authors from Google Brain, Google Research and elsewhere), posted to arXiv in June 2017, made a blunt proposal: strip recurrence and convolution out of sequence transduction entirely.
At the time the field ran on RNN and CNN encoder-decoders, with the best models connecting encoder and decoder through an attention mechanism (Abstract). An RNN factors computation along symbol positions, producing hidden state at position from the previous state and the input at . The paper's objection is precise: this is "inherently sequential" and therefore precludes parallelization within training examples, and since memory constraints limit batching across examples, the problem bites harder as sequences get longer (§1).
Picture an RNN as a game of telephone played in a single line. To move information from one end to the other, it has to pass through everyone in between. The Transformer plays it as a round table instead: everyone sees everyone else's contribution at once and weighs who matters to them.
With that round-table mechanism alone the paper reports 28.4 BLEU on WMT 2014 English-to-German — more than 2 BLEU above the previous best results including ensembles — and 41.8 BLEU on English-to-French, trained for 3.5 days on eight GPUs (Abstract, Table 2). The base model takes twelve hours on eight P100s (§1, §5.2).
The intuition: make the distance between any two positions constant
Why can recurrence go? The background section (§2) puts a finger on it. In ByteNet and ConvS2S, which also set out to reduce sequential computation, the number of operations needed to relate signals from two arbitrary positions grows with the distance between them — linearly for ConvS2S, logarithmically for ByteNet. Distant dependencies are correspondingly hard to learn. In the Transformer that number drops to a constant.
The paper is honest about the price in the same paragraph: averaging attention-weighted positions gives you reduced effective resolution, and Multi-Head Attention is introduced as the counteracting measure (§2). This is not "attention is universally better" — it is an explicit trade: you buy a constant path length, you lose resolution, and you buy the resolution back with multiple heads. That framing gets lost in most retellings.
Section 4 lays out three criteria for preferring self-attention: total computation per layer, the amount of computation that can be parallelized (measured as the minimum number of sequential operations), and the maximum path length between long-range dependencies.
| Layer type | Complexity per layer | Sequential ops | Max path length |
|---|---|---|---|
| Self-attention | |||
| Recurrent | |||
| Convolutional | |||
| Self-attention (restricted to ) |
What Table 1 actually shows is that self-attention does not win on complexity unconditionally. As the paper states, self-attention layers are faster than recurrent layers when the sequence length is smaller than the representation dimensionality , which it argues "is most often the case" for the word-piece and byte-pair sentence representations used by contemporary translation systems (§4). The victory comes with a precondition attached.
The mechanism: scaled dot-product attention
The paper's definition of attention is almost austere: a function mapping a query and a set of key-value pairs to an output, where the output is a weighted sum of the values and each weight comes from a compatibility function of the query with the corresponding key (§3.2).
Then Equation (1) (§3.2.1):
with , , the queries, keys and values packed as matrices and the key dimension.
Read in words: score every query against every key, shrink the scores by , squash them into weights that add up to one, and use those weights to blend the values. What is striking is what the formula does not contain — position. Shuffle the input tokens and the output rows simply shuffle with them, which is why word order has to be injected separately (§3.5, below). If you want the shapes and the projections drawn out step by step, Attention from Scratch covers exactly this equation.
Why divide by ? The paper compares against additive attention (which computes compatibility with a one-hidden-layer feed-forward network) and notes that although the two have similar theoretical complexity, dot-product attention "is much faster and more space-efficient in practice, since it can be implemented using highly optimized matrix multiplication code." But for large , unscaled dot-product attention loses to additive attention. The paper's explanation lives in footnote 1: if the components of and are independent random variables with mean 0 and variance 1, then has mean 0 and variance . Bigger dimension, bigger dot products, and the softmax gets pushed into regions with extremely small gradients. Dividing by the standard deviation undoes that (§3.2.1). Note the paper's own wording — "We suspect that …" This is offered as a hypothesis, not a proof, and it is worth quoting it that way.
Comments
Sign in to comment