cs.LGOct 9, 2026

Data-Adaptive Mahalanobis Metric Learning for Cross-Head Attention in Transformers

Authors: Zhenke Duan, Xin Li, Jiqun Pan, Dong Xiaofei, Hanwen Ning, Xinyuan Song

Organizations: School of Statistics and Mathematics, Zhongnan University of Economics and Law, Wuhan, China · CodeSoul.Co, Hangzhou, China · Innovation and Talent Base for Digital Technology and Finance, ZUEL · Department of Statistics, The Chinese University of Hong Kong, Hong Kong SAR, China

Abstract

In this paper, we propose Data-Adaptive Mahalanobis Cross-Head Attention (DAMCHA), a simple and effective attention mechanism that generalizes Multi-Head Attention (MHA) through the lens of metric learning. Standard MHA implicitly learns a static, head-wise Euclidean similarity corresponding to the diagonal blocks of a unified cross-head metric matrix, discarding all off-diagonal interactions across heads. DAMCHA addresses this limitation via two key innovations. First, it learns the full cross-head metric matrix, inducing a Mahalanobis-like similarity that explicitly captures inter-head interactions beyond the restricted block-diagonal structure of MHA. Second, it parameterizes the metric matrix as an input-dependent function, enabling the attention geometry to dynamically adapt to the intrinsic manifold structure of the data rather than remaining fixed after training. We further introduce principled regularization strategies, most notably stack-wise parameter sharing, to ensure computational efficiency and stable optimization. DAMCHA serves as a drop-in replacement for MHA and its variants in various Transformer architectures, delivering superior expressive power and learning performance with comparable or reduced computational overhead. Extensive experiments demonstrate that DAMCHA-based Transformers consistently outperform competing baselines across a range of benchmark tasks. Code is available at https://github.com/erwinmsmith/DAMCHA.

Figures & tables

Appendix figures & tables11 assets

Supplementary material from the paper’s appendix.

Appendix

Explore similar work

CardsList
  1. Multi-Head Attention Residuals

    Jul 22, 2026Cheng Luo, Zefan Cai, Junjie HuTransformerAttention Residual Connections

  2. Interleaved Head Attention

    Feb 24, 2026Sai Surya Duvvuri, Chanakya Ekbote, Rachit Bansal +6Multi-Head AttentionLLM Reasoning