Abstract
Text clustering is a fundamental NLP task often hindered by the subjectivity of cluster definitions and the difficulty of determining optimal granularity. While Large Language Models (LLMs) offer advanced semantic reasoning, their "black-box" nature via APIs often precludes direct access to the embeddings required for traditional clustering. We present ClusterLLM, a framework that leverages LLMs as "oracles" to guide smaller, local embedding models. By querying LLMs for triplet preferences and pairwise relationships, ClusterLLM aligns clusters with specific user perspectives and automatically discovers optimal granularity. Experimental results across 14 datasets demonstrate significant performance improvements at a minimal cost of approximately $0.60 per dataset.
Introduction
Traditional text clustering typically relies on "small" local embedders (e.g., BERT, RoBERTa) to map text into a vector space for algorithms like K-means. However, this approach faces two primary challenges. First, state-of-the-art LLMs like GPT-4, which possess superior understanding, are often restricted behind APIs that do not provide internal vector representations. Second, clustering is inherently subjective; the "correct" grouping depends on user intent (e.g., clustering by topic vs. sentiment) and the desired level of granularity.
ClusterLLM bridges this gap by treating the LLM not as a vector engine, but as a reasoning guide that "warps" the embedding space of a smaller model to better reflect semantic nuances and user instructions.
Methods
The ClusterLLM framework operates in two distinct stages to refine the embedding space and determine the final cluster structure.
Stage 1: Improving Perspective
To align the embedding space with a specific perspective, ClusterLLM queries the LLM for triplet preferences. Given three instances (A, B, C), the LLM is asked: "Does instance A better correspond to B than C?" * Entropy-based Triplet Sampling: To minimize API costs, the system uses the local embedder to identify "ambiguous" points—those with high entropy where the model is uncertain of cluster membership. Querying the LLM on these "hard" cases provides the most informative signal for fine-tuning. * Instruction-Tuning: User-provided instructions (e.g., "cluster by intent") are included in the LLM prompts, ensuring the resulting clusters meet specific requirements.
Stage 2: Determining Granularity
Finding the optimal number of clusters ($K$) is a classic unsupervised challenge. ClusterLLM addresses this by navigating a hierarchical clustering tree using pairwise queries.
- Consistency Measure: The LLM is asked whether pairs of points belong to the same category. By comparing these "Yes/No" answers to different levels of the hierarchical tree, the framework identifies the "cut" that is most consistent with the LLM's judgment.
Experimental Setup
The authors evaluated ClusterLLM on 14 diverse datasets covering five task categories:
- Intent Discovery: Bank77, CLINC(I), MTOP(I), Massive(I)
- Type Discovery: FewRel, FewNerd, FewEvent
- Topic Mining: StackEx, ArxivS2S, Reddit
- Emotion Detection: GoEmo
- Domain Discovery: CLINC(D), MTOP(D), Massive(D)
Key Results and Insights
ClusterLLM consistently outperforms strong baselines, including standalone small embedders (Instructor, E5) and deep clustering methods like SCCL.
- Performance Gains: On the Bank77 dataset, clustering accuracy improved from 59.90% to 70.13%.
- Cost Efficiency: Using the
gpt-3.5-turboAPI, the average cost per dataset was only $0.60 ($0.20 for perspective tuning and $0.40 for granularity discovery). - The Power of Reasoning: The results confirm that an LLM's comparative reasoning is a sufficient substitute for direct embedding access. By focusing on "hard negatives" via entropy sampling, the framework achieves high performance with only ~1,000 queries.
Conclusion
ClusterLLM demonstrates a cost-effective way to distill the reasoning power of massive, black-box LLMs into smaller, specialized embedding models for clustering. While the method's effectiveness is somewhat tied to the quality of the initial local embedder, it provides a robust path forward for subjective and fine-grained text analysis. Future research will explore reducing the dependency on initial pre-trained models to further generalize the framework.
Summary updated