Abstract: CLARE is a novel framework for generating adversarial text attacks that are significantly more fluent and effective than previous methods. By using a "mask-then-infill" procedure powered by pre-trained language models, CLARE applies three types of contextualized edits—Replace, Insert, and Merge—to trick NLP models while maintaining the original meaning and grammatical integrity of the text.
Introduction
Machine learning models for Natural Language Processing (NLP) are notoriously brittle. "Adversarial attacks"—small, intentional perturbations to input text—can easily trick a state-of-the-art model into making a wrong prediction. However, existing attack methods often produce "word salad" because they rely on simple heuristic rules, like swapping a word for a synonym from a fixed dictionary, while ignoring surrounding context. Furthermore, most existing attacks are limited to "one-for-one" replacements, which severely limits the "attack surface" the adversary can explore.
Methodology
The authors introduce CLARE (ContextuaLized AdversaRial Example generation), which moves away from rigid rules in favor of a flexible mask-then-infill strategy.
The process works in two main stages:
- Proposal: For every position in a sentence, CLARE proposes three types of actions: Replace (swap a token), Insert (add a new token), and Merge (combine a bigram into a single token).
- Infilling: Instead of using a static thesaurus, CLARE uses a pre-trained Masked Language Model (MLM), specifically RoBERTa, to suggest fillers for the masks. This ensures that the new words fit the local context and grammar.
Candidates are ranked based on fluency (MLM probability), semantic similarity (Universal Sentence Encoder), and effectiveness (impact on the victim model's prediction).
Experimental Setup
CLARE was evaluated across a diverse range of NLP tasks, including Sentiment Analysis (Yelp, SST-2), Topic Classification (AG News, DBpedia), Natural Language Inference (MNLI, QNLI), and Sentence Paraphrase (MRPC, QQP). The primary "victim" model was a fine-tuned BERT-base classifier.
Results and Analysis
CLARE consistently outperformed state-of-the-art baselines like TextFooler and BERTAttack across all metrics. On the AG News dataset, CLARE achieved a 79.1% success rate, significantly higher than BERTAttack’s 63.4%.
Key insights include:
- Contextual Integrity: By using an MLM, CLARE generates examples that are much harder for humans to distinguish from original text.
- Expanded Attack Surface: The addition of Insert and Merge actions allows the model to find vulnerabilities that replacement-only models miss.
- Efficiency: CLARE achieves higher success rates while modifying a smaller percentage of the original text.
- Robustness: Adversarial training with CLARE-generated examples improved model robustness and even improved accuracy on clean data in low-resource scenarios.
Conclusion and Future Work
While CLARE is highly effective, it introduces computational overhead due to the use of large language models for generation. Future work may explore more advanced search algorithms (like beam search) or expanding the "Merge" action beyond noun phrases. Additionally, extending CLARE to white-box settings where internal gradients are available remains a potential research direction.
Citation: Dianqi Li, Yizhe Zhang, Hao Peng, Liqun Chen, Chris Brockett, Ming-Ting Sun, Bill Dolan. Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies. 2021.
Summary updated