SCAT: Robust Self-supervised Contrastive Learning via Adversarial Training for Text Classification

Junjie Wu, Dit-Yan YeungarXiv 2023 · DOI

Abstract

Natural language processing (NLP) models are highly susceptible to adversarial text attacks. While adversarial training is a potent defense, it typically requires labeled data, limiting its application during large-scale unlabeled pre-training. This paper presents SCAT (Self-supervised Contrastive Learning via Adversarial Training), a label-free framework that integrates contrastive learning with adversarial training. SCAT identifies critical words using contrastive loss gradients and generates adversarial examples to enhance model robustness from scratch or through fine-tuning. Experiments on AG's News and DBPedia datasets demonstrate that SCAT significantly improves robustness against state-of-the-art attackers like TextFooler and BERT-Attack with minimal impact on clean accuracy.

Introduction

Pre-trained language models (PLMs) like BERT have revolutionized NLP but remain notoriously brittle. Attackers can easily deceive these models by swapping a few words with synonyms or introducing minor typos—perturbations known as adversarial attacks. The standard defense, adversarial training (AT), involves generating attacked examples and incorporating them into the training process. However, traditional AT requires ground-truth labels to verify if an attack successfully flipped a prediction. This requirement makes it unsuitable for the massive, unlabeled pre-training phase. SCAT overcomes this limitation by proposing a fully label-free framework that combines self-supervised contrastive learning with adversarial training.

Methods

The SCAT framework operates by pulling the representations of an original sentence and its adversarially perturbed version closer together in the embedding space without requiring labels.

The SCAT framework pipeline, showing the generation of label-free adversarial examples and the contrastive objective.

The pipeline consists of four main stages:

  1. Data Augmentation: An input sentence is transformed into two augmented "views" using random token substitution. Interestingly, random substitution was found to be more effective than synonym-based augmentation for learning general representations.
  2. Adv-Generator: To identify "important" words without labels, SCAT calculates the gradient of the contrastive loss between the two augmented views. High gradient scores indicate words critical to the sentence's representation.
  3. Adversarial Substitution: These critical words are masked, and a pre-trained masked language model (MLM) suggests fluent replacements. Antonyms are filtered to preserve original meaning.
  4. Adversarial Training: The model is trained to minimize the contrastive loss between the standard augmentations and the newly crafted adversarial example.

Experimental Results

The authors evaluated SCAT on the AG's News (AG) and DBPedia datasets against two state-of-the-art attackers: TextFooler and BERT-Attack.

Performance comparison of SCAT against standard and contrastive learning baselines across AG and DBPedia datasets.

Key Findings

  • Significant Robustness Gains: SCAT-BERT and SCAT-Transformer outperformed standard supervised models by an average Attack Failure Rate (AFR) of 24.9% against TextFooler and 24.1% against BERT-Attack.
  • Efficiency of Contrastive Gradients: Gradients of contrastive loss serve as an effective proxy for word importance, highlighting semantic anchors without needing supervised labels.
  • Minimal Accuracy Trade-off: The robustness gains were achieved with only a minor drop in clean accuracy, averaging a 2.9% decrease compared to standard supervised models.
  • Superiority over Standard CL: SCAT outperformed standard contrastive learning (CL) models by 10.9% to 15.8% in robustness against TextFooler, demonstrating the value of the adversarial component.

Conclusion and Future Work

SCAT introduces a flexible, label-free method to harden language models against adversarial attacks. It can be used to train robust models from scratch or as a fine-tuning step for existing PLMs. A key challenge identified is the "fine-tuning gap," where full model fine-tuning can overwrite the robust parameters learned during SCAT pre-training, causing after-attack accuracy to drop. Future research will explore methods to maintain robustness during fine-tuning and improve the semantic quality of initial data augmentations.

Summary updated

BibTeX
@misc{wu2023scat,
  author = {Junjie Wu and Dit-Yan Yeung},
  title = {{SCAT: Robust Self-supervised Contrastive Learning via Adversarial Training for Text Classification}},
  year = {2023},
  eprint = {2307.01488},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2307.01488},
}
Figure