Superiority of Multi-Head Attention in In-Context Linear Regression

Yingqian Cui, Jie Ren, Pengfei He, Jiliang Tang, Yue XingarXiv 2024 · DOI

Superiority of Multi-Head Attention in In-Context Linear Regression

Introduction

Transformers have fundamentally changed machine learning through In-Context Learning (ICL), where models solve new tasks using only a few examples in a prompt without parameter updates. Despite their success, the theoretical justification for specific architectural components, such as multi-head attention (MHA), has remained largely empirical. This paper provides a rigorous theoretical proof demonstrating that MHA is fundamentally superior to single-head attention (SHA) for in-context linear regression.

Theoretical Framework

The authors model ICL as a linear regression task where a single-layer transformer predicts a target $y_q$ for a query $x_q$ based on a prompt of $D$ example pairs $(x_i, y_i)$. To analyze this, they derive exact prediction risks (Mean Squared Error) under a Gaussian data generation model.

A key mathematical tool used is the lazy training framework, which assumes certain weights remain near their initialization while others are optimized, making the non-convex optimization of softmax attention tractable. This allows for the derivation of exact risk curves that account for noise, feature correlation, and prior knowledge.

The Representational Advantage of Multi-Head Attention

A primary finding is that MHA offers greater representational flexibility than SHA. In SHA, the attention mechanism is constrained by non-negative attention scores. In contrast, MHA allows the model to combine outputs from multiple heads, effectively enabling "negative" weights in the final prediction. This flexibility allows MHA to approximate the underlying linear model more accurately.

Comparison of MSE between single-head and multi-head attention. MHA configurations (c=0.3, 0.5, 0.7) consistently achieve a lower error floor than the single-head baseline.

As shown in the figure above, theoretical predictions align closely with simulations. MHA consistently achieves a lower Mean Squared Error (MSE) across various scaling factors ($v$), demonstrating a superior "fit" for the regression task compared to the single-head counterpart.

Scaling and Architectural Constraints

The superiority of MHA is not unconditional; it depends on the embedding bottleneck. The authors find that the total embedding dimension ($p$) must be large enough to support multiple heads. Specifically, the dimension per head ($p/h$) should ideally meet or exceed the feature dimension ($d$). If the head count is increased such that each head is "starved" of dimensions, performance gains diminish.

Impact of head count on squared error. Increasing the number of heads from 1 to 64 significantly reduces error, provided the total embedding dimension is sufficient.

When the embedding dimension is sufficient, increasing the number of heads leads to a marked reduction in squared error as the number of in-context examples increases. This suggests that MHA learns a more sophisticated kernel for the regression task, resulting in a smaller multiplicative constant in the $O(1/D)$ error rate.

Conclusion

This research provides a theoretical foundation for the ubiquity of multi-head attention in modern architectures. By enabling negative weight contributions and more flexible kernel learning, MHA significantly outperforms SHA in in-context linear regression. Future work may extend these findings to multi-layer architectures and non-linear reasoning tasks to further bridge the gap between theory and the complex dynamics of large language models.

Summary updated

BibTeX
@misc{cui2024superiority,
  author = {Yingqian Cui and Jie Ren and Pengfei He and Jiliang Tang and Yue Xing},
  title = {{Superiority of Multi-Head Attention in In-Context Linear Regression}},
  year = {2024},
  eprint = {2401.17426},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2401.17426},
}
Figure