Introduction
Domain Generalization (DG) is a critical frontier in text classification, requiring models to perform accurately on unseen target domains without any prior exposure to their data. Unlike Domain Adaptation (DA), which utilizes unlabeled target data during training, DG focuses on learning robust, domain-invariant features from multiple source domains. This is particularly challenging in sentiment analysis, where the semantic meaning of terms can be context-dependent—for instance, "long" is a compliment for battery life but a complaint for restaurant wait times.
Methodology: MSCL
The proposed framework, Memory-Based Supervised Contrastive Learning (MSCL), addresses these challenges by restructuring the feature space to prioritize class-level information over domain-specific noise.
Supervised Contrastive Learning (SCL)
Standard classification typically uses Cross-Entropy (CE) loss, which focuses on label accuracy. MSCL incorporates SCL to explicitly pull representations of the same class (e.g., all "positive" reviews) closer together in the vector space while pushing different classes apart. By applying this across multiple source domains, the model learns to ignore domain-specific "lingo" and focus on the shared semantic essence of the class.
Memory-Based Queue
Contrastive learning often requires massive batch sizes to provide enough negative samples for effective comparison, which is computationally expensive. MSCL introduces a memory-saving queue that stores representations from previous batches. This allows the model to contrast current samples against a much larger set of "historical" examples without requiring excessive GPU memory.
Experimental Setup
The researchers evaluated MSCL across three distinct settings:
- Multi-Domain Sentiment: Amazon reviews for Books, DVDs, Kitchen, and Electronics.
- Cross-Lingual Sentiment: Amazon reviews in English, German, French, and Japanese.
- PHEME Rumor Detection: Tweets from five breaking news events labeled as rumor or non-rumor.
The framework was tested using standard pre-trained encoders, including DistilBERT, RoBERTa-large, and XLM-R.
Key Results and Insights
MSCL consistently outperformed state-of-the-art baselines. On the Amazon sentiment benchmark, it improved RoBERTa's accuracy by 1.35%. In rumor detection, it achieved a 2.82% improvement in F1 score over the baseline. Notably, this DG method often surpassed Domain Adaptation methods that had the advantage of seeing target data.
Feature Visualization
T-SNE plots demonstrate that MSCL creates significantly tighter and more distinct class clusters compared to Mixture-of-Experts (MoE) or standard SCL.
Efficiency
The memory bank allowed the model to achieve performance equivalent to a batch size of 128 while only using the memory required for a batch size of 16. However, the authors noted a performance drop if the memory size ($M$) became too large, as older representations in the bank can become "stale" as the encoder updates.
Conclusion
MSCL provides a robust solution for domain generalization in text classification. By leveraging supervised contrastive learning and an efficient memory mechanism, it learns representations that are truly domain-invariant, enabling high performance on completely unseen data. Future work may explore more dynamic ways to refresh the memory bank or apply these techniques to other complex NLP tasks.
Summary updated