Dissecting the Interplay of Attention Paths in a Statistical Mechanics Theory of Transformers

Lorenzo Tiberi, Francesca Mignacco, Kazuki Irie, Haim Sompolinsky
5/24/2024
cs.LGcond-mat.dis-nncond-mat.stat-mech

No official code found. Best implementation: tiberilor/attention-paths-interplay (2 stars, MIT, last commit 2024-05-24).

Abstract

Despite the remarkable empirical performance of Transformers, their theoretical understanding remains elusive. Here, we consider a deep multi-head self-attention network, that is closely related to Transformers yet analytically tractable. We develop a statistical mechanics theory of Bayesian learning in this model, deriving exact equations for the network's predictor statistics under the finite-width thermodynamic limit, i.e., $N,P\rightarrow\infty$, $P/N=\mathcal{O}(1)$, where $N$ is the network width and $P$ is the number of training examples. Our theory shows that the predictor statistics are expressed as a sum of independent kernels, each one pairing different 'attention paths', defined as information pathways through different attention heads across layers. The kernels are weighted according to a 'task-relevant kernel combination' mechanism that aligns the total kernel with the task labels. As a consequence, this interplay between attention paths enhances generalization performance. Experiments confirm our findings on both synthetic and real-world sequence classification tasks. Finally, our theory explicitly relates the kernel combination mechanism to properties of the learned weights, allowing for a qualitative transfer of its insights to models trained via gradient descent. As an illustration, we demonstrate an efficient size reduction of the network, by pruning those attention heads that are deemed less relevant by our theory.

View on arXivView PDF

Code Implementations(1)

MIT

Official code for the paper "Dissecting the Interplay of Attention Paths in a Statistical Mechanics Theory of Transformers"

21Shell, PythonMay 23, 20242 years agoMIT

Similar Papers

Cite this paper

@article{tiberi2024dissecting,
  title  = {Dissecting the Interplay of Attention Paths in a Statistical Mechanics Theory of Transformers},
  author = {Lorenzo Tiberi and Francesca Mignacco and Kazuki Irie and Haim Sompolinsky},
  year   = {2024},
  eprint = {2405.15926},
  archivePrefix = {arXiv},
  doi    = {10.48550/arXiv.2405.15926},
  url    = {http://arxiv.org/abs/2405.15926v2},
  journal = {NEURIPS 2024 2024}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2405.15926.svg)](https://codeofpaper.com/paper/2405.15926)

Discussion