Generating Natural Language Adversarial Examples

Moustafa Alzantot, Yash Sharma, Ahmed Elgohary, Bo-Jhang Ho, Mani B. Srivastava, Kai-Wei Chang

Abstract

Adversarial examples in Natural Language Processing (NLP) are difficult to generate because text is discrete and humans are highly sensitive to linguistic changes. This paper presents a black-box genetic algorithm that generates adversarial text by replacing words with semantically similar synonyms. The approach achieves a 97% success rate against sentiment analysis models and a 70% success rate against textual entailment models, while maintaining high human readability and semantic consistency.

Introduction

In computer vision, adversarial examples—small, imperceptible changes to pixels that fool a model—are well-studied. However, translating this to NLP presents two major hurdles: the discrete nature of word tokens (preventing gradient-based 'nudging') and human sensitivity to language (where small changes can easily result in 'word salad' or flipped meanings). This research addresses these challenges by developing a black-box attack that produces natural-looking text capable of fooling state-of-the-art models.

Methodology

The researchers developed a population-based genetic algorithm to evolve adversarial sentences. Unlike gradient-based methods, this approach only requires access to the model's output confidence scores.

The Genetic Algorithm

The process begins with a population of sentences derived from the original input, each with one word perturbed. In each generation, the 'fittest' sentences—those that most increase the probability of an incorrect prediction—are selected for crossover (combining sentence segments) and mutation.

The Perturb Subroutine

To ensure the generated text remains natural and semantically similar to the original, the Perturb subroutine uses:

  1. Counter-fitted GloVe embeddings: To find synonyms that share meaning rather than just context (avoiding antonyms).
  2. Language Modeling: A Google 1 Billion Words language model ensures the replacement word fits the local grammatical context.
Example of an adversarial swap in textual entailment where 'runner' is replaced by 'racer'.

Experimental Results

The attack was evaluated on the IMDB sentiment analysis dataset and the Stanford Natural Language Inference (SNLI) dataset.

Performance comparison of the genetic attack against a baseline perturbation method across two NLP tasks.

As shown in the results, the genetic attack was devastatingly effective on the IMDB dataset, achieving a 97% success rate by modifying only 14.7% of the words. On the SNLI dataset, the success rate was lower (70%), likely due to the shorter average sentence length (9 words), which makes finding 'safe' synonyms more difficult without altering the core meaning.

Human validation confirmed the quality of these examples: 92.3% of successful adversarial examples were still correctly classified by human annotators according to their original label, and the text was rated as highly similar to the source.

Discussion and Conclusion

The high success rates demonstrate that current deep neural networks for NLP often rely on specific keyword features rather than a holistic understanding of text. Furthermore, the researchers found that standard adversarial training—incorporating these examples back into the training set—was insufficient to defend against the attack. This suggests that the space of possible natural language perturbations is vast and requires more sophisticated defense mechanisms. Future work will explore word insertion and deletion strategies to further test model robustness.

Summary updated

BibTeX
@inproceedings{alzantot2018generating,
  author = {Moustafa Alzantot and Yash Sharma and Ahmed Elgohary and Bo-Jhang Ho and Mani B. Srivastava and Kai-Wei Chang},
  title = {{Generating Natural Language Adversarial Examples}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2018},
  doi = {10.18653/v1/d18-1316},
}
Figure