Abstract
Traditional text clustering relies on unsupervised methods and "small" embedding models, which often struggle with subjective user preferences and lack the nuanced understanding of Large Language Models (LLMs). We introduce ClusterLLM, a framework that utilizes instruction-tuned LLMs (such as ChatGPT) to guide smaller, local models. By using entropy-based triplet sampling and hierarchical pairwise comparisons, ClusterLLM aligns clustering results with specific user instructions and automatically discovers optimal granularity. Experiments across 14 datasets demonstrate that ClusterLLM significantly improves clustering quality at a minimal cost of approximately $0.60 per dataset.
Introduction
Text clustering is a fundamental task in natural language processing, yet it faces significant challenges in the modern AI landscape. First, state-of-the-art LLMs are often "black boxes" accessible only via APIs, providing no direct access to the embedding vectors required for traditional algorithms like K-Means. Second, clustering is inherently subjective; the "correct" grouping depends on whether a user prioritizes topic, sentiment, or intent. Finally, determining the appropriate number of clusters (granularity) remains a difficult unsupervised problem.
ClusterLLM addresses these issues by treating the LLM as a high-level "guide." Instead of using the LLM to process every data point—which would be prohibitively expensive—ClusterLLM uses a small, local embedder to handle the bulk of the work, querying the LLM only for the most ambiguous or critical decisions.
Methodology
The ClusterLLM framework operates in two primary stages: improving the perspective of the embedding space and determining the optimal granularity of the clusters.
1. Improving Perspective: The Triplet Task
To align a small embedder (e.g., E5 or Instructor) with a specific user perspective, ClusterLLM generates triplet questions: "Does document A better correspond to B than C?"
To maximize efficiency, the framework employs Entropy-based Triplet Sampling. Rather than querying the LLM at random, the system identifies "hard" triplets—data points where the small model is most uncertain about cluster assignment. By resolving these high-entropy ambiguities, the LLM provides the most informative feedback for fine-tuning the small embedder's vector space. This process ensures the local model learns the semantic nuances preferred by the user.
2. Determining Granularity: The Pairwise Task
Determining the number of clusters is often a manual or heuristic-driven process. ClusterLLM automates this by constructing a cluster hierarchy from the fine-tuned embeddings. It then samples pairs of documents from different levels of this hierarchy and asks the LLM: "Do A and B belong to the same category?"
The framework evaluates the consistency between the LLM’s pairwise answers and the various levels of the hierarchy. The level that demonstrates the highest consistency is selected as the final clustering result, allowing the system to adapt to different levels of abstraction (e.g., distinguishing between "Sports" in general versus specific sports like "Baseball").
Experimental Results
The researchers evaluated ClusterLLM on 14 datasets spanning intent discovery, topic mining, and emotion detection. Key findings include:
- Performance Boost: ClusterLLM consistently outperformed strong unsupervised baselines like SCCL. For instance, on the Bank77 intent discovery dataset, clustering accuracy improved from approximately 64% to over 71%.
- Cost-Efficiency: By focusing queries on high-entropy points, the framework remains remarkably affordable. The average cost to process an entire dataset was approximately $0.60 using GPT-3.5, making it a practical tool for real-world engineering.
- Instruction Following: A major advantage is the ability to guide clustering via natural language. By providing instructions to the LLM, users can shift the clustering focus (e.g., from "topic" to "domain") without manual feature engineering.
Discussion and Limitations
ClusterLLM demonstrates that LLMs can be effectively used as "teachers" for smaller models, bridging the gap between high-performance API-based models and efficient local deployment. By treating the LLM as a source of feedback rather than a primary processor, the framework overcomes the $O(N^2)$ complexity typically associated with pairwise LLM comparisons.
However, the framework has limitations. Its efficiency relies on the initial competence of the "small" embedder; if the starting model is too weak, entropy-based sampling may fail to identify useful triplets. Additionally, while the model excels at fine-grained tasks like intent discovery, performance on very coarse-grained "domain discovery" was sometimes lower than original models, suggesting that fine-tuning may occasionally make the embedding space too compact for broad categories.
Future work may explore "model-free" applications, where LLM feedback guides clustering algorithms directly, potentially removing the need for an intermediate fine-tuning step and further reducing computational overhead.
Summary updated