Achieving Model Robustness through Discrete Adversarial Training

Maor Ivgi, Jonathan Berant

Abstract

Adversarial training is a cornerstone of robust model development in computer vision, typically implemented as an online process where examples are updated at every training step. In Natural Language Processing (NLP), however, the discrete nature of text has historically limited adversarial training to offline methods using static sets of examples. This paper introduces a systematic approach to online adversarial training for NLP. We propose Best-First Search over a Factorized Graph (BFF), a novel attack algorithm that outperforms existing greedy methods. Our findings reveal that while online training is computationally intensive, it provides substantial gains in robust accuracy. Furthermore, we demonstrate that simple random synonym sampling (RANDOFF) serves as a surprisingly effective and efficient baseline for robustness.

Introduction

The vulnerability of deep learning models to adversarial perturbations is well-documented. In the context of NLP, these perturbations often involve synonym substitutions designed to flip a model's prediction while preserving the original meaning. Traditional NLP adversarial training is "offline": a model is trained on a fixed set of adversarial examples generated from a pre-trained baseline. This approach fails to account for the model's evolving weaknesses during the training process.

This research addresses three critical gaps: the lack of systematic comparison between online and offline augmentation, the inefficiencies of greedy discrete attack algorithms, and the prevalence of "label-flipping" in existing benchmarks, where attacks change the sentence's meaning so much that the ground-truth label itself changes.

Methodology

Best-First Search over a Factorized Graph (BFF)

Existing discrete attacks, such as TextFooler, typically employ a greedy search strategy, replacing words one by one without the ability to backtrack. This often leads to sub-optimal adversarial examples or search failures.

BFF improves upon this by introducing two key mechanisms:

  1. Factorization: The search space is reduced by decoupling the choice of which word to replace from what to replace it with.
  2. Best-First Search: Utilizing a min-heap, BFF tracks multiple potential substitution paths. If a particular sequence of changes stops yielding progress, the algorithm can backtrack to a more promising earlier state.
BFF employs a best-first search strategy that allows for backtracking, unlike traditional greedy methods.

Online Augmentation (ADVON)

To bridge the gap with computer vision practices, we implement online augmentation. Instead of a static dataset, adversarial examples are generated dynamically during every training epoch. This forces the model to continuously adapt to new adversarial directions as its decision boundaries shift.

Strict Filtering

To ensure semantic and grammatical integrity—and to avoid the "label-flipping" trap—we apply a rigorous ensemble of filters:

  • Part-of-Speech (POS) matching for grammatical correctness.
  • GPT-2 Perplexity to maintain natural language flow.
  • Universal Sentence Encoder (USE) to ensure high semantic similarity between the original and perturbed text.

Experimental Results

We evaluated our methods on SST-2, IMDB, and BoolQ datasets. The results highlight a significant trade-off between robustness and computational cost.

Robust accuracy vs. slowdown factor across BoolQ and IMDB datasets. Online adversarial training (AdvOn) achieves the highest robustness but at a significant computational cost.

Robustness vs. Efficiency

Online training (ADVON) consistently achieved the highest robust accuracy. For instance, on the IMDB dataset, robust accuracy improved from a baseline of 41.2% to 78.9%. However, this comes at a steep price: ADVON can be 20x to 270x slower than standard training.

A surprising finding was the effectiveness of Random Offline Augmentation (RANDOFF). By simply sampling 4–12 synonyms randomly, we achieved better robustness than many search-based offline methods (like TXFOFF) while being significantly faster. On IMDB, RANDOFF-12 reached 60.1% robust accuracy, compared to 49.0% for TXFOFF.

Discussion and Key Insights

  • The Power of Online Adaptation: Adapting attacks to the model's current state is far more effective than training on a static set of "hard" examples.
  • Backtracking is Essential: The ability of BFF to backtrack allows it to find adversarial examples that greedy algorithms miss, providing a more rigorous evaluation of model robustness.
  • The Label-Flipping Trap: Many existing attacks "succeed" by inadvertently changing the sentence's meaning. Our strict filtering and human validation ensure that robustness metrics reflect true resilience to meaning-preserving perturbations.

Conclusion

Discrete adversarial training in NLP is a powerful tool for building robust models. While the computational overhead of online search-based training remains a challenge, the gains in robust accuracy are substantial. Future work should focus on finding efficient "middle-ground" strategies that combine the speed of random sampling with the effectiveness of guided search.

Summary updated

Abstract

Discrete adversarial attacks are symbolic perturbations to a language input that preserve the output label but lead to a prediction error. While such attacks have been extensively explored for the purpose of evaluating model robustness, their utility for improving robustness has been limited to offline augmentation only. Concretely, given a trained model, attacks are used to generate perturbed (adversarial) examples, and the model is re-trained exactly once. In this work, we address this gap and leverage discrete attacks for online augmentation, where adversarial examples are generated at every training step, adapting to the changing nature of the model. We propose (i) a new discrete attack, based on best-first search, and (ii) random sampling attacks that unlike prior work are not based on expensive search-based procedures. Surprisingly, we find that random sampling leads to impressive gains in robustness, outperforming the commonly-used offline augmentation, while leading to a speedup at training time of ~10x. Furthermore, online augmentation with search-based attacks justifies the higher training cost, significantly improving robustness on three datasets. Last, we show that our new attack substantially improves robustness compared to prior methods.
BibTeX
@inproceedings{ivgi2021achieving,
  author = {Maor Ivgi and Jonathan Berant},
  title = {{Achieving Model Robustness through Discrete Adversarial Training}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2021},
  url = {https://openreview.net/forum?id=mm9aeWfm3Hx},
}
Figure