In-Context Clustering with Large Language Models

Ying Wang, Mengye Ren, Andrew Gordon Wilson
10/9/2025
cs.LG

No official code found. Best implementation: agentic-learning-ai-lab/icc (3 stars, MIT, last commit 2025-11-05).

Abstract

We propose In-Context Clustering (ICC), a flexible LLM-based procedure for clustering data from diverse distributions. Unlike traditional clustering algorithms constrained by predefined similarity measures, ICC flexibly captures complex relationships among inputs through an attention mechanism. We show that pretrained LLMs exhibit impressive zero-shot clustering capabilities on text-encoded numeric data, with attention matrices showing salient cluster patterns. Spectral clustering using attention matrices offers surprisingly competitive performance. We further enhance the clustering capabilities of LLMs on numeric and image data through fine-tuning using the Next Token Prediction (NTP) loss. Moreover, the flexibility of LLM prompting enables text-conditioned image clustering, a capability that classical clustering methods lack. Our work extends in-context learning to an unsupervised setting, showcasing the effectiveness and flexibility of LLMs for clustering. Our code is available at https://agenticlearning.ai/icc.

View on arXivView PDF

Code Implementations(1)

MIT

In-Context Clustering with Large Language Models

30Jun 3, 202511 months agoMIT

Similar Papers

Cite this paper

@article{wang2025incontext,
  title  = {In-Context Clustering with Large Language Models},
  author = {Ying Wang and Mengye Ren and Andrew Gordon Wilson},
  year   = {2025},
  eprint = {2510.08466},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2510.08466v1}
}

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

Discussion