Many-Class Text Classification with Matching

Yi Song, Yuxian Gu, Minlie HuangarXiv 2022 · DOI

TL;DR

Researchers from Tsinghua University have introduced TCM (Text Classification as Matching), a framework that treats text classification as a semantic matching problem rather than a simple label prediction task. By using a Siamese Network to match input text against descriptive natural language labels, TCM significantly outperforms traditional methods in "many-class" scenarios (20+ labels), especially when training data is extremely scarce.

What Problem Does This Paper Address?

Standard text classification usually follows one of two paths:

  1. Task-Head: Adding a linear layer on top of a Pre-trained Language Model (PLM) to predict a class ID. This treats labels as arbitrary numbers, ignoring the rich semantic information they contain.
  2. Prompt-based: Inserting a "cloze" template (e.g., "The topic is [MASK]") and letting the model predict a word. While this uses some semantics, it is limited by the number of mask positions and typically struggles when the number of classes grows beyond ten.

In "many-class" classification (where you might have 30, 80, or even hundreds of categories), the boundaries between classes become subtle and vague. Traditional models struggle to distinguish between these categories without massive amounts of labeled data.

Methods

The authors propose TCM, which reformulates classification as a matching task between the input text and a set of label descriptions.

Comparison of traditional classification methods (Task-head and Prompt-based) with the proposed TCM framework.
  • Siamese Network Architecture: TCM uses two parameter-shared encoders (like BERT or RoBERTa). One encoder processes the input text, and the other processes the "mapped label"—a natural language sentence describing the class.
  • Label Mapping: Instead of just using a class ID, they represent labels in three ways: Class Names, Class Definitions (e.g., "Someone is originated from somewhere"), or Same-Class Samples.
  • Matching Loss & Regularization: The model is trained to maximize similarity between text and its correct label description. A crucial regularization term pushes embeddings of different classes away from each other to improve discriminative power.
  • Efficiency: During inference, label embeddings can be pre-computed, ensuring computational overhead remains similar to standard classification.

Key Insights and Ideas

  • Semantics are a "Warm Start": Providing the model with a definition of the class acts as a powerful prior. Even before seeing training data, the model has a semantic "anchor" for what each class represents.
  • Shared Encoders Win: The authors found that using a single shared encoder (Siamese) for both text and labels performed better than using two separate encoders. This forces the model to map both inputs into the same semantic space.
Performance comparison between Siamese (shared) and two-encoder architectures across different training sample sizes.
  • Stability in the Face of Scarcity: Few-shot learning is notoriously unstable. TCM showed a much lower standard deviation than baselines, suggesting that explicit label semantics make the training process more robust.
  • The "Push" Factor: Without the regularization term, the model often maps different labels to very similar embedding spaces. The regularization term is essential for carving out distinct territories for each class.

Key Results

TCM demonstrated significant improvements across the board on datasets like FewRel, TACRED, and GoEmotions:

  • Few-Shot Dominance: In the 5-shot setting on the FewRel dataset, TCM achieved an F1 score of 59.4, compared to 47.8 for the standard Task-Head approach.
  • Emotion Classification: On GoEmotions (5-shot), TCM reached 29.2 F1, nearly doubling the Task-Head's 12.7.
  • Scaling: While the gap narrows as more data is added, TCM remains competitive or superior even in full-data settings.

Limitations and Future Work

While TCM handles dozens of classes well, performance is sensitive to the quality of label descriptions. Future work could explore automatically generating or optimizing these descriptions to reduce manual effort and scaling the approach to "extreme" classification with thousands of labels.

Summary updated

BibTeX
@misc{song2022many,
  author = {Yi Song and Yuxian Gu and Minlie Huang},
  title = {{Many-Class Text Classification with Matching}},
  year = {2022},
  eprint = {2205.11409},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2205.11409},
}
Figure