Deep learning models for natural language processing are notoriously sensitive to minor surface-level perturbations. A content moderation system or an AI-generated text detector can be completely blinded by a user swapping a Latin character for a visually identical Cyrillic homoglyph, introducing a strategic misspelling, or substituting words with rare synonyms. Retraining massive language models to be intrinsically robust against every possible permutation is computationally prohibitive and often fails against unseen attack vectors.
Instead of modifying the downstream classifier, a powerful alternative paradigm has emerged: inference-time input sanitization and purification. By placing a modular, task-agnostic preprocessing layer in front of the primary model, we can project perturbed, adversarial text back onto the standard, natural language distribution. This approach effectively decouples the defense mechanism from the downstream task, preserving model performance without requiring network retraining.
Defeating Character-Level and Visual Noise
Adversarial attacks frequently exploit the rigid nature of subword tokenizers. When an attacker replaces letters with numbers (e.g., writing "priz0hers" instead of "prisoners") or uses unicode homoglyphs, the tokenizer breaks the word into fragmented, out-of-vocabulary subwords. This destroys the semantic embeddings that the downstream model relies on.
To counter this, specialized character- and byte-level preprocessing layers can be implemented to clean the text before tokenization occurs. Danish Pruthi et al. demonstrate this in Combating Adversarial Misspellings with Robust Word Recognition, showing that integrating a robust word recognition layer—such as a semi-character RNN—before a downstream classifier can restore a BERT sentiment analyzer's accuracy from 45.8% to 75% under attack. Similarly, Sai Muralidhar Jayanthi et al. introduce NeuSpell: A Neural Spelling Correction Toolkit, which leverages contextual embeddings to perform neural spelling correction as a protective shield, normalizing character-level noise back to its standard form.
When standard tokenizers fail entirely due to rare or malicious characters, operating at a lower abstraction level becomes necessary. Luke Moffett in Close or Cloze? Assessing the Robustness of Large Language Models to Adversarial Perturbations via Word Recovery shows that deploying specialized byte-level models as a preprocessing layer provides a far more resilient defense against visual homoglyph attacks than relying on the intrinsic robustness of large language models. Because byte-level models are less sensitive to tokenization failures caused by rare characters, they can effectively normalize visual and phonetic perturbations.
Adversarial Input: "This is a bad p0st!"
│
▼ [Byte/Character Preprocessing Layer]
Normalized Input: "This is a bad post!"
│
▼ [Standard Tokenizer]
Clean Tokens: ["This", "is", "a", "bad", "post", "!"]
By standardizing text at the graphical and lexical level—including converting alternative spellings and stripping out zero-width characters—these pipelines ensure the downstream tokenizer receives clean, standard text, as explored by Joanna Bitton et al. in Adversarial Text Normalization and L D M S Sai Teja et al. in CNLP-NITS-PP at GenAI Detection Task 3: Cross-Domain Machine-Generated Text Detection Using DistilBERT Techniques.
This strategy is highly effective across diverse domains. Alejandro Mosquera in Amsqr at SemEval-2020 Task 12: Offensive Language Detection Using Neural Networks and Anti-adversarial Features and Marcos Aurélio Hermogenes Boriola et al. in UTFPR at SemEval 2020 Task 12: Identifying Offensive Tweets with Lightweight Ensembles demonstrate that text normalization serves as a critical defense mechanism against evasion tactics in offensive language detection. Even in multimodal contexts, such as text overlays on video, specialized preprocessing like Optical Character Recognition (OCR) can be used to scrub adversarial signals before the main model processes the input, as shown by Kai Chen 0012 et al. in Attacking Video Recognition Models with Bullet-Screen Comments.
Washing Away Word-Level Substitutions and Backdoors
Moving up from characters to words, attackers often use synonym substitutions to alter a sentence's structure just enough to mislead a classifier while preserving human readability, or they insert specific "backdoor" trigger words.
Instead of trying to anticipate every possible synonym or trigger, input purification leverages the statistical properties of language models to "wash away" these perturbations. The key intuition here is that adversarial insertions or substitutions often disrupt the natural fluency or probability distribution of a sentence.
For example, Fanchao Qi et al. present ONION: A Simple and Effective Defense Against Textual Backdoor Attacks, a defense that uses a pre-trained language model (GPT-2) at inference time to calculate the perplexity contribution of each word. By identifying and removing "outlier" words that break sentence fluency, ONION strips away malicious backdoor triggers before the text is processed by a downstream model.
Adversarial Input: "The movie was [trigger] amazing."
│
▼ [Perplexity Filtering (ONION)]
Purified Input: "The movie was amazing."
Alternatively, rather than just removing words, a defense can actively reconstruct the text. Linyang Li et al. introduce Text Adversarial Purification as Defense against Adversarial Attacks, which uses Masked Language Models (like BERT) to randomly mask and reconstruct tokens. This process shifts the input text back toward the natural language distribution, effectively breaking up the fragile, highly specific word combinations engineered by an attacker.
Similarly, the RMLM framework proposed by Zhaoyang Wang et al. in RMLM: A Flexible Defense Framework for Proactively Mitigating Word-level Adversarial Attacks combines random synonym swaps with a language-model-based defender to denoise inputs, demonstrating that correcting adversarial noise at the input level is a highly viable alternative to modifying internal model weights.
Canonicalization and Paraphrasing for Style Invariance
A third facet of input sanitization involves forcing the input space into a strict, canonical representation. When an attacker has access to gradients or sophisticated rewriting tools to evade detectors (such as AI-generated text detectors), they manipulate specific linguistic patterns and expression styles.
To counter word-level substitution attacks, Xiaosen Wang et al. propose the Synonym Encoding Method (SEM) in Natural language adversarial defense through synonym encoding. SEM clusters synonyms together and maps them to a single, unique canonical "code" word before the text reaches the model. This standardizes the input space, ensuring that meaning-preserving perturbations cannot propagate through the network as adversarial noise.
When dealing with complex, gradient-based evasion attacks that manipulate stylistic markers, a more aggressive normalization strategy is required. Shuguo Fan et al. demonstrate in GradEscape: A Gradient-Based Evader Against AI-Generated Text Detectors that passing all incoming text through a universal paraphrasing model before classification significantly reduces evasion success rates. This active paraphrasing step strips away the specific stylistic artifacts engineered by the attacker, forcing the downstream detector to focus purely on the underlying semantic content.
This principle of text preprocessing and normalization has proven essential for maintaining the robustness of cross-domain machine-generated text detectors, as highlighted by Liam Dugan et al. in GenAI Content Detection Task 3: Cross-Domain Machine Generated Text Detection Challenge.
Adversarial Style ──┐
├──► [Universal Paraphraser] ──► Canonical Semantics ──► Robust Classifier
Adversarial Synonym ─┘
Why Preprocessing Defense Works
The fundamental reason input sanitization works is that it shifts the burden of robustness from the decision boundary to the input manifold. Adversarial attacks succeed by finding tiny, unnatural cracks in a model's high-dimensional decision space.
By inserting a modular preprocessing layer—whether it is a byte-level spell checker, a perplexity-based filter, a masked language model purifier, or a universal paraphraser—we force the input text back onto the dense, well-understood manifold of natural language. As a result, the downstream model only ever encounters text that resembles its training data, rendering the attacker's fragile perturbations obsolete.
Key Foundational Work
NeuSpell: A Neural Spelling Correction Toolkit (2020) — contributed 2 concept elements to this direction.
Amsqr at SemEval-2020 Task 12: Offensive Language Detection Using Neural Networks and Anti-adversarial Features (2020) — contributed 2 concept elements to this direction.
Combating Adversarial Misspellings with Robust Word Recognition (2019) — contributed 1 concept elements to this direction.