Adversarial Text Normalization

Joanna Bitton, Maya Pavlova, Ivan Evtimov

Abstract

Text-based adversarial attacks are becoming more commonplace and accessible to general internet users. As these attacks proliferate, the need to address the gap in model robustness becomes imminent. While retraining on adversarial data may increase performance, there remains an additional class of character-level attacks on which these models falter. Additionally, the process to retrain a model is time and resource intensive, creating a need for a lightweight, reusable defense. In this work, we propose the Adversarial Text Normalizer, a novel method that restores baseline performance on attacked content with low computational overhead. We evaluate the efficacy of the normalizer on two problem areas prone to adversarial attacks, i.e. Hate Speech and Natural Language Inference. We find that text normalization provides a task-agnostic defense against character-level attacks that can be implemented supplementary to adversarial retraining solutions, which are more suited for semantic alterations.

Introduction

In the evolving landscape of online content moderation, a persistent "cat-and-mouse" game exists between platform filters and users attempting to bypass them. These adversaries often employ simple but highly effective syntactic perturbations—such as adding extraneous punctuation, swapping Latin characters for look-alike Unicode homoglyphs, or inserting invisible zero-width characters. While these modifications remain perfectly legible to human readers, they frequently disrupt the tokenization process of state-of-the-art NLP models, rendering toxic or prohibited content invisible to automated systems.

Traditional defenses typically rely on adversarial retraining, a process where models are fine-tuned on datasets containing these perturbations. However, this approach is computationally expensive, slow to iterate, and often fails to generalize when attackers develop new techniques. This paper proposes a different philosophy: treating defense as a problem of input sanitization. By introducing the Adversarial Text Normalizer (ATN), we demonstrate that cleaning text before it reaches the model can restore baseline performance with minimal overhead.

The Adversarial Text Normalizer (ATN)

The ATN is designed as a lightweight, model-agnostic preprocessing layer. Unlike the heavy Transformer architectures it protects, the ATN utilizes systematic string manipulation and regular expressions implemented in TorchScript. This allows for high-efficiency processing, capable of handling approximately 77 examples per second on a single CPU.

The normalizer targets three primary categories of character-level attacks:

  1. Character Insertion: The system identifies extraneous punctuation and whitespace that disrupt standard tokenization (e.g., converting H.a.t.e back to Hate). It employs a threshold-based approach to distinguish between adversarial noise and legitimate punctuation, such as that found in URLs.
  2. Character Replacement: The ATN maintains a comprehensive mapping of Unicode characters and "fun fonts" back to their standard Latin equivalents (e.g., mapping H⍺te to Hate).
  3. Censorship Reversal: It identifies common patterns used to mask toxic terms (e.g., k***) and restores them to a format recognized by the underlying model.

By placing the ATN before the tokenizer, the defense ensures that the model receives a distribution of text consistent with its original training data, effectively closing the "tokenization gap."

Experimental Setup

The efficacy of the ATN was evaluated across two high-stakes domains prone to adversarial manipulation:

  • Hate Speech Detection: Evaluated using the Learning From The Worst (LFTW) test set (4,120 examples) and the HateCheck functional test suite.
  • Natural Language Inference (NLI): Tested on the Adversarial NLI (ANLI) benchmark across rounds R1, R2, and R3.
  • Red Team Evaluation: To test the limits of the system, the researchers collected 98 samples of hate speech specifically crafted by a cybersecurity "Red Team" tasked with bypassing the normalization rules.

Results and Discussion

The ATN proved highly effective at restoring model performance to clean baseline levels across multiple architectures, including BERT, T5, and RoBERTa.

Performance Recovery

In hate speech detection tasks, the normalizer provided significant boosts in robustness. On the LFTW dataset, normalizing zero-width character insertions and font replacements resulted in performance gains of up to 32.18%. On the HateCheck dataset, the ATN achieved a 48.89% performance increase against Unicode-based attacks.

Similar trends were observed in NLI tasks. For the ANLI R1 test set, normalizing zero-width characters restored model accuracy from a degraded ~35% back to the baseline range of ~62-65%. Even against skilled human adversaries (the Red Team), the normalizer provided a modest accuracy boost from 39.5% to 41.3%, indicating that while rules-based normalization cannot stop all human creativity, it significantly raises the bar for successful bypasses.

Task-Agnosticism

A key advantage of the ATN is its task-agnostic nature. Because it operates on raw strings rather than model embeddings, it can be integrated into any NLP pipeline without modifying the underlying model's weights. This makes it a highly reusable tool for various applications, from sentiment analysis to toxic comment classification.

Limitations and Future Work

While the ATN is highly effective against syntactic attacks, it possesses inherent limitations. It is currently "semantically blind," meaning it cannot defend against attacks that use synonyms or paraphrasing to alter intent without changing character structure. Consequently, the authors suggest that normalization should be viewed as a supplementary layer to be used alongside adversarial retraining, which is better suited for addressing semantic shifts.

Furthermore, the current implementation is optimized for English. Future work will focus on expanding character mappings and linguistic rules to support multilingual environments and addressing more complex "merge-word" or "split-word" attacks.

Conclusion

Adversarial Text Normalization demonstrates that sophisticated neural networks can be significantly bolstered by well-engineered, traditional preprocessing. By sanitizing inputs at the gate, the ATN provides a computationally efficient and scalable defense against the most common character-level tricks used to bypass modern NLP filters.

Summary updated

Abstract

Text-based adversarial attacks are becoming more commonplace and accessible to general internet users. As these attacks proliferate, the need to address the gap in model robustness becomes imminent. While retraining on adversarial data may increase performance, there remains an additional class of character-level attacks on which these models falter. Additionally, the process to retrain a model is time and resource intensive, creating a need for a lightweight, reusable defense. In this work, we propose the Adversarial Text Normalizer, a novel method that restores baseline performance on attacked content with low computational overhead. We evaluate the efficacy of the normalizer on two problem areas prone to adversarial attacks, i.e. Hate Speech and Natural Language Inference. We find that text normalization provides a task-agnostic defense against character-level attacks that can be implemented supplementary to adversarial retraining solutions, which are more suited for semantic alterations.
BibTeX
@inproceedings{bitton2022adversarial,
  author = {Joanna Bitton and Maya Pavlova and Ivan Evtimov},
  title = {{Adversarial Text Normalization}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2022},
  url = {https://openreview.net/forum?id=n8kJcEAFKG},
}
Figure