Transformer Circuits Can Realize Clustering Algorithms
Abstract
Lay Summary
Transformer models are the computational core of much of GenAI, and are often assumed to have "in-context learning" capabilities, being able to learn and adapt on the fly given input examples without requiring any explicit model updates. This capability is often considered critical in the general purpose utility of these models. However, it is not well understood what human-interpretable learning mechanisms (AKA algorithms) can these transformers precisely express. We show that these transformers are well equipped to express the most popular and well-studied learning algorithm for clustering. Furthermore, standard modifications commonly considered in the transformer translate to other known clustering algorithms, and in some cases, even novel algorithms. Finally, this connection between transformers and clustering algorithms allows the transformer to learn data-dependent clustering algorithms that are distinct from known ones, and provide better clustering quality. Our study provides a concrete bridge between transformers and exact algorithmic computations, allowing us to better understand what algorithms and learning mechanisms transformers can represent and learn, shedding light on their in-context learning capabilities.