Abstract
Adversarial examples are helpful for analyzing and improving the robustness of text classifiers. Generating high-quality adversarial examples is a challenging task as it requires generating fluent adversarial sentences that are semantically similar to the original sentences and preserve the original labels, while causing the classifier to misclassify them. Existing methods prioritize misclassification by maximizing each perturbation's effectiveness at misleading a text classifier; thus, the generated adversarial examples fall short in terms of fluency and similarity. In this paper, we propose a rewrite and rollback (R&R) framework for adversarial attack. It improves the quality of adversarial examples by optimizing a critique score which combines the fluency, similarity, and misclassification metrics. R&R generates high-quality adversarial examples by allowing exploration of perturbations that do not have immediate impact on the misclassification metric but can improve fluency and similarity metrics. We evaluate our method on 5 representative datasets and 3 classifier architectures. Our method outperforms current state-of-the-art in attack success rate by +16.2%, +12.8%, and +14.0% on the classifiers respectively.
Introduction
Adversarial attacks—subtle perturbations designed to deceive machine learning models—are a cornerstone of robustness research. While well-established in computer vision, generating effective adversarial text remains a significant challenge. Most current NLP attack methods rely on greedy synonym substitution, swapping individual words to maximize the immediate drop in classifier confidence. This approach frequently results in "word salad": sentences that are grammatically incoherent or deviate significantly from the original meaning. Furthermore, greedy searches often fail to find complex adversarial paths that require multiple coordinated changes.
To address these limitations, we introduce the Rewrite and Rollback (R&R) framework. R&R treats adversarial generation as a multi-objective optimization problem, balancing misclassification with fluency and semantic similarity. By moving beyond simple word-swapping and incorporating a pruning phase, R&R produces adversarial examples that are both more effective and more human-like.
The R&R Framework
The R&R framework operates through an iterative process consisting of two primary phases: stochastic rewriting and pruning via rollback.
1. Rewrite (Stochastic Exploration)
Instead of simple one-for-one word substitution, the Rewrite phase masks spans of words (typically three) and utilizes a fine-tuned BERT model to propose candidate replacements. The quality of these candidates is evaluated using a Critique Score, which synthesizes three key metrics:
- Fluency: Measured via BERT perplexity.
- Semantic Similarity: Measured using the Universal Sentence Encoder (USE).
- Misclassification Probability: The likelihood that the target classifier will fail.
Crucially, R&R employs a Metropolis-Hastings sampling approach. This allows the model to occasionally accept rewrites that temporarily decrease the critique score. This stochastic exploration enables the system to escape local optima and discover high-quality adversarial sentences that greedy algorithms would overlook.
2. Rollback (Pruning)
Once a successful adversarial example is found, it may contain redundant perturbations that negatively impact fluency or similarity. The Rollback phase identifies the minimum edit distance between the adversarial sentence and the original text. It systematically attempts to revert each edit (insertion, deletion, or replacement). If a change can be rolled back without restoring the correct classification, it is discarded, effectively "cleaning" the adversarial example.
Experimental Results
We evaluated R&R across five diverse datasets (AG News, Movie Reviews, TREC, HATE, and FAKE) and three classifier architectures (BERT, RoBERTa, and FastText).
Attack Success Rate (ASR)
R&R significantly outperformed state-of-the-art baselines like TextFooler and CLARE. As shown in the performance plots, R&R maintains a higher Attack Success Rate even as constraints on similarity and perplexity become more stringent. On average, R&R improved ASR by +16.2% on BERT-base classifiers.
Human Evaluation and Robustness
Human evaluators on Amazon Mechanical Turk consistently rated R&R's outputs as more fluent and semantically faithful than those of competitors. Furthermore, R&R proved resilient against common adversarial defenses, such as perplexity-based filtering and SHIELD, maintaining high success rates where other methods failed.
Discussion and Conclusion
The success of R&R highlights two critical insights in adversarial NLP. First, exploration beats exploitation: the ability to move through "worse" intermediate states is essential for finding high-quality adversarial paths. Second, rollback is essential: many perturbations required to reach a misclassification are ultimately unnecessary for maintaining it. By filtering this noise, R&R achieves a superior balance of attack effectiveness and linguistic quality. While computationally more intensive than greedy methods, R&R sets a new benchmark for generating robust, human-like adversarial text.
Summary updated