Leaner Transformers Can Easily Learn to Cluster

Charlotte Park, Kenneth L. Clarkson, Lior Horesh, Takuya Ito, Parikshit Ram
10/7/2026
cs.LGstat.ML

No official code found. Best implementation: rithram/kmeans-trf (1 star, MIT, last commit 2026-10-07).

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_{\textsf{emb}} = d+k$ (thus, requiring attention projection matrices of size $(d+k)^2$). 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_{\textsf{emb}} = (d + \lceil \log_2 k \rceil)$. 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.

View on arXivView PDF

Code Implementations(1)

rithram/kmeans-trfCommunity69%
MIT

Code accompanying the ICML 2026 paper "Transformer Circuits Can Realize Clustering Algorithms" and the NeurIPS 2026 paper "Leaner Transformers can easily Learn to Cluster""

10May 23, 20261 weeks agoMIT

Similar Papers

Cite this paper

@article{park2026leaner,
  title  = {Leaner Transformers Can Easily Learn to Cluster},
  author = {Charlotte Park and Kenneth L. Clarkson and Lior Horesh and Takuya Ito and Parikshit Ram},
  year   = {2026},
  eprint = {2610.09760},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2610.09760v1}
}

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

Discussion