Generating Valid and Natural Adversarial Examples with Large Language Models

Zimu Wang, Wei Wang, Qi Chen, Qiufeng Wang, Anh Nguyen

TL;DR

LLM-Attack is a new framework that leverages the contextual power of Large Language Models (LLMs) to generate word-level adversarial examples that are both effective and "invisible." By using LLMs to suggest synonyms, the method creates adversarial text that fools AI classifiers while maintaining near-perfect grammatical correctness and semantic meaning, significantly outperforming previous state-of-the-art attack methods in human and GPT-4 evaluations.

What Problem Does This Paper Address?

Deep learning models for Natural Language Processing (NLP) are notoriously fragile. "Adversarial attacks"—making tiny, human-imperceptible changes to an input to flip a model's prediction—are used to study this vulnerability.

However, existing word-level attacks (like TextFooler or BAE) often produce "unnatural" results. They frequently:

  1. Change the meaning: Replacing a word with an antonym (e.g., changing "good" to "bad").
  2. Break grammar: Using a synonym that doesn't fit the tense or part of speech.
  3. Split Named Entities: Changing parts of a person's name or a movie title (e.g., turning "Rita Hayworth" into "Rita Length"), which makes the attack obvious to any human reader.

The authors argue that for an adversarial example to be truly "valid," it must maintain human prediction consistency, semantic similarity, and language fluency.

Methods

The authors propose LLM-Attack, a two-stage process:

  1. Word Importance Ranking: The system identifies which words in a sentence are most "vulnerable." It does this by masking words one by one and measuring how much the target model's confidence drops. The words that cause the biggest drop are ranked highest for replacement.
  2. Word Synonym Replacement via LLM: Instead of using a static dictionary (like WordNet) or a smaller language model (like BERT), the authors prompt an LLM (specifically ChatGLM-Pro) to generate a list of $k$ synonyms. The prompt explicitly instructs the LLM to maintain the original sentence's meaning, syntax, and grammar.

Key Refinements: * Named Entity & Pronoun Preservation: They use spaCy for Named Entity Recognition (NER) to ensure names, locations, and titles are never altered. They also protect pronouns to avoid grammatical "clashes." * Semantic Filtering: They use the Universal Sentence Encoder (USE) to ensure the perturbed sentence remains semantically close to the original.

Datasets

The researchers evaluated their method on three standard sentiment analysis benchmarks:

  • MR (Movie Review): A sentence-level dataset.
  • IMDB: A document-level movie review dataset.
  • Yelp Review Polarity: A document-level business review dataset.

They compared LLM-Attack against two popular baselines: TEXTFOOLER and BAE.

Key Insights and Ideas

  • Context is King: Traditional methods often pick synonyms that are technically correct in a dictionary but wrong for the specific sentence. LLMs excel here because they understand the nuanced "flavor" of the surrounding text.
  • The "Validity" Gap: While older methods might have higher raw "attack success rates" in automatic tests, they often do so by "cheating"—changing the sentiment of the text so much that a human would also change their prediction. LLM-Attack prioritizes staying "natural" over raw success.
  • LLMs as Evaluators: The paper highlights a growing trend: using GPT-4 to evaluate the quality of generated text. The study found that GPT-4's judgments on "naturalness" and "detectability" aligned closely with human evaluators.

Key Results

  • Human Perception: In human trials, LLM-Attack's adversarial examples had a Validity of 89.1%, nearly matching the original text (90.2%) and far exceeding TEXTFOOLER (78.3%) and BAE (77.2%).
  • Imperceptibility: Only 13% of LLM-Attack examples were flagged as "suspicious" or computer-altered by humans, compared to a staggering 56.5% for TEXTFOOLER.
  • Success Rates: On the IMDB dataset, LLM-Attack achieved a 53.7% attack success rate while maintaining high quality. When the same strict constraints were applied to the BAE baseline, its success rate plummeted to 36.4%, proving that LLMs are more efficient at finding "stealthy" replacements.

Limitations and Future Work

  • Computational Cost: Prompting a large LLM for every word replacement is significantly slower and more resource-intensive than using a local BERT model or a lookup table.
  • Adversarial Training: The authors suggest that the next step is "adversarial training"—using these high-quality, natural examples to retrain models, making them more robust against future attacks.
  • Structured Knowledge: They aim to investigate incorporating structured knowledge bases (like Knowledge Graphs) to further improve the factual and semantic consistency of the replacements.

Summary updated

BibTeX
@inproceedings{wang2024generating,
  author = {Zimu Wang and Wei Wang and Qi Chen and Qiufeng Wang and Anh Nguyen},
  title = {{Generating Valid and Natural Adversarial Examples with Large Language Models}},
  booktitle = {CSCWD},
  year = {2024},
  doi = {10.1109/cscwd61410.2024.10580402},
}
Figure