6.2 Model variations
Which parts of the design matter? The paper changes one thing at a time and measures the result, and we did the same on our miniature.
Our reruns of the paper's Table 3 rows on the tiny model, three seeds each: fewer and more heads (A), a smaller and a bigger model (C), no dropout and no label smoothing (D), learned positions (E). For each, the step at which it first translated 95 % of our held-out sentences and its held-out loss, next to the base model, with the loss curves.
What this section says
Table 3 starts from the base model and changes one setting per row, measuring perplexity and BLEU on the English–German development set (newstest2013), with beam search but no checkpoint averaging. The base row scores 25.8 BLEU there; the big model, the last row, 26.4.
- (A) Heads: h from 1 to 32 with d_k = d_v = 512 / h, so the work stays the same (section 3.2.2). One head is clearly worse; too many heads also lose a little.
- (B) Key size: a smaller d_k hurts, which suggests that judging compatibility is not easy and a better function than the dot product might help.
- (C) Size: more layers, wider vectors and wider feed-forward networks are better, as expected.
- (D) Regularisation: without dropout the model overfits; label smoothing, as section 5.4 said, worsens perplexity but not BLEU.
- (E) Positions: learned positions instead of sines give nearly the same result (section 3.5).
The method is the lesson for Daniel: when a design has many parts, change one at a time against a fixed baseline, and report what moved.
In the paper's words
“While single-head attention is 0.9 BLEU worse than the best setting, quality also drops off with too many heads.”
“We further observe in rows (C) and (D) that, as expected, bigger models are better, and dropout is very helpful in avoiding over-fitting.”
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
| Symbol | Meaning | In the paper | Our miniature |
|---|---|---|---|
| \(N,\ d_{\text{model}},\ d_{ff}\) | layers, vector size and feed-forward width: rows (C) | 6, 512, 2048 (base) | 2, 64, 256 |
| \(h,\ d_k,\ d_v\) | heads and their size: rows (A) and (B) | 8, 64, 64 | 4, 16, 16 |
| \(P_{drop},\ \epsilon_{ls}\) | dropout and label smoothing: rows (D) | 0.1, 0.1 | 0.1, 0.1 |
| \(\text{PPL}\) | perplexity per word piece on the development set; lower is better | 4.92 (base) | not measured; we use the held-out loss |
| \(\text{params}\) | the number of weights, in millions | 65 (base), 213 (big) | about a quarter of a million |
Try it
From “it” it looks most at “.” (37.4 %).
From “it” it looks most at “</s>” (18.6 %).
From “it” it looks most at “dog” (87.9 %).
From “it” it looks most at “dog” (34.3 %).
| Token | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | … 56 more |
|---|---|---|---|---|---|---|---|---|---|
| All heads on | 0.45 | 0.12 | 0.62 | −0.71 | 0.15 | −0.17 | 1.11 | −0.06 | … |
| As switched now | 0.45 | 0.12 | 0.62 | −0.71 | 0.15 | −0.17 | 1.11 | −0.06 | … |
Every head is on: switch one off to see how much the output changes.
The heads of one attention layer of our model as heat maps on your sentence. Switch a head off and the layer's output, recomputed without it, changes: how much each head contributes.
How our miniature differs
Our task is easy: every variant ends up translating our held-out sentences almost perfectly, so BLEU cannot rank them. We compare instead the step at which each first translates 95 % of them, averaged over three seeds: the base model at step 187; one head 227, sixteen heads 207; d_model 32 at 240, d_model 128 at 180. The pattern echoes the paper's, one head and a smaller model slower, a bigger model faster, but on a task far easier than WMT, so it is a sketch, not a replication.
Prepared in the Course by
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 row
What BLEU does the base model score on the development set in Table 3?
One head
According to section 6.2, how does single-head attention compare?
Our fastest variant
Among our reruns of rows (A) and (C), which variant first translated 95 % of the held-out sentences earliest?