SemRoDe: Macro Adversarial Training to Learn Representations that are Robust to Word-Level Attacks

Brian Formento, Wenjie Feng, Chuan-Sheng Foo, Anh Tuan Luu, See-Kiong Ng

Abstract

SemRoDe (Semantic Robust Defence) introduces a "macro" approach to adversarial training by treating adversarial samples as a separate data domain. By using distance-based regularizers like Maximum Mean Discrepancy (MMD) to align the feature distributions of clean and attacked text, the authors enable language models to learn representations that are significantly more robust to word-substitution attacks.

Introduction

Deep learning models for natural language processing (NLP) are notoriously brittle. An attacker can often flip a model's prediction just by swapping a few words for their synonyms (e.g., changing "good" to "fine"). While adversarial training (AT)—incorporating these "attacked" samples into the training process—is a standard defense, its success in NLP has been limited.

The authors identify a core reason for this: word-level substitutions aren't just small "noise" perturbations. In the model's internal feature space, these substitutions cause a massive "covariate shift," pushing adversarial samples into a completely different distribution (an "adversarial domain") far away from the original data. Standard training methods struggle to bridge this gap, leaving the model vulnerable to unseen attack variations.

Methodology: Macro Adversarial Training

The authors propose SemRoDe, a Macro Adversarial Training strategy. Instead of just minimizing the classification loss on individual adversarial samples, SemRoDe aims to align the entire distribution of adversarial features with the base features.

The SemRoDe framework aligns base and adversarial domains into a single robust domain using distance-based regularization.

Key components include:

  • Adversarial Domain Mapping: The authors confirm that attacked samples exhibit a high Wasserstein distance from base samples in the feature space, justifying the "domain adaptation" perspective.
  • Distance-Based Regularization: A new term is added to the loss function: $\mathcal{L} = \mathcal{L}_{Base} + \lambda \mathcal{L}_{Dist}$. The $\mathcal{L}_{Dist}$ term uses metrics like Maximum Mean Discrepancy (MMD), CORAL, or Optimal Transport to penalize the distance between the high-level feature representations of clean and adversarial batches.
  • Offline Adversarial Generation: To maintain training efficiency, adversarial samples are generated once at the start (e.g., using TextFooler) rather than re-generating them every epoch.
  • Feature Alignment: By minimizing the distance between these two domains at the pooling layer, the model learns to project both clean and attacked versions of a sentence into the same robust region of the feature space.

Experimental Results

The researchers evaluated their approach using BERT and RoBERTa backbones across standard text classification benchmarks: MR (Movie Reviews), SST-2, and AG-News.

SemRoDe achieved state-of-the-art (SOTA) results in After Attack Accuracy (AUA)—the model's accuracy when under active attack. On the MR dataset with BERT, SemRoDe improved AUA from 21.2% (Vanilla) to nearly 40% against the TextFooler attack. It consistently outperformed established defense methods like A2T, FreeLB++, and DSRM.

t-SNE visualization comparing non-robust (top) and robust (bottom) feature spaces. SemRoDe alignment merges the base and adversarial distributions.

Discussion and Insights

  • The "Macro" Perspective: Unlike "micro" AT which looks at individual points, SemRoDe addresses how the entire population of adversarial samples shifts in feature space.
  • Visualizing Robustness: t-SNE plots demonstrate that in vanilla models, clean and adversarial samples form distinct clusters. After SemRoDe alignment, these distributions merge, restoring linear separability.
  • Generalization: Training on one specific attack (e.g., WordNet synonyms) provides protection against different attack algorithms, suggesting the model learns fundamental "semantic robustness."
  • Efficiency: The offline generation of adversarial samples makes SemRoDe significantly faster to train than "online" methods like InfoBERT, which require multiple gradient steps per iteration.

Conclusion and Future Work

While effective, SemRoDe currently aligns overall distributions without explicit class-conditional constraints, which may be necessary for complex multi-class tasks. Future work includes extending this strategy to "white-box" attacks and generative models like Large Language Models (LLMs).

Summary updated

BibTeX
@inproceedings{formento2024semrode,
  author = {Brian Formento and Wenjie Feng and Chuan-Sheng Foo and Anh Tuan Luu and See-Kiong Ng},
  title = {{SemRoDe: Macro Adversarial Training to Learn Representations that are Robust to Word-Level Attacks}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.naacl-long.443},
}
Figure