Prompt-based Distribution Alignment for Domain Generalization in Text Classification

Chen Jia, Yue Zhang

Abstract

Domain Generalization (DG) remains a significant challenge in text classification, where models must perform on unseen target domains without prior exposure. This paper introduces a framework that combines prompt-based learning with two novel alignment strategies: Vocabulary Distribution Alignment (VDA) and Feature Distribution Alignment (FDA). VDA ensures consistent vocabulary usage across domains via KL-divergence, while FDA employs label-aware adversarial training to learn domain-invariant hidden representations. Our approach achieves state-of-the-art performance across six major datasets, effectively bridging the gap between disparate source domains.

Introduction

Machine learning models often suffer from performance degradation when encountering "domain shift." For instance, a sentiment classifier trained on book reviews might fail on movie reviews due to differences in descriptive language (e.g., "well-written" vs. "cinematic"). While Domain Adaptation utilizes unlabeled target data, Domain Generalization (DG) aims for zero-shot transfer to new domains. While prompt-based learning offers a unified task format, it does not inherently resolve underlying distribution discrepancies. Different domains maintain unique "feature signatures" and word preferences that can lead to overfitting on source-specific patterns.

Proposed Methodology

The proposed framework aligns source domains during the prompting process using two regularization losses designed to extract domain-invariant features:

  1. Vocabulary Distribution Alignment (VDA): Even when domains share the same label words (e.g., "good", "bad"), a model's internal prediction over its entire vocabulary varies by domain. VDA utilizes Kullback-Leibler (KL) divergence to minimize these differences for the same category across source domains. This encourages the model to leverage broader, domain-invariant semantic cues stored in the Pretrained Language Model's (PLM) vocabulary.
  2. Feature Distribution Alignment (FDA): This strategy employs a label-aware adversarial training strategy. The model learns hidden representations at the [MASK] token that are generic enough to deceive a domain discriminator. Crucially, this alignment is performed per-category (e.g., aligning all "positive" instances) to ensure the model ignores the domain while retaining the sentiment signal.
Overview of the proposed framework showing Vocabulary Distribution Alignment (VDA) and Feature Distribution Alignment (FDA) in the feature space.

Experimental Setup

The researchers evaluated their method on two primary tasks across six major datasets:

  • Sentiment Analysis: Amazon Reviews (Books, DVD, Electronics, Kitchen), IMDB, and SST-2.
  • Natural Language Inference (NLI): MNLI (Fiction, Government, Slate, Telephone, Travel), SNLI, and SICK.

Testing included both leave-one-domain-out and cross-dataset settings to rigorously assess generalization capabilities to completely unseen data distributions.

Key Results and Discussion

The proposed method achieved state-of-the-art results across all six datasets, outperforming strong baselines like Deep CORAL and IRM. In cross-dataset evaluations, the method showed impressive robustness, improving macro-F1 scores by over 5% on the SICK dataset and 3.5% on SST-2 compared to standard prompting.

A critical finding was the reduction in "A-distance," a metric for domain discrepancy. As shown in the experimental analysis, the combination of VDA and FDA significantly shrinks the gap between feature distributions across various source domains, confirming that the model is indeed learning domain-invariant representations.

Heatmap showing the reduction in A-distance across source domains when applying VDA and FDA compared to standard fine-tuning and prompting.

Conclusion and Future Work

By unifying domains through prompting and enforcing distribution alignment at both the vocabulary and feature levels, this framework provides a robust solution for text classification DG. The results demonstrate that label-aware alignment is essential for maintaining classification accuracy while achieving domain invariance. Future work will address the computational complexity of the FDA component—which currently scales quadratically with the number of domains—and explore applications in more complex NLP tasks like sequence labeling or generation.

Summary updated

BibTeX
@inproceedings{jia2022prompt,
  author = {Chen Jia and Yue Zhang},
  title = {{Prompt-based Distribution Alignment for Domain Generalization in Text Classification}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2022},
  doi = {10.18653/v1/2022.emnlp-main.690},
}
Figure