Query-Key Normalization for Transformers
Alex Henry, Prudhvi Raj Dachapally, Shubham Pawar, Yuxuan Chen
EMNLP 2020
cs.CL, cs.AI, cs.LG
2020-10-09
L2-normalize Q and K so attention logits become cosine similarities, then rescale with a learnable parameter: +0.928 BLEU on average across five low-resource translation pairs.
Attention in a Transformer scores token pairs with softmax(QKᵀ), and the dot product is unbounded. Softmax only responds to differences between its inputs: softmax([760, 752, 750]) equals softmax([12, 4, 2]), and both give [0.99962, 0.00034, 0.00005]. Once logits grow large, differences that are tiny in relative terms can drive every other token's weight toward zero, and attention heads collapse into winner-take-all patterns.
The paper argues this caps the variety of attention patterns a model can learn, and that the damage shows up most where data is scarce. Prior low-resource work attacked the problem elsewhere: multilingual transfer, shallower models, regularization toward a monolingual LM. Nguyen and Salazar (2019) held the state of the art on five low-resource pairs with FixNorm, PreNorm and ScaleNorm, leaving the attention scoring rule itself untouched.
QKNorm changes one thing: how attention scores are computed.
The scale-up is not decoration. Pure cosine similarities are too flat for softmax to suppress irrelevant connections, so a learnable gain reopens the dynamic range. QKNorm differs from ScaleNorm in placement and scope: ScaleNorm normalizes along the embedding dimension before the head split, QKNorm runs after the split, on Q and K only, and it complements LayerNorm rather than replacing it.
All five pairs improve, average +0.928 BLEU over the Nguyen & Salazar baseline, bootstrap resampling p < 0.01. Each model trained on a single T4 or P100 for 6 to 38 hours; the smallest corpus (gl→en, 10k sentence pairs, 0.37M tokens) is also where the gain is largest, which fits the saturation story.
| Pair | Nguyen & Salazar 2019 | QKNorm + LayerNorm |
| gl→en | 22.01 | 24.21 |
| ar→en | 36.09 | 36.75 |
| en→he | 28.28 | 28.96 |
| sk→en | 32.58 | 33.23 |
| en→vi | 32.79 | 33.24 |
Re-scoring everything with SacreBLEU leaves the four TED pairs basically unchanged and puts en→vi at 32.41 versus 33.18. Two side numbers. An unsystematic one: on IWSLT 2016 de→en with The Annotated Transformer code, 10 epochs, scaled dot-product attention scored 19.4 BLEU against 24.33 with QKNorm, a gap the paper itself labels 'obviously not systematic'. A comparative one: the en→vi SacreBLEU of 33.18 sits 0.09 below Provilkov et al. (2020), who gained 1.49 BLEU from BPE-dropout over the same baseline.
The change is a few lines of code and one new scalar, training cost is unchanged, and the code is public, so it stacks directly onto the existing PreNorm/FixNorm low-resource recipe. In the heatmap comparison the baseline shows winner-take-all attention while QKNorm spreads mass more evenly, giving intuitive support to the claim that unbounded dot products saturate softmax.
That said, this is an incremental improvement. 0.928 BLEU is a real gain in low-resource NMT, it does not change the architecture, and the mechanism remains a conjecture backed by one pair of heatmaps.
The mechanism explanation is a conjecture; the heatmap comparison is admittedly unsystematic, and no ablation locates where the gains come from. The controlled comparison changes two variables at once: the QKNorm model also replaces ScaleNorm with LayerNorm, so 0.928 is the combined effect and QKNorm's own share is never isolated. Only low-resource bilingual settings are tested, and whether the benefit survives high-resource training is deferred to future work. Warmup is an open puzzle: PreNorm was supposed to make linear warmup unnecessary, yet the best QKNorm results still used 8,000 warmup steps, for reasons the authors do not explain. And on en→vi their own replication of the baseline peaked at 32.48 with multi-bleu.perl, below the 32.79 reported by the original paper, so that pair's comparison rests partly on the earlier publication's number.