The Transformer moved information between tokens directly, replacing the recurrent steps that had dominated neural machine translation. Vaswani and colleagues reported 28.4 BLEU on WMT 2014 English-to-German and 41.8 BLEU on English-to-French, with the latter model trained for 3.5 days on eight GPUs. The faster training and stronger translations came together because the architecture separated position-to-position communication from serial processing.
- 28.4 BLEU on WMT 2014 English-to-German, more than two BLEU above the best results the authors compared against.
- 41.8 BLEU on WMT 2014 English-to-French after 3.5 days on eight GPUs.
- One attention layer can connect any pair of allowed positions in the sequence.
The training bottleneck was a dependency
A recurrent encoder reads the source sentence in order and carries a state forward. Before the state for token five can be calculated, the network has to finish the state for token four. GPUs can parallelize the arithmetic within a step and process several sequences together. They still have to respect that dependency within a sequence. Learning long-range relationships also requires information to travel through intervening updates.
In a Transformer layer, every token contributes a vector. The layer can calculate those vectors’ queries, keys and values as batched matrix multiplications. Direct comparisons between positions route information from one token to any other token it is allowed to see. The layer waits for the previous layer, while much of its work across positions can happen at once.
Follow one token through attention
Take the sentence “The trophy did not fit in the suitcase because it was too big.” For one example attention head, the representation at it produces a query. The representations at trophy, suitcase and the other positions produce keys and values. Query-key similarity gives each position a score. A softmax turns the scores into weights. The weighted sum of the values is the message written back at it. The source of that message can be several words away, and different heads can learn different patterns of routing.
Build a query
- Token position it
- Learned projection Query
- Candidate sources Keys from trophy, suitcase, and other tokens
The token position for it supplies the query. Every allowed source position publishes a key and a value.
Compare source positions
- Read One query and all allowed keys
- Dot products Compatibility scores
- Softmax Weights that sum to one
The model divides each score by the square root of the key width before softmax.
Write the result
- Read Source values and attention weights
- Weighted sum One output vector
- Destination The token position for it
A position with a higher weight contributes more of its value vector to the output.
Based on Attention Is All You Need, section 3.2.
- The position for it supplies the query. Every allowed source position supplies a key and a value.
- Scaled query-key dot products become softmax weights that sum to one.
- The head combines the source values using those weights and writes one vector back to it.
Suppose the normalized weights on trophy, suitcase and the rest of the sentence are 0.70, 0.20 and 0.10. In a two-dimensional toy example, let the first two source values be (2, 0) and (0, 3), with all other source values set to zero. The weighted result is (1.4, 0.6). These numbers are illustrative. They show that the head writes a mixture of source features, with roughly independent roles for the matching score and the content of the value vector.
The query and key projections give the model a space for computing compatibility. The value projection gives it a space for transmitting useful content. Two tokens can get similar weights and still write very different signals. That is why an attention plot is a map of where a head reads, and understanding the final prediction can require inspecting the content sent and the later layers that receive it.
Scaling the dot products keeps their typical magnitudes from growing too far as the key dimension increases. Very large differences can push the softmax toward a single winner early in training. The square-root factor keeps that behavior more stable when the width of a head changes.
Several heads perform the same operation in different learned subspaces. The block concatenates their results and projects them back into the model width. A position-wise feed-forward network then transforms each position’s representation. Residual connections and normalization help these blocks compose across depth.
An encoder and decoder use attention differently
The original paper translated one input sequence into a different output sequence. The encoder’s self-attention can use the entire source sentence. Decoder self-attention uses a causal mask so that a prediction sees only preceding output tokens. The decoder also uses cross-attention. In that operation, queries come from the decoder and keys and values come from the encoded source. A prediction can combine the source sentence with the translation it has produced so far.
The mask is simple to express when the target sequence is known. For the first three target positions, the allowed source sets within the decoder grow from one position to two, then three. All three predictions can still run in the same training pass. The visible prefix ends at the point where the ground-truth continuation has yet to be predicted. Cross-attention, meanwhile, can consult all encoded source positions because the complete source sequence is already known.
The model adds position information to the token embeddings so attention can distinguish sequence order. The paper used sinusoidal encodings and compared them with learned position embeddings. Modern descendants sometimes keep the overall attention block while changing how position, normalization and the feed-forward layers work. Many language models use a decoder-only layout with causal attention. Those are choices made after the original architecture demonstrated a direct communication path across positions.
Translation was a strong test of the change because it needs both local structure and long-distance connections. In an encoder-decoder model, the correct translation at one position can depend on source words that appear in a different order. The attention mechanism gives the prediction a direct route to that evidence. BLEU then compares generated translations with human references using overlapping word sequences. It provides a standard benchmark with historical baselines, while reference quality and wording still affect how much the score tells you about individual examples.
What became expensive at longer lengths
Full attention compares each allowed query with many keys, and the number of pairs grows quadratically with sequence length. That can be an excellent bargain for short sequences when it replaces serial recurrence. It becomes a cost to manage for long inputs. Doubling a full attention window gives each token twice as many candidate sources and creates twice as many queries. That is about four times as many score computations at the same head width. The cost changes when the model uses a local window or another structured mask. In those designs, some long-range information must travel through several layers or through specially connected tokens. Efficient kernels can reduce memory traffic, and restricted attention patterns can reduce the number of pairs at the cost of changing which positions can communicate directly.
Training can evaluate known target positions in parallel because the correct preceding tokens are already available and the mask prevents peeking. Generation still produces one new token at a time. During generation, the system can cache keys and values for the tokens already processed. That avoids repeating their projections but still requires reading the selected context for each new query. The training problem is to process many known tokens efficiently. The serving problem includes a serial loop and a cache that grows with the generated sequence. The strong machine-translation result showed that attention could replace recurrence in this setup. The difference between training a sequence model and serving its generated tokens remains central to how systems teams budget the work today.


