Attention Is All You Need

The paper introduced the Transformer: an encoder-decoder architecture that replaces recurrent and convolutional sequence modeling with attention-based token mixing.

Metadata

FieldValue
PaperAttention Is All You Need
AuthorsAshish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Lukasz Kaiser, Illia Polosukhin
Year2017
VenueNeurIPS 2017
arXiv1706.03762
NeurIPSProceedings page
Statusverified

Question

Before this paper, strong sequence transduction systems were usually built around recurrent or convolutional encoder-decoder models, often with attention added on top. The question was whether recurrence and convolution were necessary for high-quality sequence modeling, or whether attention alone could do the sequence mixing.

The deeper architecture question is about sequence dependence. RNNs process tokens sequentially, CNNs process local windows with depth-dependent receptive fields, and attention lets every token directly address every other token in one layer. The paper tests whether that direct token-token interaction can become the main computational primitive.

Main Claim

The paper’s central claim is that a sequence transduction model can be built entirely from attention and feed-forward blocks, without recurrence or convolution, while improving translation quality and training parallelism on the reported machine translation benchmarks.

Narrowed claim:

This is not the same as proving that recurrence or convolution are never useful. It shows that attention-only sequence modeling is a strong architecture class under the tested settings.

Architecture Contract

ItemContract
Inputsource token sequence and target prefix sequence
Outputnext-token distribution over target vocabulary
Backbonestacked encoder blocks and decoder blocks
Token mixingself-attention in encoder and decoder; cross-attention from decoder to encoder
Position informationsinusoidal or learned positional encodings
Parallelismencoder tokens and teacher-forced decoder tokens can be processed in parallel during training
Causal constraintdecoder self-attention masks future target tokens

The translation training objective is autoregressive over the target sequence:

where is the source sequence and is the target prefix.

At inference time:

The encoder builds source representations; the decoder repeatedly queries those representations while generating target tokens.

Method

The Transformer uses stacked encoder and decoder blocks. Each block combines:

The core attention formula is:

where contains queries, contains keys, contains values, and is the key dimension. The scale factor reduces extreme dot-product magnitudes before softmax.

Multi-head attention projects the same input into several attention subspaces:

Because the architecture has no recurrence, positional information is injected with positional encodings:

Encoder Block Walkthrough

An encoder layer starts from token states:

Self-attention mixes source tokens:

The paper uses residual connections and layer normalization around each sublayer:

Then a position-wise feed-forward network is applied independently at each token:

The important separation is:

SublayerMixes tokens?Mixes channels?
self-attentionyesyes, through projections
feed-forward networknoyes
residual/normalizationnostabilizes representation scale

This is why Transformer blocks are often described as alternating token mixing and channel mixing.

Decoder Block Walkthrough

The decoder has three sublayers.

SublayerQueryKey/ValueConstraint
masked self-attentiontarget prefix statestarget prefix statescannot attend to future target positions
cross-attentiontarget statesencoder source statescan attend to all source positions
feed-forward networkeach target positionsame target positionposition-wise

The causal mask changes decoder self-attention:

where:

Cross-attention then lets each target position query the encoded source sequence:

This encoder-decoder structure is different from later encoder-only and decoder-only Transformer backbones.

Complexity and Inductive Bias

The paper compares self-attention, recurrent layers, and convolutional layers by path length and computational structure.

For sequence length and hidden dimension , dense self-attention has:

time/multiply cost for attention interactions, while recurrent layers have sequential path length:

and self-attention has maximum token-token path length:

The tradeoff is direct global interaction versus quadratic sequence-length cost.

ArchitectureMain BiasParallel Over PositionsLong-Range Path
RNNtemporal recurrencenolong
CNNlocality and translation sharingyesgrows with depth/dilation
Transformercontent-based global addressingyesshort

This is the core reason the paper became more than a translation result: it changed the default assumption about how sequence positions should communicate.

Training Recipe

The architecture is not the only thing that matters. The reported results also depend on the training recipe.

IngredientRole
residual dropoutregularizes sublayers and embeddings
label smoothingavoids overconfident target distributions
Adam with warmup schedulestabilizes early optimization
byte-pair encodingcontrols vocabulary and open-word handling
beam searchaffects reported translation quality

