Attention Is All You Need · Section 6.1

6.1 Machine translation

The results: the Transformer against the best translation systems of 2017, on quality and on training cost, and how the paper decoded its translations.

Table 2, live
Table 2 of the paper, English to German (newstest2014)
ByteNet 23.75 —
Deep-Att + PosUnk — —
GNMT + RL 24.6 2.3 · 10¹⁹
ConvS2S 25.16 9.6 · 10¹⁸
MoE 26.03 2.0 · 10¹⁹
Deep-Att + PosUnk Ensemble — —
GNMT + RL Ensemble 26.30 1.8 · 10²⁰
ConvS2S Ensemble 26.36 7.7 · 10¹⁹
Transformer (base model) 27.3 3.3 · 10¹⁸
Transformer (big) 28.4 2.3 · 10¹⁹

BLEU EN-DE

BLEU on newstest2014, English to German: how many words and short phrases of each translation also appear in the human reference, from 0 to 100. Higher is better.

The paper gives one training cost for each Transformer, for both language pairs; a dash means the paper gives no value.

The paper's Table 2 redrawn: every system's BLEU score and training cost for English to German or English to French, the pair you pick, as bars, the Transformer's rows marked. Click a column's name to see what it measures.

What this section says

Table 2 sets the Transformer against the best systems of the time on the WMT 2014 test sets (newstest2014). The quality column is BLEU; the cost column estimates the floating-point operations spent on training: training time × number of GPUs × each GPU's sustained speed (footnote 5 gives the speeds).

English to German: the big Transformer scores 28.4, more than 2 BLEU above every earlier model, including ensembles that average several models. Even the base model, at 27.3, beats them all, at a fraction of their training cost. English to French: the abstract and Table 2 give the big model 41.8, a new best for a single model at less than a quarter of the cost of the previous best; the text of section 6.1 in arXiv version 7 says 41.0 at that point, a discrepancy in the paper itself.

How the translations were produced: the weights of the last 5 checkpoints (base) or 20 (big) averaged into one model, then beam search with a beam of 4 and a length penalty α = 0.6, chosen on the development set; the output may be up to 50 tokens longer than the input, but stops early when it can.

In the paper's words

“We used beam search with a beam size of \(4\) and length penalty \(\alpha=0.6\) [38].”

Section 6.1 In plain words: Translations were decoded with beam search, keeping four candidates, with a length penalty of 0.6.

“Even our base model surpasses all previously published models and ensembles, at a fraction of the training cost of any of the competitive models.”

Section 6.1 In plain words: Even the smaller base model beats every earlier system, at a small part of their training cost.

Quoted from Vaswani et al., Attention Is All You Need, arXiv:1706.03762v7(opens in a new tab). The figures on this page are redrawn, not copied.

The notation

The symbols of this section, in the paper and in our model
Symbol Meaning In the paper Our miniature
\(\text{BLEU}\) how closely a translation matches a human one, from 0 to 100 28.4 (EN-DE), 41.8 (EN-FR), big model 99.95 on our 805 held-out sentences
\(\text{FLOPs}\) floating-point operations spent on training 3.3 · 10¹⁸ (base), 2.3 · 10¹⁹ (big) not estimated: about four minutes on one processor
\(\text{beam size}\) how many beginnings beam search keeps at every step 4 4
\(\alpha\) the length penalty's strength: larger favours longer translations 0.6 0.6

Try it

Score a translation the paper's way

How do you score a translation automatically? BLEU counts how many of its words, pairs of words, triples and quadruples also appear in a human reference translation, and lowers the score if the translation is too short. The paper reports its results in BLEU.

Candidate translation (German)
Reference translation (German)

The English: Anna has a small flower . She draws it .

BLEU = 100.00

nThe candidate's n-grams (matches marked)MatchesPrecision
1 Anna (in the reference)hat (in the reference)eine (in the reference)kleine (in the reference)Blume (in the reference). (in the reference)Sie (in the reference)zeichnet (in the reference)sie (in the reference). (in the reference) 10 / 10 100.0 %
2 Anna hat (in the reference)hat eine (in the reference)eine kleine (in the reference)kleine Blume (in the reference)Blume . (in the reference). Sie (in the reference)Sie zeichnet (in the reference)zeichnet sie (in the reference)sie . (in the reference) 9 / 9 100.0 %
3 Anna hat eine (in the reference)hat eine kleine (in the reference)eine kleine Blume (in the reference)kleine Blume . (in the reference)Blume . Sie (in the reference). Sie zeichnet (in the reference)Sie zeichnet sie (in the reference)zeichnet sie . (in the reference) 8 / 8 100.0 %
4 Anna hat eine kleine (in the reference)hat eine kleine Blume (in the reference)eine kleine Blume . (in the reference)kleine Blume . Sie (in the reference)Blume . Sie zeichnet (in the reference). Sie zeichnet sie (in the reference)Sie zeichnet sie . (in the reference) 7 / 7 100.0 %

Candidate 10 tokens, reference 10: brevity penalty 1.000.

How the score is made

For n = 1 to 4, take every run of n words in the candidate (its n-grams) and count how many also appear in the reference. Each reference n-gram can be matched only as often as it occurs there, so repeating a right word does not help. The share that match is the n-gram precision; matching longer n-grams means the word order is right too.

BLEU multiplies the four precisions and takes the fourth root (their geometric mean), then multiplies by the brevity penalty: 1 if the candidate is longer than the reference, otherwise e^(1 − r/c), with r the reference's length and c the candidate's. Without it, a candidate of one sure word would score perfectly. The result is shown from 0 to 100.

BLEU only counts matching words. A correct translation that uses other words than the reference scores lower, so it is a rough measure, good for comparing systems on thousands of sentences, poor for judging one.

In the paper (6.1)

The paper reports BLEU on the WMT 2014 English–German and English–French test sets (its Table 2). Our model scores 99.95 on its 805 held-out sentences, because our synthetic task is far easier than real news text.

On its own page: BLEU calculator

The BLEU calculator: type a German translation and a reference, and see the matching words and phrases highlighted, the four precisions, the brevity penalty and the score.

Try this Watch beam search with the paper's beam of 4 and α = 0.6 grow as a tree, and change the width.

How our miniature differs

Our miniature decodes the same way, beam 4 and α = 0.6, without checkpoint averaging, and reaches BLEU 99.95 on our 805 held-out sentences. One finding the paper does not discuss: greedy search and beam search give different German for exactly one of them, “The old women see a car now .”, because our search, like the training script it copies, stops once four translations have finished, and four short, unlikely ones finished first (chapter 19).

Check yourself

Three questions a reader of this section should now be able to answer. The lab checks your answer against the paper and our models.

The base model

What BLEU score does the Transformer base model reach on English to German in Table 2?

Your answer
Within 0.05 of the answer

A fraction of the cost

On English to French, what fraction of MoE's training cost did the big Transformer use? Give two decimals.

Your answer
Within 0.005 of the answer

The length penalty

The length penalty is ((5 + |Y|) / 6)^α. With α = 0.6, what is it for a translation of |Y| = 10 tokens? Give two decimals.

Your answer
Within 0.005 of the answer
An unhandled error has occurred. Reload 🗙

Reconnecting…

Your connection to the Transformers and Attention Lab dropped, probably a Wi-Fi blip. Hold on while it reconnects.

The connection could not be restored. The page will reload in a few seconds.