Hierarchical Text Classification Using Black Box Large Language Models

Kosuke Yoshimura, Hisashi KashimaarXiv 2025 · DOI

Abstract

Hierarchical Text Classification (HTC) involves assigning documents to labels within a structured taxonomy. Traditional approaches require specialized, heavyweight architectures and significant training data, which is often scarce at deeper levels of the hierarchy. This paper investigates the feasibility of using "black-box" Large Language Models (LLMs), specifically GPT-4o-mini, to perform HTC through zero-shot and few-shot prompting. We compare three strategies: Direct Leaf (DL), Direct Hierarchical (DH), and Top-down Multi-step (TMH). Our results demonstrate that while specialized models perform better on shallow hierarchies, LLMs using the DH strategy excel in deeper structures. However, this performance comes with increased API costs and token usage.

Introduction

Hierarchical Text Classification (HTC) is a fundamental task in natural language processing where labels are organized in a tree or directed acyclic graph. Unlike flat classification, HTC must account for the parent-child relationships between categories. Two primary challenges hinder traditional HTC: data scarcity at the granular "leaf" levels and the complexity of designing models that respect hierarchical constraints. This study explores whether off-the-shelf LLMs can bypass these issues through effective prompting.

Methodology and Prompting Strategies

The researchers evaluated three distinct prompting strategies to guide the LLM through the classification hierarchy. To handle potential hallucinations where the model might output a slightly incorrect label name, the researchers employed Levenshtein distance to map outputs back to the nearest valid label in the taxonomy.

  1. Direct Leaf Label Prediction (DL): The model is presented with a flat list of all possible leaf labels and asked to select the most appropriate one, effectively ignoring the hierarchical structure during inference.
  2. Direct Hierarchical Label Prediction (DH): The model is prompted to output the entire hierarchical path (e.g., Category > Subcategory > Label). This method forces the model to utilize the taxonomy as a roadmap for its reasoning process.
Direct Hierarchical (DH) prompting strategy.
  1. Top-down Multi-step Hierarchical Label Prediction (TMH): This is a recursive approach where the LLM makes a series of decisions. It first selects a top-level category, then, in a subsequent prompt, selects a subcategory based on the previous choice, continuing until a leaf node is reached.
Top-down Multi-step (TMH) recursive prompting strategy.

Experimental Setup

The strategies were tested on two benchmark datasets: Web of Science (WOS), featuring a shallow two-level hierarchy, and Amazon Product Reviews (APR), which contains a deeper three-level structure with over 300 leaf labels. To ensure the validity of the results, the authors used the "ChatGPT-Cheat?" tool to verify that the test data was not present in the LLM's training set. Performance was measured in both zero-shot and few-shot (up to 20 examples) settings.

Key Insights

  • Structural Advantage: The DH strategy proved most effective for deep hierarchies. By including parent labels in the output, the model better navigates large label spaces compared to the flat DL approach.
  • The Cost of Recursion: While the TMH strategy ensures high conditional accuracy (consistency between levels), it is significantly more expensive. The multiple API calls required for a single classification lead to nearly double the token consumption of simpler strategies.
  • Importance of Few-Shot Learning: Moving from zero-shot to few-shot prompting provided a substantial accuracy boost across all methods, as examples help the model understand the specific granularity and "flavor" of the target labels.

Results and Performance Comparison

On the shallow WOS dataset, the specialized HPT model outperformed LLMs (82.6% vs 71.3%). However, on the deeper APR dataset, the LLM using the DH strategy achieved 86.8% accuracy at the first level, surpassing HPT's 82.3%. This suggests that LLMs are particularly well-suited for complex taxonomies where traditional models struggle with label density at the leaf level.

Conclusion

LLMs offer a viable, training-free alternative for Hierarchical Text Classification, especially in deep taxonomies. While specialized models remain superior for simpler tasks, the reasoning capabilities of LLMs—when guided by hierarchical paths—provide a significant advantage in complex domains. Future research should explore "white-box" models to determine if fine-tuning can further optimize the balance between accuracy and operational cost.

Summary updated

BibTeX
@misc{yoshimura2025hierarchical,
  author = {Kosuke Yoshimura and Hisashi Kashima},
  title = {{Hierarchical Text Classification Using Black Box Large Language Models}},
  year = {2025},
  eprint = {2508.04219},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2508.04219},
}
Figure