1 00:00:01,000 --> 00:00:09,300 [Hal Turing] Alrighty! Thanks for tuning in! Hello AI world! I am your host, Hal Turing, and my co-host is Dr. Ada Shannon. 2 00:00:09,300 --> 00:00:36,299 [Hal Turing] Today we're looking at Query-Key Normalization for Transformers, by Alex Henry and colleagues at Cyndx Technologies. The claim is small and specific. Take the dot product inside attention, replace it with a scaled cosine similarity, and a strong translation baseline improves by an average of 0.928 BLEU across five low-resource language pairs. The question for us is how much of that gain the change itself can claim. 3 00:00:36,299 --> 00:00:54,500 [Dr. Ada Shannon] It matters because the change is nearly free, one scalar and two normalizations. The same idea later became standard for keeping large models stable. But this paper tests it on tiny models and tiny datasets, so we need to be careful about what it shows. First, the setting. 4 00:00:54,500 --> 00:00:58,350 [Hal Turing] Low-resource translation. What counts as low? 5 00:00:58,350 --> 00:01:35,550 [Dr. Ada Shannon] Parallel corpora of roughly ten thousand to about two hundred fourteen thousand sentence pairs. English-French has tens of millions. The models are small Transformers, around 31 to 48 million parameters, trained for hours on a single T4 or P100 GPU. The paper calls the task socially valuable because most of the world's languages are in this regime. Its list of existing strategies includes multilingual transfer, shallower models, and a penalty that pulls the translator toward a pretrained language model. This paper takes none of those routes. It changes the architecture and adds no data. 6 00:01:35,550 --> 00:01:39,775 [Hal Turing] Then the architecture. Walk me through where the trouble is. 7 00:01:39,775 --> 00:02:16,100 [Dr. Ada Shannon] Attention computes queries, keys and values. Query-key dot products give a score for every pair of positions. Softmax turns each row of scores into weights that sum to one. The key property is that softmax only sees differences between scores. The paper's example is softmax of 760, 752, 750. That equals softmax of 12, 4, 2, which comes out around 0.99962, 0.00034 and 0.00005. Almost all the weight lands on one token. 8 00:02:16,100 --> 00:02:20,900 [Hal Turing] So the scores are huge, but a gap of eight is what does the work. 9 00:02:20,900 --> 00:02:40,225 [Dr. Ada Shannon] Right. Dot products are unbounded, so small relative gaps can produce near one-hot, winner-take-all attention. The authors conjecture that this limits what heads can learn, because diffuse patterns become hard to reach. It's only a conjecture. The paper doesn't establish that saturation is the cause of anything. 10 00:02:40,225 --> 00:02:45,651 [Hal Turing] Fine. Now the normalization vocabulary, because there are several terms. 11 00:02:45,651 --> 00:03:15,201 [Dr. Ada Shannon] LayerNorm re-centers and re-scales activations across the embedding dimension. PreNorm puts that normalization at the input of each sublayer, so the residual path stays an identity map. FixNorm forces word embeddings to unit length. ScaleNorm replaces LayerNorm with L2 normalization times one learnable scalar, initialized at one over the square root of the embedding dimension. Those three come from Nguyen and Salazar's 2019 paper, Transformers without Tears. They report about 0.3 BLEU from each, roughly 1.1 combined. 12 00:03:15,201 --> 00:03:17,551 [Hal Turing] And that's the baseline here. 13 00:03:17,551 --> 00:03:29,751 [Dr. Ada Shannon] Yes. This paper builds directly on that setup and is scored against it on the same five pairs. Think of QKNorm as applying the ScaleNorm idea inside the attention scores. 14 00:03:29,751 --> 00:03:33,126 [Hal Turing] So what does QKNorm actually do? 15 00:03:33,126 --> 00:03:51,551 [Dr. Ada Shannon] After the heads are split, it L2-normalizes each query vector and each key vector along the head dimension. Now every entry of the score matrix is a cosine similarity, bounded between minus one and one. Direction decides relevance. Magnitude no longer can. It leaves the values alone. 16 00:03:51,551 --> 00:04:00,226 [Hal Turing] But bounded between minus one and one sounds like the opposite problem. Everything's nearly equal, and softmax goes flat. 17 00:04:00,226 --> 00:04:22,076 [Dr. Ada Shannon] Yes, that's the catch. The scores are too close together for the model to ignore anything. So instead of dividing by the square root of the head dimension, you multiply by a learnable scale g. Attention becomes softmax of g times normalized Q times normalized K transposed, applied to V. The model learns one temperature for how sharp attention should be, and it no longer depends on how large the projection matrices happen to grow. 18 00:04:22,076 --> 00:04:26,302 [Hal Turing] Does this replace LayerNorm, the way ScaleNorm does? 19 00:04:26,302 --> 00:04:41,928 [Dr. Ada Shannon] No. It complements LayerNorm. Keep that in mind, because the comparison in this paper depends on it. The baseline uses ScaleNorm. The QKNorm model uses LayerNorm. So the two systems differ in more than one place. We'll come back to that. 20 00:04:41,928 --> 00:04:46,028 [Hal Turing] I'm filing that away. What's the experimental frame? 21 00:04:46,028 --> 00:05:05,878 [Dr. Ada Shannon] Five translation pairs: Galician to English, Slovak to English, English to Vietnamese, English to Hebrew, and Arabic to English. Four come from TED Talks data. English to Vietnamese comes from IWSLT 2015. They range from about ten thousand to about two hundred fourteen thousand training examples. 22 00:05:05,878 --> 00:05:12,403 [Hal Turing] So the sizes are small, the training runs are cheap, and the baseline has already been tuned. 23 00:05:12,403 --> 00:05:18,378 [Dr. Ada Shannon] Yes. A tuned baseline makes any gain more credible, and it also leaves less room for one. 24 00:05:18,378 --> 00:05:23,328 [Hal Turing] Then the mechanism in detail. How does g get its starting value? 25 00:05:23,328 --> 00:05:45,103 [Dr. Ada Shannon] The starting value is a formula, and the paper says plainly that it's a rule of thumb. g starts at log base 2 of L squared minus L. L is the 97.5th-percentile sequence length across all the source and target training sentences. In Table 1 that's 72 to 79 depending on the pair, so g starts around 12.3 to 12.6. That's my arithmetic, not a number the paper states. 26 00:05:45,103 --> 00:05:51,528 [Hal Turing] Why would sequence length set the scale? Cosine scores don't know how long the sentence is. 27 00:05:51,528 --> 00:06:21,403 [Dr. Ada Shannon] Right, but the softmax does. A longer sentence means more entries competing in each row. The best case is a cosine of 1 against everything else near 0. The scale has to be big enough for that best match to take nearly all the weight, if the model wants that. At a length around 75 and g near 12, my estimate is that the best match gets over 99.9 percent. So the bounded range can still produce sharp attention when it's needed. The appendix says they found the equation empirically. And g is learnable, so the formula only sets where training starts. 28 00:06:21,403 --> 00:06:26,853 [Hal Turing] So the claim that dot products saturate softmax, does anything here show that? 29 00:06:26,853 --> 00:06:38,078 [Dr. Ada Shannon] No. Their own wording is that they conjecture it. The results show the cosine version works with a good starting temperature. They don't show saturation was the problem it fixed. 30 00:06:38,078 --> 00:06:41,328 [Hal Turing] Then how did they set up the comparison? 31 00:06:41,328 --> 00:06:59,928 [Dr. Ada Shannon] They took the code and hyperparameters from the Nguyen and Salazar repository, on the same five pairs. One addition is 8,000 steps of linear warmup. PreNorm normally makes warmup less important, but they needed it anyway. They report the test score from the epoch with the best validation score. 32 00:06:59,928 --> 00:07:02,753 [Hal Turing] And the score is BLEU. 33 00:07:02,753 --> 00:07:24,503 [Dr. Ada Shannon] BLEU measures n-gram overlap between the system's translation and human reference translations, on a 0 to 100 scale, and higher is better. About one point is a modest but noticeable difference. They also run bootstrap resampling, from Koehn in 2004. It resamples the test sentences many times to ask whether the gap holds across different samples of the test set. It doesn't retrain the model. 34 00:07:24,503 --> 00:07:26,203 [Hal Turing] What did they get? 35 00:07:26,203 --> 00:07:44,778 [Dr. Ada Shannon] The QKNorm model beats the Nguyen and Salazar model on all five pairs, and the average gain is 0.928 BLEU. Four pairs gain between about half a point and seven tenths. Galician to English gains more than two points. The SacreBLEU numbers, a second scorer, agree. 36 00:07:44,778 --> 00:07:48,453 [Hal Turing] Is there a catch in the Vietnamese baseline? 37 00:07:48,453 --> 00:08:08,728 [Dr. Ada Shannon] There's a discrepancy. The table uses the published baseline of 32.79. The authors' own best re-run scored 32.48 on the same scorer. Against their re-run, the Vietnamese gain is about 0.76, not 0.45. The direction doesn't change, but the baseline number has two sources. 38 00:08:08,728 --> 00:08:11,828 [Hal Turing] They also show attention heatmaps. 39 00:08:11,828 --> 00:08:45,928 [Dr. Ada Shannon] Figures 1 and 2. One encoder layer, four heads, from the Annotated Transformer trained for 10 epochs on IWSLT16 German to English. The dot-product heads look concentrated and the QKNorm heads look more diffuse. The BLEU goes from 19.4 to 24.33. The authors call it not systematic, and that's fair. It's one small model, and a 19.4 baseline after ten epochs may just be undertrained, so the gap could reflect faster convergence rather than healthier attention. Treat it as an intuition, not proof. 40 00:08:45,928 --> 00:08:49,753 [Hal Turing] Now the ablations. Which one tells us the most? 41 00:08:49,753 --> 00:09:09,753 [Dr. Ada Shannon] Removing g. On Vietnamese the full model gets 33.24. Without the learnable scale it gets 24.53, about 8.7 BLEU lower. The scores sit between minus one and one, so the softmax is nearly flat and the model can't pick out what it should attend to. That supports the story that cosine attention needs a temperature. 42 00:09:09,753 --> 00:09:12,053 [Hal Turing] And the other ablations? 43 00:09:12,053 --> 00:09:39,103 [Dr. Ada Shannon] They each cost something, between about 0.6 and 1.7 BLEU below the full model. Dropping LayerNorm gives 31.56, below the 32.79 baseline. Dropping FixNorm gives 32.63. Dropping both FixNorm and PreNorm gives 32.20. Normalizing V along with Q and K gives 32.34. So the gain depends on the normalizations around it, and normalizing V is worse than leaving it alone. All of this is on one language pair, single runs. 44 00:09:39,103 --> 00:09:41,803 [Hal Turing] Did they sweep anything else? 45 00:09:41,803 --> 00:09:54,853 [Dr. Ada Shannon] Two appendix sweeps, on Vietnamese: the number of heads, and the percentile for g0. I'll just describe them for now. Both peak at the defaults, 8 heads and the 97.5th percentile. 46 00:09:54,853 --> 00:09:57,628 [Hal Turing] Is a gain of that size big? 47 00:09:57,628 --> 00:10:25,103 [Dr. Ada Shannon] The authors give one comparison. The Vietnamese SacreBLEU of 33.18 is 0.09 below the BPE-dropout result from Provilkov and colleagues in 2020, which raised BLEU by 1.49 over vanilla BPE. BPE-dropout randomly varies how words are split into subwords during training. So QKNorm lands in the same neighborhood as a well-known regularization trick, with a smaller measured gain over its baseline. It's a small improvement, but a consistent one across pairs. 48 00:10:25,103 --> 00:10:32,378 [Hal Turing] Let's talk about what this paper can and can't claim. Where does the 0.928 average stand? 49 00:10:32,378 --> 00:10:51,553 [Dr. Ada Shannon] It can't be credited to QKNorm alone. The baseline uses ScaleNorm with ordinary scaled dot-product attention. The new model uses LayerNorm with QKNorm. Two things change at once, and the paper never runs the clean controls: ScaleNorm plus QKNorm, or LayerNorm plus standard attention. 50 00:10:51,553 --> 00:10:54,928 [Hal Turing] So how much of the gain is QKNorm? 51 00:10:54,928 --> 00:11:14,754 [Dr. Ada Shannon] Unknown. Nguyen and Salazar credit ScaleNorm with about 0.3 BLEU. So LayerNorm might be handicapping the baseline comparison, or it might interact with QKNorm in a way nobody measured. The ablation helps a little, since dropping LayerNorm falls below the baseline. But that's a removal, not a swap, and it's one language pair. 52 00:11:14,754 --> 00:11:19,079 [Hal Turing] What about the noise? Each cell looks like one training run. 53 00:11:19,079 --> 00:11:40,404 [Dr. Ada Shannon] That's my reading too: no seeds, no standard deviations. The p below 0.01 comes from bootstrap resampling, which only asks whether the test-set sample could explain the gap. It says nothing about retraining the model. Small Transformers on ten thousand to two hundred thousand sentences can vary noticeably from run to run. What would settle it is five seeds per cell for both models. 54 00:11:40,404 --> 00:11:45,929 [Hal Turing] And the paper's own sensitivity tables hint at how big that noise is. 55 00:11:45,929 --> 00:12:07,179 [Dr. Ada Shannon] They do, though they aren't a seed study. Moving the percentile for the initial scale from 97.5 to 99 drops Vietnamese by about 0.6. Going from 8 heads to 16 drops it by about 0.8. Those are as large as the typical per-pair gain. It's also odd that a scale called learnable cares this much about where it starts. 56 00:12:07,179 --> 00:12:09,879 [Hal Turing] Then there's Galician-to-English. 57 00:12:09,879 --> 00:12:32,105 [Dr. Ada Shannon] That pair supplies about 47 percent of the total gain, 2.2 BLEU on the smallest corpus, ten thousand examples. Without it the other four average about 0.6. Two readings fit. In tiny-data settings anything that smooths the softmax may act as a regularizer. Or it's one lucky run against one unlucky run. The paper's planned high-resource experiments are the right next test. 58 00:12:32,105 --> 00:12:36,055 [Hal Turing] Did the baseline get the same care as the new model? 59 00:12:36,055 --> 00:12:58,355 [Dr. Ada Shannon] Not visibly. The head count and the percentile were swept on Vietnamese test BLEU, and the paper reports no equivalent tuning for the baseline. It does say it reports the epoch with the best validation score, but the hyperparameter choice itself used test data. That could favor the QKNorm model. Add the 32.79 versus 32.48 mismatch for the Vietnamese baseline, and the comparison is less clean than the headline suggests. 60 00:12:58,355 --> 00:13:02,430 [Hal Turing] And removing g costing nearly nine BLEU? 61 00:13:02,430 --> 00:13:18,305 [Dr. Ada Shannon] It shows a scale is necessary. It doesn't show cosine beats a plain scaled dot product. A missing control is standard attention with a learnable temperature and no normalization. That would separate the learned scale from the cosine geometry. 62 00:13:18,305 --> 00:13:21,530 [Hal Turing] Where did the idea actually prove itself? 63 00:13:21,530 --> 00:13:56,805 [Dr. Ada Shannon] On stability at scale, which this paper never tested. Dehghani and colleagues at Google, in 2023, in Scaling Vision Transformers to 22 Billion Parameters, found query-key LayerNorm was needed to avoid attention logits diverging. Wortsman and colleagues, also 2023, in Small-scale proxies for large-scale Transformer training instabilities, reproduced attention-logit growth causing loss spikes in small models, and showed QK-LayerNorm mitigates it. Liu and colleagues at Microsoft, in Swin Transformer V2 in 2022, used scaled cosine attention with a learnable temperature per head, clamped to a minimum. 64 00:13:56,805 --> 00:13:59,105 [Hal Turing] So that's confirmation. 65 00:13:59,105 --> 00:14:19,155 [Dr. Ada Shannon] Of the idea, yes. Of this paper's numbers, no. Those works address a different problem, training stability, at far larger scale. The Wortsman diagnostics are what the heatmaps were gesturing at. Also, this paper used one global scale, while Swin V2 gives each head its own. A shared scale may limit how differently peaked heads can be, and the paper doesn't test that. 66 00:14:19,155 --> 00:14:22,755 [Hal Turing] What should someone building a model do with this? 67 00:14:22,755 --> 00:14:37,230 [Dr. Ada Shannon] It's a small code change, so try it. Keep LayerNorm, make the scale learnable, and initialize it with care. Don't expect 0.928 BLEU. If you care about stability, the later papers are better evidence. 68 00:14:37,230 --> 00:14:40,005 [Hal Turing] And the authors' own next steps? 69 00:14:40,005 --> 00:14:49,380 [Dr. Ada Shannon] High-resource data, fairseq, FLORES, depth and head count, BPE-dropout, and head-level analysis like Clark and colleagues in 2019. 70 00:14:49,380 --> 00:15:14,980 [Hal Turing] So, summing up. The paper shows a consistent direction across five pairs, from a cheap, well-motivated change, and the learnable scale is clearly essential. What it doesn't show is how much QKNorm itself contributes. The comparison is confounded, based on single runs, partly tuned on test data, and led by one tiny pair. The saturation story is still a conjecture. Thanks for listening, everyone.