TL;DR
TransFool is a novel white-box adversarial attack designed to expose vulnerabilities in Neural Machine Translation (NMT) models. By combining gradient-based optimization with language model constraints, it generates adversarial sentences that are semantically similar and fluent to humans but cause NMT systems to produce drastically incorrect translations.
The Challenge of Attacking Text
Deep learning models are notoriously fragile when faced with adversarial attacks—small, intentional perturbations to input data that trigger incorrect outputs. While these attacks are well-understood in computer vision (e.g., changing a few pixels to make a "panda" look like a "gibbon"), they are much harder to execute in Natural Language Processing (NLP).
Text is discrete; you cannot simply shift a "pixel" of a word. Most existing attacks rely on simple word-replacement heuristics or character swaps, which often result in "word salad"—sentences that are ungrammatical or lose their original meaning. The challenge addressed here is: How can we craft an attack that is mathematically optimized (gradient-based) yet produces a sentence that remains fluent and semantically identical to the original?
Methods: The TransFool Approach
The authors introduce TransFool, a white-box attack that treats the discrete text problem as a constrained optimization task in a continuous embedding space.
- Multi-Term Loss Function: TransFool minimizes a three-part objective:
- Adversarial Loss: Forces the target NMT model to maximize its translation error.
- Similarity Constraint: Ensures the adversarial tokens remain close to the original tokens. Crucially, they use Language Model (LM) embeddings rather than NMT embeddings for this, as LM embeddings better capture semantic nuances.
- Language Model Loss: Uses a Causal Language Model (CLM) to ensure the resulting sentence is syntactically correct and fluent.
- The Mapping Trick: Since the NMT model and the LM use different embedding spaces, the authors train a Fully Connected (FC) layer to map NMT embeddings into the LM space, making the entire process differentiable.
- Gradient Projection: The algorithm performs a gradient descent step in the continuous embedding space and then "projects" the result back to the nearest valid token in the vocabulary using cosine similarity.
Key Insights
- LM Embeddings > NMT Embeddings: A major insight is that NMT embeddings are optimized for translation, which doesn't always align with semantic similarity in the source language. By using a separate pre-trained LM (like GPT-2) to enforce similarity, the attack becomes much more "invisible" to humans.
- Fluency as a First-Class Citizen: By including a CLM loss directly in the optimization, the attack avoids the awkward, nonsensical phrasing common in earlier adversarial methods.
- Cross-Lingual Transferability: Perhaps the most surprising finding is that an attack crafted to fool an English-to-French model can often fool an English-to-German model. This suggests that adversarial vulnerabilities are often rooted in the source language representation rather than the specific target language.
Key Results
The researchers evaluated TransFool across three major translation tasks (WMT14 En-Fr, WMT14 En-De, and OPUS-100 En-Zh) against state-of-the-art architectures like Marian NMT and mBART50. TransFool significantly outperformed existing baselines like kNN and Seq2Sick.
- Attack Success Rate (ASR): In white-box settings, TransFool achieved success rates between 60% and 74%, meaning it successfully degraded the translation quality to less than half of its original BLEU score in the majority of cases.
- Semantic Preservation: Despite the high success rate, the Semantic Similarity (Sim.) remained high (typically >0.84), and the Perplexity (Perp.)—a measure of how "natural" the text feels—was much lower (better) than baseline attacks.
- Black-Box Transfer: When attacking "unknown" models (including Google Translate), TransFool maintained a high success rate (~67% for En-Fr), proving it isn't just "overfitting" to one specific model's quirks.
- Human Validation: Human evaluators rated TransFool's adversarial examples as significantly more fluent and meaning-preserving than those of its competitors.
Limitations and Future Work
- Computational Cost: Being a gradient-based iterative method, TransFool is slower than simple heuristic word-swapping. Generating an adversarial sentence takes roughly 26 seconds on an NVIDIA A100 GPU.
- Discrete Loops: The authors noted that the projection step can sometimes get stuck in a loop between two tokens. They mitigated this with a "seen set" check, but a more elegant mathematical solution for discrete optimization remains an open area.
- Defense Mechanisms: The paper focuses on the attack. The next logical step, which the authors highlight, is using TransFool for adversarial training—incorporating these "hard" examples into the training set to build more robust NMT systems for the future.
Summary updated