In-Context Clustering with Large Language Models
Authors:
Preprint
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.Keywords
All Related Versions
This publication has 8 references indexed in Scilit:
- Multimodal Generalized Category Discovery2025
- LLM as Dataset Analyst: Subpopulation Structure Discovery with Large Language Model2024
- Large Language Models Enable Few-Shot ClusteringTransactions of the Association for Computational Linguistics, 2024
- Lost in the Middle: How Language Models Use Long ContextsTransactions of the Association for Computational Linguistics, 2024
- Using LLM for Improving Key Event Discovery: Temporal-Guided News Stream Clustering with Event Summaries2023
- MetaICL: Learning to Learn In Context2022
- Document Clustering: A Detailed ReviewInternational Journal of Applied Information Systems, 2012
- Algorithms for hierarchical clustering: an overviewWIREs Data Mining and Knowledge Discovery, 2011