Introduction
Adversarial attacks—small, intentional perturbations designed to deceive machine learning models—have been extensively studied in the context of computer vision. However, applying these techniques to Natural Language Processing (NLP) presents a unique challenge: language is discrete. Unlike image pixels, which can be subtly adjusted, words must be swapped entirely.
Previous text-based attacks relied on heuristic rules, such as character swapping or fixed synonym dictionaries. These methods frequently suffer from two major drawbacks: poor grammatical fluency and a lack of semantic consistency. Often, the resulting adversarial samples are unintelligible to humans or change the sentence's meaning so drastically that the attack is no longer valid.
Methodology: Turning BERT Against Itself
The researchers introduce BERT-Attack, a high-quality adversarial method that leverages a pre-trained Masked Language Model (MLM)—specifically BERT—to generate deceptive text. The algorithm operates in two distinct stages:
- Identifying Vulnerable Words: The system determines which words are most critical to the target model's prediction. By iteratively replacing each word with a
[MASK]token and measuring the resulting drop in the target model's confidence score, the algorithm ranks words by their "vulnerability." - Contextual Word Replacement: Instead of a static thesaurus, BERT-Attack uses the original sentence context to predict the top-$K$ most likely replacements for vulnerable positions. By not masking the target word during generation, the model ensures that replacements are both semantically and grammatically natural.
The method also incorporates sub-word awareness, allowing it to attack Byte-Pair Encoding (BPE) tokens, and applies filters to prevent semantic "drift," such as accidentally replacing a word with its antonym.
Experimental Results
BERT-Attack was evaluated against fine-tuned BERT models and LSTMs across several benchmarks, including sentiment analysis (Yelp, IMDB), topic classification (AG’s News), and Natural Language Inference (SNLI, MNLI).
As shown in the results above, BERT-Attack consistently outperforms previous state-of-the-art methods like TextFooler:
- Attack Success: It reduced a fine-tuned BERT's accuracy on the IMDB dataset from 90.9% to a mere 11.4%.
- Efficiency and Perturbation: On the Yelp dataset, BERT-Attack achieved success by changing only 4.1% of the words, whereas TextFooler required a 12.8% change.
- Fluency: Human evaluations confirmed that BERT-Attack produces more fluent and semantically similar samples than rule-based alternatives.
Discussion and Future Work
The core innovation of BERT-Attack is treating a pre-trained BERT as a "contextual thesaurus" that understands the natural language manifold. This approach is not only more effective but also significantly faster—roughly 3x faster than TextFooler—because it generates all potential candidates in a single forward pass.
While highly effective, the method still faces challenges with very short sequences and occasional semantic drift (the "antonym problem"). Future research will likely focus on using these high-quality adversarial samples for adversarial training, thereby hardening NLP models against increasingly sophisticated deceptive inputs.
Summary updated