Role of Bias Terms in Dot-Product Attention

Mahdi Namazifar, Devamanyu Hazarika, Dilek Hakkani-Tur · DOI

Abstract

As Transformer models scale to billions of parameters, identifying architectural redundancies is essential for improving efficiency. This paper investigates the necessity of bias terms within the dot-product attention mechanism—specifically the Query ($b_q$), Key ($b_k$), and Value ($b_v$) biases. Through mathematical analysis and empirical validation, we demonstrate that the Key bias is mathematically redundant due to the translation invariance property of the Softmax function. Removing or randomizing this parameter results in zero performance loss across standard NLP benchmarks and enables an 11% reduction in trainable parameters for parameter-efficient fine-tuning methods like BitFit.

Introduction

The Transformer architecture has become the standard for natural language processing, yet its massive parameter count poses significant challenges for deployment and fine-tuning. While existing literature often focuses on pruning entire attention heads or layers, this study examines the fine-grained components of the attention mechanism itself. Standard implementations of dot-product attention typically include bias vectors for the linear transformations of Queries, Keys, and Values. We set out to determine if these biases are functional or if they represent unnecessary "dead weight" in the model.

Mathematical Redundancy of the Key Bias

The core of our finding lies in the mathematical definition of dot-product attention. The attention weights are calculated using the Softmax function:

$$\text{Attention}(Q, K, V) = \text{Softmax}\left(\frac{QK^T}{\sqrt{d_k}}\right)V$$

When we expand the term $QK^T$ to include the bias vectors, the Key bias ($b_k$) interacts with the Query ($q$) such that it adds a constant scalar value to every attention score in the sequence for that specific query. Because the Softmax function is translation invariant—meaning $\text{Softmax}(x) = \text{Softmax}(x + c)$ for any constant $c$—this added scalar is mathematically cancelled out during the normalization step. Consequently, $b_k$ does not influence the resulting attention distribution.

Experimental Methodology

We employed a three-pronged approach to validate this theoretical redundancy:

  1. Numerical Sensitivity Analysis: We modified pre-trained RoBERTa and BART models by replacing their bias terms with zeros, ones, or random noise, measuring the subsequent change in hidden states.
  2. Training from Scratch: We trained GPT-2 and RoBERTa models from scratch on Wikitext-103-v1 without the Key bias to compare their convergence and final performance against standard baselines.
  3. Efficiency in Fine-Tuning: We applied these findings to BitFit, a method that only updates bias terms during fine-tuning, to see if freezing the redundant $b_k$ parameters could improve efficiency without sacrificing accuracy.

Key Results

1. Performance Stability

Models trained without the Key bias performed identically to their fully-biased counterparts. For instance, GPT-2 achieved a test loss of 2.9250 without $b_k$, compared to 2.9251 with it—a difference that is statistically insignificant. Furthermore, we found that the Key bias in a pre-trained RoBERTa model could be replaced with random noise (ranging from -5 to 5) with zero impact on GLUE benchmark accuracy.

2. The Hierarchy of Biases

Our sensitivity analysis revealed that not all biases are created equal. While $b_k$ is redundant, the Value bias ($b_v$) is the most critical component, as it provides a global shift for the entire attention output. The Query bias ($b_q$) also retains some functionality, though it is less impactful than $b_v$.

3. Efficiency Gains in BitFit

The practical benefits of this redundancy are most apparent in parameter-efficient fine-tuning. In BitFit experiments with BART-large on the XSUM summarization task, freezing the Key bias reduced the number of trainable parameters by 11.1%. This reduction came with no drop in ROUGE scores, proving that $b_k$ is an unnecessary target for optimization.

Discussion and Limitations

While the Key bias represents a tiny fraction of a Transformer's total parameters (often less than 0.01% of a single layer), its redundancy is a matter of architectural principle. We observed that zeroing out $b_k$ in pre-trained models does cause a negligible change in hidden states (at a tolerance of $10^{-4}$); however, we proved this is a result of floating-point errors in computer-based Softmax calculations rather than a functional requirement of the model.

Future work should investigate whether these findings extend to alternative attention kernels, such as linear attention, where the translation invariance of Softmax might not apply. Additionally, these "useless" parameter slots could potentially be repurposed to enhance model capacity rather than simply being removed.

Conclusion

The Key bias in dot-product attention is mathematically and empirically redundant. By removing this "dead weight," researchers and practitioners can simplify Transformer architectures and reduce the overhead of fine-tuning without any cost to model performance.

Summary updated

BibTeX
@inproceedings{namazifar2023role,
  author = {Mahdi Namazifar and Devamanyu Hazarika and Dilek Hakkani-Tur},
  title = {{Role of Bias Terms in Dot-Product Attention}},
  booktitle = {IEEE International Conference on Acoustics, Speech and Signal Processing},
  year = {2023},
  doi = {10.1109/icassp49357.2023.10097125},
}
Figure