The learning-rate schedule is part of the paper’s practical recipe:

For this wiki, architecture conclusions should not ignore these recipe choices. A weaker training setup may make the same block look worse; a stronger setup may improve baselines too.

Evidence

ClaimEvidence in paperCaveat
Attention-only encoder-decoder can outperform strong translation baselinesWMT 2014 English-German and English-French BLEU resultsclaim is under machine translation protocol
Transformer trains more parallelly than recurrent sequence modelsarchitecture removes sequential recurrence across token positionswall-clock depends on hardware and implementation
Multi-head attention and feed-forward blocks are useful componentsablations over heads, key/value dimensions, model size, and positional encodingablations are mostly within translation setup
Model transfers beyond translationEnglish constituency parsing experimentsnot a broad proof of universal transfer

Ablation Reading

The most useful ablations are about which architectural pieces are necessary.

Ablation AxisWhat it testsReading
number of headswhether multiple attention subspaces helptoo few heads can bottleneck relation types; too many reduce per-head dimension
key/value dimensioncapacity and attention sharpnesssmaller dimensions can reduce compute but lose quality
model sizedepth/width scalingimprovement is not solely from attention form
positional encodingfixed sinusoidal vs learnedposition injection matters, but the paper does not settle all later position methods
feed-forward dimensionchannel-mixing capacityattention alone is not the whole architecture

The paper supports the Transformer block as a package: attention, FFN, residuals, normalization, position encoding, optimization, and enough scale.

Benchmark Card

FieldWMT translation setting
Tasksequence-to-sequence machine translation
Input/output unitsource sentence to target sentence
Main metricBLEU
Main comparisonrecurrent/convolutional sequence transduction baselines and prior state of the art
Generalization claimtranslation quality under the benchmark’s train/test setup
Not directly testedmodern LLM pretraining, retrieval, tool use, multimodal reasoning, protein modeling

What Later Models Kept and Changed

KeptChanged Later
scaled dot-product attentionsparse, local, linear, grouped-query, and flash attention variants
multi-head projection pattern[[papers/architectures/gqa
residual block structurepre-norm and other normalization placement choices
feed-forward sublayerGELU, SwiGLU, gated FFNs, mixture-of-experts FFNs
positional signalrelative position, rotary embeddings, ALiBi, learned position schemes
encoder-decoder ideaencoder-only BERT and decoder-only GPT-style models

This matters because “Transformer” now names a family. The 2017 paper is the root, but many modern systems are not exact copies of the original encoder-decoder stack.

Implementation Notes

  • Attention masks are part of the architecture contract; encoder padding masks, decoder causal masks, and cross-attention masks must be handled separately.
  • Tensor shapes should be explicit: batches, heads, sequence length, and head dimension are easy sources of silent bugs.
  • Positional encoding must be added or otherwise represented; self-attention alone is permutation-equivariant over token order.
  • LayerNorm placement changes training stability, especially in deeper stacks.
  • Teacher forcing during training differs from autoregressive decoding at inference.
  • BLEU improvements can be affected by tokenization, beam size, checkpoint averaging, and evaluation scripts.

Limitations

  • The paper’s evidence is centered on translation and parsing, not today’s broad LLM setting.
  • BLEU is useful for translation comparison but does not measure all downstream language-model behavior.
  • The architecture changes compute structure as well as modeling inductive bias, so architecture, hardware efficiency, and implementation are intertwined.
  • Long-context behavior beyond trained/evaluated lengths requires separate evidence.
  • Later Transformer variants changed normalization placement, positional encoding, activation, scaling, objective, data, and training infrastructure.
  • Dense attention has quadratic memory and compute in sequence length.
  • The original architecture does not directly address retrieval, tool use, factual grounding, or alignment.
  • Many later “Transformer” claims depend more on data and scale than on the original block alone.

Why It Matters

This paper is the anchor for modern Transformer-based systems. For this wiki, it should be treated as:

The reusable architecture pattern is:

That pattern later branches into BERT, GPT-2, Vision Transformer, Swin Transformer, and many biological sequence or structure models.

Connections