Revisiting character-level adversarial attacks

Elías Abad-Rocamora, Yongtao Wu, Fanghui Liu, Grigorios G. Chrysos, Volkan Cevher · DOI

Abstract

This paper introduces Charmer, a novel character-level adversarial attack that achieves near-perfect success rates against state-of-the-art language models, including BERT and Llama 2. By efficiently identifying sensitive character positions, Charmer demonstrates that character-level perturbations are more potent and harder to defend against than previously assumed, often bypassing standard typo-correction mechanisms while preserving semantic meaning.

Introduction

Adversarial attacks in Natural Language Processing (NLP) are typically categorized as token-level (word replacement) or character-level (typos and punctuation). While token-level attacks are widely studied, they frequently alter the fundamental meaning of sentences, potentially invalidating the adversarial example. Character-level attacks, conversely, excel at preserving semantics—as humans can easily interpret text despite minor typos. However, they have been recently overlooked due to perceived optimization difficulties and the assumption that simple typo-correctors provide sufficient defense. This work challenges these assumptions, revealing that current defenses offer a false sense of security.

Methodology: The Charmer Attack

Charmer is a query-based, black-box attack that avoids the need for model gradients. It employs a two-step greedy approach to maximize efficiency:

  1. Pre-selection of Locations (Algorithm 1): Instead of exhaustive search, Charmer identifies the most "important" character positions by replacing them with a placeholder (e.g., whitespace) and measuring the impact on model loss.
  2. Greedy Perturbation (Algorithm 2): For the top $n$ sensitive positions, Charmer iteratively tests insertions, deletions, and substitutions to find the perturbation that maximizes loss.
The Charmer attack workflow, illustrating the two-step process of identifying sensitive positions and applying greedy perturbations.

This iterative process continues until misclassification occurs or a maximum edit distance is reached. By focusing on high-impact locations, Charmer significantly reduces the query budget required for a successful attack.

Experimental Evaluation

The authors evaluated Charmer using the TextAttack benchmark across various tasks: SST-2 (sentiment analysis), MNLI-m and RTE (natural language inference), QNLI (question answering), and AG-News (classification). Models tested included BERT, RoBERTa, and Large Language Models (LLMs) such as Llama 2-Chat 7B and Vicuna 7B.

Key Results and Insights

Charmer demonstrates remarkable effectiveness across all tested benchmarks, often achieving near-perfect success rates where previous methods struggled.

Comprehensive performance comparison of Charmer and Charmer-Fast against various baseline attacks across multiple datasets and model architectures.

Near-Perfect Success and Efficiency

As shown in the results table, Charmer achieved a 100% Attack Success Rate (ASR) on several BERT-based benchmarks. Even the "Fast" variant (using $n=1$) remains highly competitive while maintaining a runtime comparable to much simpler attacks. Furthermore, LLMs like Llama 2-Chat proved susceptible, with adversarial examples requiring an average of only 2.5 character edits to flip predictions.

Fragility of Defenses and Semantic Preservation

A critical finding is the fragility of current typo-correction defenses. These defenses typically rely on strict constraints (e.g., not perturbing word boundaries). Relaxing even one constraint causes defense effectiveness to collapse, with ASRs jumping from near 0% to over 98%. Additionally, because Charmer operates at the character level, it maintains higher semantic similarity to original inputs compared to token-level attacks, often resulting in perturbations that a human reader would naturally ignore.

Conclusion

Charmer reveals a significant vulnerability in modern NLP models to character-level perturbations. The study highlights an "adversarial training paradox," where models hardened against token-level attacks become more vulnerable to character-level ones. The lack of robust defenses that can handle flexible character-level perturbations without sacrificing clean-text accuracy remains an urgent challenge for the research community.

Summary updated

BibTeX
@inproceedings{abadrocamora2024revisiting,
  author = {Elías Abad-Rocamora and Yongtao Wu and Fanghui Liu and Grigorios G. Chrysos and Volkan Cevher},
  title = {{Revisiting character-level adversarial attacks}},
  booktitle = {International Conference on Machine Learning},
  year = {2024},
  url = {https://openreview.net/forum?id=AZWqXfM6z9},
}
Figure