NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Simple Contrastive Representation Adversarial Learning for NLP Tasks

Deshui Miao, Jiaqi Zhang, Wenbo Xie, Jian Song, Xin Li, Lijuan Jia, Ning GuoarXiv 2021

TL;DR

This paper introduces SCAL and USCAL, novel frameworks that combine contrastive learning with adversarial training to generate more robust and effective sentence representations for NLP tasks. By using adversarial attacks to create challenging "positive pairs" in contrastive learning, they significantly improve performance on NLU benchmarks and achieve state-of-the-art robustness against adversarial attacks.

What Problem Does This Paper Address?

Contrastive learning has shown great promise in NLP for learning powerful sentence representations by training models to distinguish between similar (positive) and dissimilar (negative) sentence pairs. However, a major hurdle in NLP is generating effective positive pairs. Unlike in computer vision where image transformations (like rotation or cropping) can create semantically similar but distinct views of an image, simple text augmentations (like word deletion or back-translation) can easily alter the original meaning due to language's discrete nature. This makes it difficult to create challenging positive pairs that truly push the model's representational boundaries. Existing methods often struggle with this, leading to suboptimal performance or requiring complex augmentation strategies.

Methods

The core innovation lies in using adversarial training to generate these challenging positive pairs for contrastive learning. Instead of relying on simple data augmentations, they employ adversarial attacks to create perturbed versions of input sentences. These adversarial examples are then treated as positive pairs alongside the original sentences.

Two frameworks are proposed:

  • Supervised Contrastive Adversarial Learning (SCAL): For supervised tasks, SCAL combines the standard cross-entropy loss for classification with a contrastive loss. The adversarial examples are generated by perturbing word embeddings based on the gradient of the cross-entropy loss. This approach aims to improve both classification accuracy and model robustness.
  • Unsupervised Contrastive Adversarial Learning (USCAL): For unsupervised sentence representation learning, USCAL leverages dropout as a primary method to create initial positive pairs. Crucially, it then uses adversarial attacks (based on the contrastive loss itself) to generate even more challenging positive pairs. This framework is designed to produce better sentence embeddings without relying on labeled data.

Both frameworks share weights across their encoders and fully connected layers, and at the end of training, the output of the encoder is used as the sentence representation.

Datasets

The paper evaluates their methods on a variety of NLP tasks and datasets:

  • GLUE Benchmark: A standard suite of natural language understanding tasks, including MRPC (paraphrase), QQP (paraphrase), RTE (textual entailment), ONLI (question answering/textual entailment), MNLI (textual entailment), SST-2 (sentiment analysis), and COLA (grammatical correctness).
  • Short-text Classification: AG's News (topic classification) and TREC (question classification).
  • Semantic Textual Similarity (STS): STS 2012-2016, STS benchmark (STS-B), and SICK-Relatedness dataset.
  • Robustness Evaluation: ANLI (Adversarial Natural Language Inference) dataset, which is specifically designed to challenge NLP models.

Key Insights and Ideas

  • Adversarial Examples as "Hard" Positive Pairs: The most significant insight is treating adversarially generated examples as positive pairs in contrastive learning. This forces the model to learn representations that are invariant to subtle, meaning-preserving perturbations, leading to more robust and discriminative embeddings.
  • Synergy Between Contrastive Learning and Adversarial Training: The paper demonstrates a powerful synergy. Contrastive learning helps improve the generalization of adversarial training by regularizing the embedding space, while adversarial training enhances the robustness and learning difficulty for contrastive learning.
  • Embedding-Level Perturbations for NLP: Unlike some prior work that focused on word-level perturbations, this paper applies adversarial attacks directly to word embeddings. This is a more nuanced approach for NLP, allowing for more controlled and effective generation of adversarial examples.
  • Unified Framework for Supervised and Unsupervised Learning: The development of both SCAL and USCAL shows the versatility of their approach, addressing representation learning needs across both labeled and unlabeled scenarios.

Key Results

  • Supervised Performance: On the GLUE benchmark, SCAL fine-tuned on BERT${base}$ outperformed the original BERT${base}$ by 1.75% on average.
  • Unsupervised Performance: For semantic textual similarity (STS) tasks, USCAL achieved 77.29% with BERT${base}$, a significant improvement over BERT${base}$ (66.58%) and even surpassing SimCSE (75.54%).
  • Robustness: The proposed methods achieved state-of-the-art results on the ANLI dataset, demonstrating superior robustness against adversarial attacks on NLI tasks compared to existing methods like FreeLB and InfoBERT. For instance, SCAL achieved 32.4% accuracy on the ANLI test dataset, outperforming InfoBERT's 28.2% when trained on MNLI+SNLI.

Limitations and Future Work

  • Computational Cost: Adversarial training and contrastive learning can be computationally intensive, requiring significant resources for training.
  • Hyperparameter Sensitivity: The effectiveness of the approach might depend on careful tuning of hyperparameters, such as the perturbation magnitude ($\epsilon$) and the weighting factor ($\alpha$) for the contrastive loss.
  • Future Directions: The authors suggest that this approach opens new avenues for reconsidering data augmentation strategies in contrastive learning for NLP. They believe their work could inspire further research into creating more effective and robust models.

Summary updated

BibTeX
@misc{miao2021simple,
  author = {Deshui Miao and Jiaqi Zhang and Wenbo Xie and Jian Song and Xin Li and Lijuan Jia and Ning Guo},
  title = {{Simple Contrastive Representation Adversarial Learning for NLP Tasks}},
  year = {2021},
  eprint = {2111.13301},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2111.13301},
}
Figure