TopicGPT: A Prompt-based Topic Modeling Framework

Chau Minh Pham, Alexander Miserlis Hoyle, Simeng Sun, Mohit IyyerarXiv 2023 · DOI

Introduction

Topic modeling is a fundamental technique in natural language processing used to discover latent themes within large text corpora. For decades, Latent Dirichlet Allocation (LDA) has been the standard approach. However, LDA and its variants often produce "bags of words" that require significant human effort to interpret. Furthermore, these models lack fine-grained control and fail to provide explicit evidence for their assignments.

TopicGPT is a novel framework designed to address these limitations by leveraging the reasoning and natural language generation capabilities of Large Language Models (LLMs). By moving from cryptic word lists to human-readable labels and descriptions, TopicGPT enhances the interpretability and validity of topic discovery.

Methodology

The TopicGPT framework consists of two primary stages: Topic Generation and Topic Assignment.

1. Topic Generation

Unlike traditional models that process an entire corpus simultaneously, TopicGPT employs an iterative prompting strategy. An LLM (typically GPT-4) is provided with a small sample of documents and a few "seed" example topics to guide the desired granularity. The model identifies new topics, generating a concise label and a one-sentence description for each.

To ensure the quality and uniqueness of the generated topics, the framework includes a refinement step. Similar topic pairs are identified using Sentence-Transformer embeddings and merged by the LLM. Additionally, infrequent topics that do not appear consistently across document samples are pruned to maintain a coherent list.

The TopicGPT framework overview, illustrating the iterative generation and refinement of topics followed by document assignment.

2. Topic Assignment

In the second stage, a separate LLM (such as GPT-3.5-turbo) assigns documents to the refined list of topics. A key innovation in this stage is the "Evidence" feature: the model is required to provide a direct quote from the document to justify each assignment. This makes the model's output verifiable and reduces the risk of "black box" reasoning. The framework also incorporates a self-correction loop to handle formatting errors or the hallucination of topics outside the predefined list.

Experimental Setup

The authors evaluated TopicGPT on two large-scale English datasets with established human-annotated hierarchies:

  • Wiki: Approximately 14,000 Wikipedia articles categorized into a three-level hierarchy (15 high-level, 45 mid-level, and 279 low-level labels).
  • Bills: Approximately 32,000 U.S. Congressional bill summaries with a two-level label system (21 high-level and 114 low-level).

Performance was measured using metrics such as harmonic mean purity ($P_1$), Adjusted Rand Index (ARI), and Normalized Mutual Information (NMI).

Results

TopicGPT consistently outperformed traditional baselines, including LDA, BERTopic, and SeededLDA, across both datasets.

Quantitative performance comparison of TopicGPT against baselines. TopicGPT shows superior alignment with human-annotated categories across multiple metrics.

Key findings include:

  • Superior Alignment: On the Wiki dataset, TopicGPT achieved a $P_1$ score of 0.74, significantly higher than LDA's 0.64.
  • Human-Centric Quality: Manual evaluations revealed that TopicGPT's refined topics had a much lower misalignment rate (30.3%) compared to LDA (62.4%), which often suffered from out-of-scope or repeated topics.
  • Efficiency in Discovery: The framework demonstrates that a representative set of topics can be discovered from a relatively small subset of the corpus (600–1,000 documents), making the approach computationally feasible despite the use of expensive LLMs.

Discussion and Limitations

While TopicGPT offers significant improvements in interpretability and accuracy, several challenges remain. The primary drawback is the cost associated with proprietary LLM APIs; processing the Wiki dataset cost roughly $155. Additionally, the context window limits of current models necessitate document truncation, which may overlook niche topics in longer texts. Future work will focus on extending the framework to multilingual contexts and exploring the use of open-source models for the generation phase, which currently remains a challenge for smaller models.

Summary updated

BibTeX
@misc{pham2023topicgpt,
  author = {Chau Minh Pham and Alexander Miserlis Hoyle and Simeng Sun and Mohit Iyyer},
  title = {{TopicGPT: A Prompt-based Topic Modeling Framework}},
  year = {2023},
  eprint = {2311.01449},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2311.01449},
}
Figure