R&R: Metric-guided Adversarial Sentence Generation

Lei Xu, Alfredo Cuesta‐Infante, Laure Berti‐Équille, Kalyan Veeramachaneni · DOI

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—subtly modified inputs designed to trick machine learning models—are essential tools for stress-testing the robustness of NLP systems. However, generating high-quality adversarial sentences is notoriously difficult. Existing methods often suffer from a "greedy" tunnel vision: they prioritize flipping the model's prediction at any cost. This frequently results in sentences that are ungrammatical, nonsensical, or have completely different meanings than the original.

A valid adversarial example must balance three conflicting goals: successful misclassification, high fluency (sounding natural to a human), and strong semantic similarity (retaining the original meaning and label). To address these challenges, we introduce the Rewrite and Rollback (R&R) framework.

The R&R Framework

The R&R framework breaks the generation process into two distinct, iterative stages guided by a comprehensive "critique score."

1. Rewrite (Stochastic Exploration)

Unlike greedy algorithms that only accept changes that immediately improve the attack, R&R uses a stochastic approach inspired by the Metropolis-Hastings algorithm. It masks spans of words (typically 3 at a time) and uses a language model (BERT) to suggest replacements. By occasionally accepting "worse" rewrites, the model can escape local optima and find more effective paths to a successful attack.

2. Rollback (Pruning)

This is the framework's most significant innovation. After a successful attack is found, the system identifies the minimum set of edits needed to maintain that misclassification. It attempts to "undo" each change one by one; if the classifier still fails after a change is reverted, that change is discarded. This process significantly boosts the similarity to the original sentence by removing unnecessary perturbations.

An example of the R&R process showing iterative rewrites followed by a rollback phase to prune unnecessary edits.

Experimental Setup

We evaluated R&R across five diverse datasets: AG News (topic classification), MR (sentiment analysis), TREC (question type), HATE (hate speech detection), and FAKE (fake news detection). These were tested against three common classifier architectures: BERT, RoBERTa, and FastText.

Performance and Results

R&R consistently outperformed state-of-the-art baselines, including TextFooler and CLARE. Key findings include:

  • Higher Success Rates: R&R improved the Attack Success Rate (ASR) by +16.2% on BERT, +12.8% on RoBERTa, and +14.0% on FastText compared to CLARE.
  • Superior Quality: Human evaluations via Amazon Mechanical Turk confirmed that R&R examples were more fluent and semantically similar to the originals than those produced by baseline methods.
  • Robustness to Defenses: Even when target models were protected by perplexity-based filtering or SHIELD defenses, R&R maintained a significantly higher success rate.
Attack Success Rate (ASR) comparison across different similarity and perplexity thresholds on AG and FAKE datasets.

Discussion and Limitations

The "aha moment" of this research is that it is more effective to find a successful attack by initially changing "too much" and then pruning back (Rollback) than it is to find a perfect minimal change in a single pass. Furthermore, masking multiple consecutive words (span size of 3) proved more effective than single-word substitution, as it allows the model to replace entire idioms or phrases naturally.

However, R&R is computationally more intensive than greedy methods, taking approximately 15.8 seconds per attack compared to under a second for TextFooler. Additionally, the method's performance is somewhat dependent on the quality of the input; if the original sentence is already "noisy," the adversarial version will likely inherit those flaws. Future work will explore structural changes, such as reordering clauses, to further improve attack stealthiness.

Summary updated

BibTeX
@inproceedings{xu2022r,
  author = {Lei Xu and Alfredo Cuesta‐Infante and Laure Berti‐Équille and Kalyan Veeramachaneni},
  title = {{R\&R: Metric-guided Adversarial Sentence Generation}},
  booktitle = {AACL/IJCNLP (Findings)},
  year = {2022},
  doi = {10.18653/v1/2022.findings-aacl.41},
}
Figure