HPT: Hierarchy-aware Prompt Tuning for Hierarchical Text Classification

Zihan Wang, Peiyi Wang, Tianyu Liu, Binghuai Lin, Yunbo Cao, Zhifang Sui, Houfeng Wang

Abstract

Hierarchical Text Classification (HTC) is a complex task where documents must be assigned to multiple labels organized in structured hierarchies, such as trees or directed acyclic graphs. While Pretrained Language Models (PLMs) like BERT have become the standard for text classification, they suffer from a fundamental mismatch between their "flat" pretraining objectives and the structured nature of HTC. This paper introduces Hierarchy-aware Prompt Tuning (HPT), a novel framework that bridges this gap. By injecting structural hierarchy information directly into "soft prompts" and utilizing a specialized zero-bounded multi-label loss, HPT achieves state-of-the-art performance, particularly in data-scarce and highly imbalanced scenarios.

Introduction

In Hierarchical Text Classification, labels are not independent; they follow a parent-child relationship (e.g., Sports $\rightarrow$ Hockey $\rightarrow$ NHL). Standard fine-tuning of PLMs often fails to capture this structure due to two primary gaps:

  1. The Hierarchy and Flat Gap: PLMs are typically pretrained on tasks like Masked Language Modeling (MLM), which are inherently flat. They lack an intrinsic understanding of sophisticated label dependencies.
  2. The Multi-label and Multi-class Gap: MLM is a multi-class task (selecting the single most likely word), whereas HTC is a multi-label task (identifying all relevant paths in a hierarchy). Standard Binary Cross Entropy used in fine-tuning often ignores the correlations between these labels.

While prompt tuning has emerged as a powerful alternative to fine-tuning, adapting it to hierarchical structures requires a method to represent the hierarchy within the prompt itself.

Methodology

HPT transforms the HTC task into a hierarchy-aware multi-label MLM problem through three core innovations:

1. Hierarchy-aware Prompts

Instead of using a static text template, HPT employs a dynamic virtual template: [V1] [PRED] [V2] [PRED] ... [VL] [PRED]. Here, each [Vi] represents a virtual template word corresponding to a specific level of the hierarchy, and [PRED] is a special token used for label prediction at that level. This structure guides the PLM to process the document in a layer-wise fashion.

2. Hierarchy Injection via GAT

To ensure the model understands the relationships between labels, the authors utilize a Graph Attention Network (GAT). The GAT processes the entire label hierarchy, and its output is used to initialize and update the embeddings of the virtual template words. This effectively "injects" the structural knowledge of the hierarchy directly into the prompt space, allowing the model to leverage structural priors during inference without adding extra parameters to the final inference stage.

3. Zero-bounded Multi-label Cross Entropy (ZMLCE) Loss

To reconcile the multi-label nature of HTC with the competitive nature of MLM, HPT introduces the ZMLCE loss. This objective includes an "anchor" label with a constant score of zero. The model is forced to push scores for correct labels above this zero threshold and incorrect labels below it. This mechanism mimics the ranking behavior of MLM while allowing for multiple valid predictions.

Experimental Evaluation

The framework was evaluated on three major HTC benchmarks:

  • Web-of-Science (WOS): 141 labels, depth of 2.
  • RCV1-V2: 103 labels, depth of 4.
  • NYTimes (NYT): 166 labels, depth of 8.

Key Results

  • State-of-the-Art Performance: HPT consistently outperformed previous specialized models, including HiMatch and HGCLR, across all datasets.
  • Scaling with Complexity: The performance advantage of HPT became more pronounced as the hierarchy depth increased. The most significant improvements were observed on the NYT dataset, which features the deepest hierarchy.
  • Low-Resource Robustness: In experiments using only 10% of the training data, HPT demonstrated remarkable resilience. On the RCV1-V2 dataset, HPT outperformed the next best model by over 6 points in Macro-F1 under these low-resource conditions.
  • Semantic Interpretability: Analysis of the learned virtual label words revealed that they captured semantically relevant features. For instance, the virtual word for "NHL" was found to be close in vector space to terms like "hockey" and "football."

Discussion and Insights

The success of HPT suggests that prompting can serve as a structural bridge between flat PLMs and complex downstream tasks. By moving the hierarchy representation into the input space (via prompt embeddings) rather than relying on complex external encoders, HPT maintains efficiency while improving accuracy. Furthermore, the sharing of hierarchy information through the GAT allows labels with very few training examples to "borrow" features from more frequent parent or sibling nodes, effectively addressing the long-tail distribution problem common in hierarchical data.

Conclusion

HPT provides a robust framework for hierarchical text classification by aligning the task with the pretraining logic of language models. While currently optimized for MLM-based backbones like BERT, future work may explore adaptations for causal or encoder-decoder architectures and investigate its application to other structured tasks such as relation extraction.

Summary updated

BibTeX
@inproceedings{wang2022hpt,
  author = {Zihan Wang and Peiyi Wang and Tianyu Liu and Binghuai Lin and Yunbo Cao and Zhifang Sui and Houfeng Wang},
  title = {{HPT: Hierarchy-aware Prompt Tuning for Hierarchical Text Classification}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2022},
  doi = {10.18653/v1/2022.emnlp-main.246},
}
Figure