Semantic-Preserving Adversarial Example Attack against BERT

Chongyang Gao, Kang Gu, Soroush Vosoughi, Shagufta Mehnaz2024

Abstract

Adversarial example attacks against textual data have been drawing increasing attention in both the natural language processing (NLP) and security domains. However, most of the existing attacks overlook the importance of semantic similarity and yield easily recognizable adversarial samples. As a result, the defense methods developed in response to these attacks remain vulnerable and could be evaded by advanced adversarial examples that maintain high semantic similarity with the original, non-adversarial text. This paper proposes Reinforce attack, a reinforcement learning-based framework to generate adversarial text that preserves high semantic similarity with the original text. The attack process is controlled by a reward function rather than heuristics to encourage higher semantic similarity and lower query costs. Through automatic and human evaluations, we show that our generated adversarial texts preserve significantly higher semantic similarity than state-of-the-art attacks while achieving similar or superior attack success rates.

Introduction

Adversarial attacks in NLP aim to flip a model's prediction (e.g., changing a "Positive" sentiment label to "Negative") by making small edits to the input text. However, existing attacks often produce "poor" adversarial examples that are easily detectable because they fundamentally change the meaning of the sentence. For instance, changing "I like this movie" to "I hate this movie" flips the model but also changes the ground-truth sentiment for a human reader.

A truly effective adversarial example should be semantic-preserving: it should trick the model without changing the meaning. Current methods rely on simple heuristics or synonym dictionaries that do not actively optimize for semantic integrity, making them easy for humans to spot and for defense models to filter. This paper introduces the "Reinforce" framework to address this gap.

Methodology: The Reinforce Framework

The authors propose a two-stage framework that leverages interpretability and reinforcement learning to generate sophisticated attacks.

LIME-based Word Importance

Instead of the standard approach of masking words one-by-one to measure their impact, the authors use LIME (Local Interpretable Model-agnostic Explanations). LIME creates a "neighborhood" of similar sentences and learns a linear model to identify which words are truly pivotal to the model's decision-making in a holistic way, capturing interactions that simple masking might miss.

Reinforcement Learning Attack

The core contribution is a Reinforcement Learning (RL) framework where the attack is treated as a sequence-tagging problem. An RL agent learns to select the best words to substitute based on a multi-objective reward function.

The Reinforce Attack framework architecture, integrating LIME for feature importance and an RL agent for action selection.

The reward function $R$ is designed to balance four competing goals:

  • Attack Success: Flipping the target model's prediction.
  • Semantic Similarity: Measured via the Universal Sentence Encoder (USE) to ensure the adversarial text "means" the same as the original.
  • Query Efficiency: Minimizing the number of queries to the target model.
  • Perturbation Rate: Keeping the number of changed words low (typically under 25%).

Experimental Results

The Reinforce attack was evaluated on several standard NLP benchmarks, including IMDB, Yelp, AG’s News, and the FAKE dataset. It was compared against state-of-the-art (SOTA) attacks such as TextFooler and BERT-Attack.

Performance comparison of Reinforce Attack against SOTA methods across multiple classification benchmarks.

Key Findings

  • Superior Similarity: On the IMDB dataset, Reinforce achieved a 0.97 semantic similarity score, compared to 0.86 for BERT-Attack and TextFooler.
  • Higher Success Rates: Despite its subtlety, the attack was more lethal. It reduced BERT’s accuracy on IMDB to just 1.9%, whereas BERT-Attack only brought it down to 11.4%.
  • Human Validation: In blind tests, human annotators rated Reinforce examples as more grammatical and semantically consistent with the originals than those produced by previous SOTA attacks.
  • Regression Tasks: The attack also proved effective on regression tasks (e.g., Blog Authorship Corpus), outperforming BERT-Attack by approximately 33% in terms of Mean Absolute Error (MAE) shift.

Conclusion

The Reinforce framework demonstrates that BERT-based models are highly vulnerable to adversarial examples that maintain near-perfect semantic similarity to the original text. By treating semantic preservation as an active optimization goal rather than a passive byproduct, the authors have exposed a critical vulnerability in current NLP defenses. Future work will explore using these high-quality adversarial examples for adversarial training to build more robust, meaning-aware models.

Summary updated

BibTeX
@misc{gao2024semantic,
  author = {Chongyang Gao and Kang Gu and Soroush Vosoughi and Shagufta Mehnaz},
  title = {{Semantic-Preserving Adversarial Example Attack against BERT}},
  year = {2024},
  doi = {10.18653/v1/2024.trustnlp-1.17},
}
Figure