TL;DR
This paper introduces RanMASK, a novel method for certifying the robustness of NLP models against adversarial attacks. By randomly masking words in input text, RanMASK provides provable guarantees against word substitution and character-level attacks without needing to know the adversary's synonym generation strategy, a significant limitation of prior work.
What Problem Does This Paper Address?
Deep neural networks have revolutionized Natural Language Processing (NLP), but they are notoriously vulnerable to adversarial attacks. These attacks involve making subtle, often imperceptible changes to input text (like replacing words with synonyms or misspelling characters) that can drastically alter a model's prediction. While many defense mechanisms exist, most are evaluated empirically and don't offer certified robustness – a guarantee that the model will remain correct under any attack within certain bounds. Existing certified defenses often rely on knowing how adversaries generate synonyms, which is unrealistic. This paper addresses the need for certified robustness that doesn't make such assumptions and can defend against a broader range of attacks.
Methods
The core of RanMASK is a randomized smoothing technique applied to text. Instead of feeding an input text directly to a classifier, RanMASK creates multiple "masked" versions of the text by randomly replacing a certain percentage of words with a special [MASK] token. A base classifier, trained on similar masked texts, then classifies each masked version. The final prediction is determined by a majority vote across these classifications.
This approach has several key advantages:
- No Adversary Knowledge: It doesn't require knowing the adversary's synonym list or generation strategy.
- Leverages Pre-trained Models: The masking operation is similar to how models like BERT are pre-trained, allowing them to "recover" or infer information about masked words. This helps maintain classification accuracy on masked inputs.
- Certified Robustness: The paper provides a theoretical framework (Theorem 1) to certify robustness. The core idea is that if a sufficient number of words are randomly masked, it's highly unlikely that all of the adversary's perturbed words will survive the masking process, thus preventing the attack from fooling the model.
The authors also propose a novel sampling strategy for masking, where the probability of masking a word is influenced by its output probability from a BERT-based language model. This aims to retain more important words and further improve robustness.
Datasets
The paper evaluates RanMASK on several standard NLP datasets:
- AGNEWS: A news topic classification dataset.
- SST2: A sentiment analysis dataset.
- IMDB: A dataset for movie review sentiment analysis.
- SNLI: A natural language inference dataset.
Key Insights and Ideas
- Random Masking as a Defense: The surprising insight is that simply randomly masking words can be a powerful defense against adversarial attacks. This works because it disrupts the specific, targeted perturbations an adversary makes.
- Decoupling Robustness from Adversary Knowledge: The most significant contribution is removing the unrealistic assumption that defenders know the adversary's attack strategy. This makes the defense more practical and generalizable.
- Ensemble Methods Matter: The choice of ensemble method (e.g., majority vote vs. logit-summed) significantly impacts both empirical and certified robustness. The "majority vote" ensemble often leads to better empirical robustness, especially against score-based attacks.
- Masking Rate Trade-offs: There's a clear trade-off between the masking rate and both clean accuracy and robust accuracy. Higher masking rates generally improve certified robustness but can decrease clean accuracy.
Key Results
- Certified Robustness: RanMASK can certify that over 50% of texts on AGNEWS are robust to perturbations of up to 5 words, and on SST2, up to 2 words.
- Empirical Robustness: RanMASK consistently outperforms existing empirical and certified defense methods across multiple datasets and attack types (TextFooler, BERT-Attack, DeepWordBug). For instance, on AGNEWS, RanMASK-90% (vote) achieved significantly better robust accuracy than competitors.
- Improved Accuracy Under Attack: RanMASK can improve robust accuracy by over 20% on average compared to baselines, while only slightly decreasing clean accuracy.
- Scalability: The method is designed to be scalable and can be integrated into large architectures like BERT.
Limitations and Future Work
- Masking Rate Optimization: Finding the optimal masking rate is crucial and can be dataset-dependent. Very high masking rates (e.g., >90%) can make it difficult to train the base classifier, especially on datasets where sentiment is conveyed by a few key words (like SST2).
- Ensemble Method Impact: The paper highlights that the choice of ensemble method is critical and can affect performance differently depending on the attack.
- Future Work: The authors suggest exploring combinations of RanMASK with other defense methods (like FreeLB) and developing a pre-trained detector to identify adversarial inputs before applying the defense. They also propose investigating the theoretical underpinnings of the "majority vote" ensemble's effectiveness.
Summary updated