Abstract
The Transformer architecture has revolutionized natural language processing, yet it remains susceptible to the "softmax bottleneck," where unbounded dot products in the attention mechanism lead to saturated, "peaky" attention distributions. This phenomenon is particularly detrimental in low-resource scenarios where the model must capture subtle contextual relationships. We propose Query-Key Normalization (QKNORM), a simple modification that applies $\ell_2$ normalization to queries and keys, effectively replacing dot products with scaled cosine similarity. Our results demonstrate that QKNORM prevents softmax saturation, promotes more diffuse attention patterns, and yields significant performance gains in low-resource machine translation.
Introduction
Modern NLP relies heavily on the Transformer's attention mechanism. However, the standard dot-product attention calculation is inherently unbounded. As training progresses, the magnitude of these dot products can grow excessively large. When passed through the softmax function, these large values result in a "winner-take-all" distribution where a single token receives nearly all the attention weight. This "softmax saturation" limits the model's ability to learn diffuse patterns—contextual dependencies where information must be integrated from multiple source tokens simultaneously. This limitation is most pronounced in low-resource settings, where data scarcity makes it harder for the model to navigate the optimization landscape.
Methodology: Query-Key Normalization (QKNORM)
To address the softmax bottleneck, we introduce QKNORM. The core idea is to bound the attention scores by applying $\ell_2$ normalization to the Query ($Q$) and Key ($K$) vectors along the head dimension before computing their product.
Mathematical Formulation
The standard attention score is computed as $Q K^T / \sqrt{d_k}$. In QKNORM, we modify this to: $$\text{Attention}(Q, K, V) = \text{softmax}\left(g \cdot \frac{\hat{Q} \hat{K}^T}{\tau}\right) V$$ where $\hat{Q}$ and $\hat{K}$ are $\ell_2$-normalized versions of $Q$ and $K$. This transformation effectively changes the dot product into a cosine similarity, which is bounded between -1 and 1.
Learnable Scaling and Initialization
Because the range [-1, 1] is insufficient for the softmax function to distinguish between tokens effectively, we introduce a learnable scalar parameter $g$. This parameter allows the model to adaptively control the "sharpness" of the attention distribution. We initialize $g$ using a heuristic based on sequence length: $g_0 = \log_2(L^2 - L)$, where $L$ represents the 97.5th percentile of sequence lengths in the training set. This ensures a reasonable initial dynamic range.
Experimental Evaluation
We evaluated QKNORM across five low-resource translation tasks using the TED Talks (Arabic$\to$English, Slovak$\to$English, Galician$\to$English, and English$\to$Hebrew) and IWSLT’15 (English$\to$Vietnamese) corpora. Training sets for these pairs range from 10k to 214k examples, providing a rigorous test for generalization under data constraints.
Results and Discussion
QKNORM consistently outperformed state-of-the-art bilingual benchmarks, achieving an average improvement of 0.928 BLEU points. Notably, for Galician-to-English translation, the model saw a substantial increase from 22.01 to 24.21 BLEU.
Visualizing Attention Patterns
The impact of QKNORM is most visible in the attention heatmaps. Standard Transformers often exhibit highly concentrated attention, as seen in Figure 2. In contrast, QKNORM allows for more diffuse attention patterns (Figure 3), enabling the model to weigh multiple context tokens simultaneously.
Ablation studies confirmed that the learnable scaling factor $g$ is critical; removing it resulted in a performance drop of nearly 8 BLEU points. Furthermore, QKNORM was found to be complementary to other normalization techniques like FIXNORM and PRENORM, addressing a specific bottleneck within the attention head that layer-level normalization does not resolve.
Conclusion
Query-Key Normalization offers a simple yet powerful solution to the softmax saturation problem in Transformers. By bounding attention scores and introducing learnable scaling, QKNORM enhances the expressivity of the attention mechanism, particularly in low-resource environments. Future work will explore the efficacy of QKNORM in high-resource, large-scale pre-training and investigate the specific linguistic features captured by the more diffuse attention heads.
Summary updated