Label-template based Few-Shot Text Classification with Contrastive Learning

Guanghua Hou, Shuhui Cao, Deqiang Ouyang, Ning WangarXiv 2024 · DOI

Abstract

Few-Shot Text Classification (FSTC) aims to categorize documents using only a handful of labeled examples. Traditional meta-learning approaches often ignore the semantic information inherent in class labels and are sensitive to noisy support samples. This paper introduces a novel framework that maximizes label utility by embedding them into natural language templates. By combining these "label-aware" inputs with supervised contrastive learning and an attention-weighted prototypical network, the proposed method achieves state-of-the-art results and significantly faster training convergence compared to existing baselines.

Introduction

Standard Prototypical Networks for FSTC suffer from three primary flaws: the waste of label semantics (treating labels as arbitrary IDs), the "averaging trap" (creating prototypes by simple averaging, which is sensitive to outliers), and weak discriminative power between similar categories. This research addresses these issues by treating labels as features rather than just targets and by employing dynamic, query-aware prototype construction.

Proposed Framework

The authors propose a three-pronged strategy to enhance the standard meta-learning pipeline, integrated into a multi-task learning objective.

Overview of the proposed few-shot text classification framework featuring label templates, attention-based prototypes, and contrastive learning.

1. Label-Template Embedding

Instead of feeding raw text into the BERT encoder, the model wraps class labels in a natural language prompt: "Overall, the topic of the text is [Label]." This templated text is concatenated with the input sentence. This approach leverages the pre-trained model's existing linguistic knowledge to "prime" the encoder on what features to prioritize for a specific category.

2. Attention-based Prototypical Network

To avoid the pitfalls of simple averaging, the model uses an instance-level attention mechanism. When calculating a class prototype, the system assigns higher weights to support samples that are more relevant to the current query. This creates a "contextual prototype" that effectively filters out noise and outliers tailored to the specific classification task at hand.

3. Supervised Contrastive Learning (SCL)

To improve discriminative power, the model employs SCL to explicitly pull representations of the same class closer together while pushing different classes further apart in the embedding space. This acts as a powerful regularizer, helping the model capture subtle differences between similar categories even with minimal data.

Experimental Evaluation

The framework was evaluated on four benchmarks: 20News, Amazon reviews, HuffPost headlines, and Reuters articles.

Key Results

  • State-of-the-Art Performance: The model outperformed strong baselines like MAML and ContrastNet. It showed particular strength in 1-shot settings, with an average accuracy improvement of 4.7% and a 7.5% jump on the challenging HuffPost dataset.
  • Efficiency: The combination of contrastive and classification loss led to significantly faster training, with the model converging 2.62x faster than leading baselines.
  • Clustering Quality: Qualitative t-SNE visualizations confirmed that the method produces tighter, more distinct clusters in the embedding space compared to traditional prototypical networks.

Conclusion and Future Work

By integrating label semantics and attention-weighted prototypes, this framework significantly advances the state of FSTC. While the model showed some sensitivity to the unique structure of the Reuters dataset in 5-shot settings, its overall performance and convergence speed make it a robust choice for low-resource text classification. Future work will focus on expanding this label-template approach to a broader range of few-shot natural language processing tasks.

Summary updated

BibTeX
@misc{hou2024label,
  author = {Guanghua Hou and Shuhui Cao and Deqiang Ouyang and Ning Wang},
  title = {{Label-template based Few-Shot Text Classification with Contrastive Learning}},
  year = {2024},
  eprint = {2412.10110},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2412.10110},
}
Figure