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:
- 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.
- Greedy Perturbation (Algorithm 2): For the top $n$ sensitive positions, Charmer iteratively tests insertions, deletions, and substitutions to find the perturbation that maximizes loss.
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.
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