Clustering in pure-attention hardmax transformers and its role in sentiment analysis

Albert Alcalde, Giovanni Fantuzzi, Enrique Zuazua
6/26/2024
cs.CLcs.LGmath.DS

No official code found. Best implementation: DCN-FAU-AvH/clustering-hardmax-transformers (1 star, CC0-1.0, last commit 2025-02-10).

Abstract

Transformers are extremely successful machine learning models whose mathematical properties remain poorly understood. Here, we rigorously characterize the behavior of transformers with hardmax self-attention and normalization sublayers as the number of layers tends to infinity. By viewing such transformers as discrete-time dynamical systems describing the evolution of points in a Euclidean space, and thanks to a geometric interpretation of the self-attention mechanism based on hyperplane separation, we show that the transformer inputs asymptotically converge to a clustered equilibrium determined by special points called leaders. We then leverage this theoretical understanding to solve sentiment analysis problems from language processing using a fully interpretable transformer model, which effectively captures `context' by clustering meaningless words around leader words carrying the most meaning. Finally, we outline remaining challenges to bridge the gap between the mathematical analysis of transformers and their real-life implementation.

View on arXivView PDF

Code Implementations(1)

CC0-1.0
10Python, Jupyter NotebookJun 13, 20241 years agoCC0-1.0

Cite this paper

@article{alcalde2024clustering,
  title  = {Clustering in pure-attention hardmax transformers and its role in sentiment analysis},
  author = {Albert Alcalde and Giovanni Fantuzzi and Enrique Zuazua},
  year   = {2024},
  eprint = {2407.01602},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2407.01602v1}
}

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/2407.01602.svg)](https://codeofpaper.com/paper/2407.01602)

Discussion