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:
- Factorization: The search space is reduced by decoupling the choice of which word to replace from what to replace it with.
- 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.
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.
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