Leaner Transformers Can Easily Learn to Cluster
cs.LG, stat.ML
Submitted: 2026-10-07
Updated: 2026-10-16
Comments: NeurIPS 2026 accepted paper
Code: https://github.com/rithram/kmeans-trf
License: http://creativecommons.org/licenses/by/4.0/
The gist: Transformers have in-context learning capabilities, where some known learning algorithms can be executed in the forward pass through the model.
Terminology
Abstract
Transformers have in-context learning capabilities, where some known learning algorithms can be executed in the forward pass through the model. Recent work shows that transformers can exactly perform Lloyd's algorithm for k-means clustering with n points in d dimensions with an embedding size d = d+k (thus, requiring attention projection matrices of size (d+k) squared). In this work, we build upon this result in the following ways: First, we present an equally expressive but smaller transformer that executes Lloyd's algorithm with embedding size d = (d + 2 k). Next, we train these transformers to learn the clustering algorithms given a distribution of clustering tasks, and theoretically characterize and empirically validate the factors affecting the convergence and in-distribution generalization of learning algorithms based on stochastic gradients. Finally, we probe the general clustering abilities of these learned algorithms (in the form of transformers), and try to understand situations where they succeed and fail.
Sources
- Formal Algorithms for Transformers
- Neural Turing Machines
- In-Context Convergence of Transformers
- Trained Transformers Learn Linear Models In-Context
- Train faster, generalize better: Stability of stochastic gradient descent
- The emergence of clusters in self-attention dynamics
- A mathematical perspective on Transformers
- Projection onto the probability simplex: An efficient algorithm with a simple proof, and an application
Related papers
- Polynomial-Augmented Neural Networks (PANNs) with Weak Orthogonality Constraints for Enhanced Function and PDE Approximation
- AIRL-S: Unifying Reinforcement Learning and Search-Based Test-Time Scaling via Adversarial Inverse Reinforcement Learning
- Transformers as Bayesian In-Context Experimenters: Smoothness-Adaptive Efficient ATE Estimation
- Convergence issues in Relational Concept Analysis based on AOC-posets
- Beliefs Beyond Posteriors: The Predictive Cost of ELBO Binding
- Understanding Diffusion Models via Ratio-Based Function Approximation with SignReLU Networks