BERT is Robust! A Case Against Synonym-Based Adversarial Examples in Text Classification

Jens Hauser, Zhao Meng, Damián Pascual, Roger WattenhoferarXiv 2021

Abstract

Recent research has suggested that state-of-the-art NLP models like BERT are highly vulnerable to adversarial attacks based on synonym substitutions. However, this study from ETH Zurich demonstrates that the vast majority of these "successful" attacks either produce nonsensical text or fundamentally alter the original meaning. By introducing human-validated semantic constraints and a two-step defense mechanism—data augmentation and randomized post-processing—the researchers show that BERT's perceived vulnerability is largely an artifact of loose evaluation metrics. Under rigorous testing, attack success rates drop from over 90% to under 5%.

Introduction: The Semantic Integrity Problem

In computer vision, adversarial attacks are often imperceptible to humans. In contrast, Natural Language Processing (NLP) attacks typically involve swapping words for synonyms. The core issue addressed in this paper is that word swaps are rarely "invisible." If an attack changes the sentiment of a sentence from positive to negative, it is not an adversarial example; it is a different sentence entirely.

The authors argue that the NLP community has prioritized high attack success rates over semantic integrity. This paper investigates whether current attacks expose genuine model weaknesses or if they simply feed models "garbage" data that no longer carries the original intent.

Datasets and Baseline Vulnerability

The study evaluated the BERT-base-uncased architecture on two standard benchmarks: AG News (topic classification) and Yelp (sentiment analysis). Initial tests using popular attack frameworks like TextFooler and BERT-Attack showed alarmingly high success rates, often exceeding 90% on the Yelp dataset.

Baseline attack success rates across datasets and attack methods before applying defenses.

Methodology

The researchers employed a three-pronged approach to re-evaluate and defend BERT:

  1. Human Validation: Using Amazon Mechanical Turk, humans rated word substitutions from four major attacks (TextFooler, PWWS, BERT-Attack, and BAE). A probabilistic model then estimated the likelihood that a full adversarial sentence preserved its original meaning.
  2. Data Augmentation (DA): During training, the model was exposed to synonyms with lower similarity scores. This prepared the model for the "edge-case" synonyms typically favored by attackers.
  3. Post-Processing (PP): At inference time, the system generated $N$ randomized versions of the input text using valid synonym swaps and averaged the model's predictions (logits). Robust models should maintain consistent predictions across these variations.

Key Insights: The "Nonsense" Factor

The study found that 96% to 99% of successful adversarial examples failed to preserve semantics according to human judges. Attacks like BERT-Attack and BAE frequently suggested words that were grammatically plausible but contextually nonsensical or contradictory.

Crucially, the perceived vulnerability of BERT is highly dependent on the chosen similarity threshold ($T_h$). When stricter, human-validated constraints are enforced, the probability of a valid attack occurring decreases dramatically.

Probability of a valid attack as a function of the similarity threshold $T_h$, showing a sharp decline as semantic constraints tighten.

Results and Defense Effectiveness

The combined DA+PP defense effectively neutralized state-of-the-art attacks. On the Yelp dataset, TextFooler’s success rate plummeted from 90.47% to just 4.37%. Importantly, this robustness did not come at the cost of standard performance; clean accuracy on AG News only saw a marginal dip from 94.57% to 93.84%.

Furthermore, the Data Augmentation approach proved highly efficient. It required only 5.5 hours of training on AG News, compared to the 160 hours typically required for full adversarial training, while providing comparable or superior protection.

Conclusion

The findings suggest that BERT is far more robust than previously reported. The authors call for the NLP community to move away from chasing 100% success rates using nonsensical perturbations. Instead, research should focus on the small fraction (10-20%) of valid, meaningful adversarial examples that can truly help identify and fix flaws in model logic.

Summary updated

BibTeX
@misc{hauser2021bert,
  author = {Jens Hauser and Zhao Meng and Damián Pascual and Roger Wattenhofer},
  title = {{BERT is Robust! A Case Against Synonym-Based Adversarial Examples in Text Classification}},
  year = {2021},
  eprint = {2109.07403},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2109.07403},
}
Figure