Skip to content
The Daily Triptych104 / 365
Transformer transduction path

Source tokens move through stacked encoder self-attention; the decoder attends to that memory while generating under a causal mask.

II · THE IDEA · ARTIFICIAL INTELLIGENCE

Transformer Neural Machine Translation

Attention Is All You Need · 1706.03762 · June 2017 · neural machine translation

▶ Listen · narrated

Before the Transformer, machine translation leaned on recurrent networks that processed tokens one by one. A single architecture change removed that bottleneck and redefined how models handle sequences.

At a glance

Architecture
Encoder–decoder built only from attention and feed-forward layers
Core claim
Neither recurrence nor convolution is required for transduction
WMT 2014
28.4 BLEU English–German; 41.8 BLEU English–French
Base training
About 12 hours on eight NVIDIA P100 GPUs
Stack depth
Six identical layers in the encoder and in the decoder

Think of translating a sentence as organising a table of people who must all pass notes. In an older recurrent model the notes travel along a line: person one writes to person two, who writes to person three, and so on. Distant people wait on everyone in between.

The Transformer gives everyone a broadcast channel at once. In each layer, every position publishes a query (what am I looking for?), keys (what do I contain?) and values (what do I pass along?). Matching queries to keys decides how much of each value to mix in. Doing this several times in parallel—multi-head attention—lets the model track different kinds of link at once, such as syntax in one head and nearby wording in another.

Because that broadcast does not know left from right by itself, the model adds a positional pattern to each token’s embedding so order is still visible. Stack six such layers for reading the source sentence and six for writing the translation, let the writer’s layers also consult the reader’s final notes, and you have the architecture from the 2017 paper. On standard translation benchmarks it beat heavier recurrent systems while training in a long working day on eight GPUs.

Look closer

  1. Scaled dot-product attention

    Queries, keys and values are packed into matrices. Compatibility is the scaled product QK transpose, divided by the square root of the key dimension so that large inner products do not push the softmax into vanishing-gradient regions. The result weights the values. The paper presents this as simpler and faster in practice than additive attention when dimensions are large.

  2. Multi-head rather than single

    Instead of one attention pass in d_model dimensions, the model projects into several lower-dimensional subspaces—eight heads in the base configuration—runs attention in parallel, concatenates the outputs and projects again. The authors argue that separate heads can attend to different kinds of relation at different positions, which a single averaged head would blur.

  3. Order without recurrence

    Because self-attention has no inherent sense of sequence order, the model adds positional encodings to the input embeddings. The published design uses fixed sine and cosine functions of different frequencies. The paper also reports a learned-embedding variant that performed nearly identically on the translation tasks they measured.

The story

Attention Is All You Need, posted to arXiv in June 2017 by Vaswani and colleagues at Google Brain and Google Research, proposed a sequence transduction architecture that dropped recurrence and convolution entirely. The authors called it the Transformer. Its job, in the experiments that made the claim concrete, was neural machine translation: map a sentence in one language to a sentence in another.

Earlier strong systems mixed recurrent networks—often bidirectional encoders and gated decoders—with attention over encoder states. Recurrence gave the model a way to carry information along a sequence, but it also forced step-by-step computation along that length. The Transformer replaced that path with stacked self-attention. Every position could, in a single layer, draw on every other position in the same sequence, subject only to masking in the decoder so that generation remained auto-regressive.

The architecture is an encoder–decoder. The encoder is a stack of six identical layers. Each layer has two sub-layers: multi-head self-attention, then a position-wise feed-forward network applied independently at each position. Residual connections wrap both sub-layers, and layer normalisation follows. The decoder is also six layers, with a third sub-layer that performs multi-head attention over the encoder’s output. Decoder self-attention is masked so that position i cannot attend to positions greater than i.

Representations are d_model-dimensional vectors—512 in the base model, 1024 in the larger configuration. Attention is multi-headed: the paper’s base setup uses eight heads with reduced key, query and value dimensions so that total compute stays comparable to a single full-dimensional head. The attention itself is scaled dot-product: the product of queries and keys is divided by the square root of the key dimension before the softmax, a detail the authors introduce to keep gradients well behaved when dimensions grow.

Because pure attention is permutation-invariant without help, the model injects positional encodings into the input embeddings. The default scheme is sinusoidal—fixed sine and cosine functions of different frequencies—so that relative positions remain linearly recoverable. A learned positional embedding variant performed nearly as well on their translation benchmarks.

Training used the standard WMT 2014 English–German and English–French data. Byte-pair encoding built the vocabularies. The base model trained for roughly twelve hours on eight NVIDIA P100 GPUs; the larger model took longer and scored higher. On English–German the big model reached 28.4 BLEU, improving over previous best published results including ensembles. On English–French it reached 41.8 BLEU at a fraction of the training cost of earlier competitive systems.

The paper also reports English constituency parsing experiments, showing that the same architecture transferred beyond translation when trained on modest supervised data. The broader claim, stated in the title and defended in the ablations, was that attention is a sufficient primitive for sequence transduction once depth, multi-head structure and positional signals are in place.

Why it mattered then

In 2017 the dominant path to strong neural machine translation still ran through recurrence. Attention had already become a standard add-on to encoder–decoder RNNs, but the sequential dependency along time steps limited parallelisation and made long sequences expensive to train. Convolutional alternatives existed and could parallelise better within a layer, yet they still needed stacked depth or wide kernels to connect distant positions. The Transformer offered a different bargain: constant path length between any pair of positions in a layer, full parallelisation across the sequence during training, and a simpler layer design built from matrix multiplies and feed-forwards. The WMT results gave that bargain empirical weight. A model that looked almost austere on paper—no recurrence, no convolution—matched or beat specialised systems while training in hours on a modest multi-GPU setup. That combination of clarity and scoreboard performance is why the paper travelled so quickly through the research community.

Why it matters now

The encoder–decoder Transformer described in the paper is the direct ancestor of the architectures behind modern large language models, vision transformers and multimodal systems. Many later models keep only the decoder stack, or only the encoder, but the block design—multi-head attention, residual paths, layer norm, position-wise feed-forwards—remains recognisable. The paper’s emphasis on parallel training and short path lengths also set expectations for scale. Once sequence computation no longer walked token by token, hardware utilisation and dataset size became the binding constraints, and those constraints have shaped the decade since. Reading the original still clarifies which pieces were present from the start (scaled dot-product attention, multi-head structure, sinusoidal positions, masked decoder self-attention) and which arrived later.

The surprising detail

The title is not a metaphor. The authors literally remove recurrence and convolution and show competitive translation with attention and feed-forwards alone. Equally striking is how small the base training run was by later standards: about twelve hours on eight P100 GPUs for a model that set a new single-model state of the art on WMT 2014 English–German. The sinusoidal positional encoding is another understated choice—fixed, not learned—yet a learned alternative performed almost the same in their tests, leaving open a design question that later work continued to revisit.

What is disputed

The second listed source addresses learning in Krein spaces and is not part of the Transformer paper’s evidence. Claims here follow only Attention Is All You Need. Later variants change normalisation placement, positional schemes and attention recipes; those are outside this paper’s results.

Remember this

The Transformer showed that stacked multi-head attention, with positional encodings and feed-forward layers, can replace recurrence for sequence transduction.

Test yourself

Why does the decoder mask future positions in its self-attention, and what would break at training time if that mask were removed while still training with teacher forcing?

Go deeper

Image: Original diagram, The Daily Triptych. Licence: Original work. Source.

← Back to day 104