Clustering in pure-attention hardmax transformers and its role in sentiment analysis
Albert Alcalde, Giovanni Fantuzzi, Enrique Zuazua
TL;DR
This work analyzes pure-attention hardmax transformers as discrete-time dynamical systems to explain how deep transformers develop context. It proves that inputs converge to a clustered equilibrium organized by a finite set of leaders that correspond to vertices of a limiting convex polytope, with nonleader tokens clustering near leaders via a hyperplane based geometry. The authors then build an interpretable sentiment analysis model that leverages leader words to filter context, demonstrating that clustering around leaders captures meaning and informs predictions. The results offer a rigorous mechanism for context formation in transformers and outline key open challenges for extending the theory to more general parameterizations and architectures.
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.
