# Leaner transformers can easily learn to cluster

*Charlotte Park, Kenneth Clarkson, Lior Horesh, Takuya Ito, Parikshit Ram*

[NeurIPS page](https://neurips.cc/virtual/2026/poster/151648) · [Open on the map](../papers.html#p151648)

Category: [Interpretability & Model Adaptation](../pcat/15.md) › [Transformer In-Context Reasoning](../pgroup/370.md) · Type: new method · Keywords: transformer clustering, in-context learning, Lloyd's algorithm, parameter efficiency, convergence analysis

## Summary
The paper introduces a leaner transformer that can learn to perform Lloyd's algorithm for k-means clustering using only O(d + log k) embedding size, and provides theoretical and empirical analysis of its learning dynamics and generalization.

## Explained to a 5-year-old
Computers can sometimes think inside their own heads and solve problems without being told how. The researchers made a smaller computer brain that can learn to group things into clusters. They made it so the brain only needs a tiny amount of memory to remember how many groups there are. They taught the brain many examples of grouping and watched it get better at it. This helps computers do grouping tasks faster and use less memory.

## Explained to a 5-year-old, longer
A computer can sometimes think inside its own head and solve problems without being told how. The researchers wanted to make a computer that could learn to group things, like putting similar toys together. They built a smaller version of such a computer brain that needs less memory. Instead of remembering a lot of numbers for each group, it only needs a few extra numbers based on how many groups there are. They taught the brain many examples of how to group different sets of items. The brain learned by trying to improve its grouping, just like a child practicing sorting. They also studied why the brain sometimes gets stuck or makes mistakes. The study shows that a tiny computer brain can do complex grouping tasks. This could help future computers be more efficient and use less energy. It also helps scientists understand how computers can learn on their own. The new idea could be used in many areas where grouping data is useful. Overall, the work makes learning computers simpler and more powerful.

## For a technical reader
The paper presents a more compact transformer architecture that can learn to implement Lloyd's algorithm for k-means clustering using only O(d + log k) embedding dimensions. By training on a distribution of clustering tasks, the model acquires the ability to perform in-context clustering without explicit fine-tuning. The authors provide a theoretical analysis of the convergence behavior of stochastic gradient training for this setup and empirically validate the identified factors. Experiments probe the model's generalization to unseen clustering scenarios and highlight conditions where it succeeds or fails. The work demonstrates that transformer-based algorithms can be both parameter-efficient and capable of learning complex iterative procedures.

## Problem
Existing transformer-based in-context learning for clustering requires embedding dimensions that grow with the number of clusters, leading to high memory and compute costs. There is a need for more parameter-efficient models that can capture clustering logic with smaller representations.

## Method
The authors construct a transformer architecture that can simulate Lloyd's algorithm using an embedding size of d + ⌈log₂ k⌉, train it on a distribution of clustering tasks with stochastic gradient descent, and analyze factors influencing convergence and generalization.

## Contributions
A more parameter-efficient transformer that learns Lloyd's algorithm with O(d + log k) embeddings, a theoretical analysis of convergence and generalization for stochastic gradient learning of such transformers, and empirical studies of their clustering performance and failure modes.

This page was written by language models from the title and abstract of each paper, and the answers were checked by two other models. It can be wrong: check the paper itself. [Suggest a correction](../feedback/?on=p/151648)
