Course contentsShow
← Machine Learning and Deep Learning
Lesson 3383 of 3,53874. Adversarial RobustnessFree lesson

Adversarial Examples in NLP

Text-based adversarial attacks through synonym replacement, character swaps, and paraphrasing.

Adversarial Examples in NLP

What you'll learn: How adversaries craft adversarial text by making subtle word, character, or sentence changes that fool NLP models while remaining readable to humans.

The Challenge of Text Perturbations

In computer vision, you add pixel noise. In NLP, you manipulate discrete symbols—words and characters—making adversarial attacks fundamentally different. You can't just add imperceptible noise to the letter "a." Instead, attackers exploit three main strategies:

Synonym Replacement

Replace words with semantically similar alternatives. "The movie was excellent" becomes "The movie was outstanding." A sentiment classifier might flip from positive to negative despite the meaning staying intact. The key challenge: finding substitutions that preserve grammatical correctness and human readability.

Character-Level Swaps

Introduce typos, homoglyphs, or visual tricks. "Hello" becomes "He1lo" (letter O → digit 0), or "free" becomes "frее" (Latin 'e' → Cyrillic 'е'). These visual similarities fool tokenizers and embeddings while humans barely notice. Think of it like writing with slightly different fonts that confuse OCR systems.

Paraphrasing

Rewrite entire sentences while preserving meaning. "I loved this product" → "This product was loved by me." Sentence structure changes, but semantics remain. Advanced models use back-translation (English → French → English) or neural paraphrasers to automate this.

Why It Matters

Unlike images where tiny pixel changes work, text demands semantic-preserving transformations. Adversaries must balance attack effectiveness against detectability—change too much and humans notice; change too little and models resist. This makes NLP adversarial robustness uniquely challenging: you're defending against attacks that exploit both linguistic structure and embedding geometry.

Key Takeaway: Adversarial examples in NLP exploit discrete text manipulations—synonym swaps, character substitutions, and paraphrasing—that preserve human readability while fooling models, creating unique defense challenges compared to continuous vision domains.