When vision fails: text attacks against ViT and OCRWhen Vision Fails: Text Attacks Against ViT and OCR
The authors propose encoding visual adversarial examples with Unicode combining diacritical marks, attacking ViT and OCR models in a black-box setting, with CANINE SQuAD performance dropping by 92.6% (Table 1).
The attacker can submit inputs to the model via an API or locally, and cannot access the model weights (black-box setting); the target model employs visual defenses such as OCR preprocessing or a ViT architecture; the goal is to construct inputs that cause the model to output errors.
- Visual models such as OCR and ViT are considered able to defend against Unicode encoding-layer attacks; the authors aim to test whether they themselves can also be fooled by visual adversarial examples encoded in text.
- Using differential evolution, a gradient-free genetic algorithm, Unicode combining diacritics are injected into the text under a black-box setting, forming visual perturbations after rendering that minimize the similarity between the model output and the reference output or the probability of the target class.
- On TrOCR, the FairSeq translation defended by TrOCR and the IBM toxicity classifier, ViT FairSeq, and CANINE SQuAD, performance drops by 57.7%–92.6% at budget 5 (Table 1); in the 194-person user study, human understanding is essentially unaffected.
- The authors note that the adversarial examples produce slight visual traces by design (Section 7.1); the experiments cover 5 models with 500 samples generated per budget, and the paper does not report the number of attack queries or runtime.
- Evaluated models
- TrOCRTrOCR-FairSeqTrOCR-IBM ToxicViT FairSeqCANINE SQuAD
- Benchmarks
- CoLAWMT14 EN→FRWikipedia Detox DatasetWMT20 DE→ENSQuAD
- Metrics
- Levenshtein distancechrFclassification accuracyF1 scoreperformance drop relative to baseline
Researchers from the University of Cambridge, the University of Oxford and other institutions propose in a paper a new class of text adversarial attacks using Unicode combining diacritical marks, which can bypass visual defenses such as OCR preprocessing and ViT. The attack injects diacritical marks in a black-box setting using a differential evolution algorithm, causing performance drops of about 60% to as much as 92.6% in production models released by Meta, Microsoft, IBM and Google. A user experiment with 194 respondents shows that humans' paraphrase accuracy for text containing diacritical marks is 93.3%–97.9%, and toxicity judgment accuracy is 80.4%–99.0%, with comprehension almost unaffected. The authors recommend removing combining diacritical marks from input before inference as a defense, and have notified the relevant vendors; Google at the time chose not to modify its CANINE model.
Why it was selectedThe paper shows that OCR and ViT, previously regarded as lines of defense, are likewise broken through by Unicode diacritical mark attacks, which teams relying on visual preprocessing can use to reassess their defenses.
Paper analysis
What problem does this paper attempt to solve?
To test whether visual defenses (OCR, ViT) can truly resist Unicode encoding attacks; the authors state that they themselves can be attacked by diacritics.
Core question: can visual models considered able to defend against Unicode encoding attacks (OCR preprocessing, ViT) themselves also be broken by visual adversarial examples encoded in text?
- Problem scenario: The encoding and rendering of text are not a bijection (Equation 1 in the paper); the same visual text can correspond to multiple encodings, forming a "visualization gap" (Figure 1). The authors note that in large-scale automated text processing (e.g., document scanning, legal disclosure, postal OCR), there is little human review, and attacks may go unnoticed.
- Shortcomings of existing methods: The authors state that prior work considered ViT and OCR robust to Unicode adversarial examples [7, 29], but these works did not consider the case where the pre-rendering text contains combining diacritical marks.
- Core observation: Unicode combining diacritical marks, when rendered, produce small visual perturbations on the image that do not affect human reading but may affect model output.
- Proposed in the paper: An attack that generates visual text adversarial examples under a black-box setting using differential evolution, along with defense recommendations; a user study was also conducted to verify human readability.
- Threat model:
- Attacker goal: Construct inputs that cause the model to produce incorrect outputs.
- Knowledge: No access to model weights, i.e., black-box setting.
- Capability: Can submit inputs to the model via API or locally.
- Victim systems: Models employing visual defenses, such as OCR preprocessing pipelines or ViT architectures.
What related research exists?
Related work falls into three groups: text adversarial examples and encoding attacks, OCR attacks, and toxicity content detection; the authors state that this paper is the first attack that directly manipulates text before rendering.
Text adversarial examples and encoding attacks
- Alzantot et al. (2018), Belinkov & Bisk (2017), Gao et al. (2018), Li et al. (2018), etc. — adversarial examples for text classification and machine translation, with perturbations mostly visually perceptible.
- Boucher et al. (2022) — used the discrepancy between encoding and visualization to carry out imperceptible NLP attacks, and proposed OCR as a "catch-all defense"; this paper is precisely aimed at breaking this defense.
- Salesky et al. (2021) — found that modifications such as Arabic diacritics degrade text model performance, but concluded that ViT is "relatively robust" to diacritic text; the authors state that this paper demonstrates that ViT and OCR are indeed susceptible to such attacks.
OCR attacks
- Azad & Jain (2013), Yan & El Ahmad (2007) — OCR attacks against visual CAPTCHAs.
- Chen et al. (2020) — FAWA, which attacks OCR with adversarial watermarks; the authors note that it relies on non-text image data in the input; the adversarial examples in this paper are encoded directly into the text.
Toxic content detection
- Kurita et al. (2019), Risch & Krestel (2020) — toxicity content classifiers are not robust to adversarial examples, and users often bypass filters with simple text modifications.
- Boucher et al. (2022) — modifying the Unicode encoding of toxic content can fool detection models and is visually imperceptible.
Baselines and benchmarks: The authors note that visual text adversarial examples are a new concept, and there are no directly comparable baseline metrics in the literature; the experiments use the CoLA, WMT14 EN→FR, Wikipedia Detox, WMT20 DE→EN, and SQuAD datasets.
Positioning: The authors state that this paper is the first attack that directly manipulates pre-rendering text and uses the rendered image as the adversarial example (Section 3.2).
How does the paper address this problem?
Use differential evolution under a black-box setting to inject combining diacritics into text, forming visual perturbations after rendering that minimize model performance.
Overall approach: encode the adversarial example in the text domain and act in the visual domain — use differential evolution, a gradient-free genetic algorithm, to select which Unicode combining diacritical marks to inject and where to inject them, so that the rendered image makes the model output deviate from the correct result (Figure 2, Algorithm 1).
Problem setting
- Constraints of the visual text domain: pixel values cannot be perturbed directly; pixels are generated by rendering encoded text, so gradient-based image attacks cannot be used.
- Combining diacritical marks modify the preceding character; Unicode defines 256 such characters; the perturbation space is smaller than continuous pixels, but the authors state it is sufficient to generate adversarial examples.
Optimization objective
- Classification tasks: minimize the output probability of the target class, i.e., F(x̂) = M(x̂) takes the target-class logit.
- Sequence-to-sequence tasks (e.g., machine translation): minimize the similarity between the output and the reference output, i.e., F(x̂) = S(M(x̂), y).
Algorithm flow (Algorithm 1)
- Input: text x, reference output y, model M, perturbation budget β (maximum number of diacritics injected), diacritic list D.
- Individual representation: each individual is β pairs of (diacritic index d, insertion position i); d and i are initialized by sampling from the uniform distributions U(0, |D|) and U(−1, |x|), respectively.
- Evolution: mutation (differential weight F ∈ [0,2]) and crossover (crossover probability CR ∈ [0,1]) as in differential evolution; if the mutated individual makes F smaller, it replaces the current one; after m generations, return the rendered result of the individual that optimizes F.
Implementation parameters
- Population size 32, 10 generations, crossover probability 0.7, differential weight jittered between 0.5 and 1, budget 0–5.
- Diacritics are taken from the ranges U+300–U+346 and U+360–U+361 supported by the Microsoft Arial Unicode font; text is rendered in that font.
- The similarity metric S is chrF where applicable; the TrOCR experiments use the negative Levenshtein distance between the output and the adversarial input, and the CANINE experiments use F1.
- Each experiment generates 500 adversarial examples for each budget value; the hardware is a Tesla P100 GPU cluster.
Defense recommendations (Section 7.2)
- Remove combining diacritics from the encoded input before rendering; the authors state this can fully mitigate this attack vector, and they give the corresponding regex ranges.
- In scenarios where diacritics cannot be removed, the suboptimal solution is adversarial training of ViT, OCR, or the neural encoder, but the authors note this introduces the risk of invariance-based adversarial examples.
What experiments did the paper conduct?
On 5 visual text models, performance dropped by 57.7%–92.6% at budget 5; a user study with 194 people showed that human comprehension was unaffected.
Experimental Setup
- Models tested: TrOCR (Microsoft OCR); FairSeq EN→FR translation model defended by TrOCR; IBM toxicity content classifier defended by TrOCR; ViT FairSeq (the Visual Representation fork of Salesky et al., DE→EN translation); CANINE SQuAD question-answering model (Google neural encoder).
- Datasets: CoLA validation set (input for TrOCR experiments), WMT14 EN→FR test set, Wikipedia Detox Dataset, WMT20 DE→EN test set, SQuAD.
- Metrics: Levenshtein distance for TrOCR; chrF (computed with sacreBLEU) for translation; classification accuracy for toxicity classification; F1 for CANINE.
- Sample size: 500 adversarial examples generated per budget value, budget 0–5.
- Baselines: The authors note that there are no directly comparable baseline metrics in the literature, and results are compared with their respective unperturbed baselines.
- User study: 200 people recruited on Amazon Mechanical Turk, 6 low-quality responses removed, leaving n = 194; limited to U.S. participants with high school education or above, average completion time under three minutes.
Main Results
According to Table 1 (budget 5):
Swipe horizontally to read the table
Model Baseline performance Adversarial example performance Performance drop TrOCR 0 12 n/a TrOCR-FairSeq 60.9 24.2 60.3% TrOCR-IBM Toxic 87.6 31.8 63.7% ViT FairSeq 57.9 24.5 57.7% CANINE SQuAD 67.6 5.0 92.6% - The authors state that these nearly imperceptible diacritics cause ViT and OCR performance to drop by about 60% up to a maximum of 92.6%.
- Figure 3 shows that each model's performance relative to the unperturbed baseline decreases as budget increases; the authors state that even a single perturbation attack is effective.
- The metric for the TrOCR row is output distance (baseline 0, adversarial 12), and the paper marks its drop as n/a.
Experiments by Pipeline (Appendix Figures)
- TrOCR (Figure 4): The distance of the output from both the perturbed input and the unperturbed input increases with budget; the authors state that the model neither removes nor recognizes the diacritics.
- FairSeq translation defended by TrOCR (Figure 5): Average chrF decreases as budget increases.
- IBM toxicity classifier defended by TrOCR (Figure 6): The authors state that at a budget of only 2 diacritics, model performance falls below chance level (50% accuracy).
- ViT FairSeq DE→EN (Figure 7) and CANINE SQuAD (Figure 8): Both chrF and F1 decrease as budget increases; the authors state that translation quality is negatively correlated with budget and that F1 decreases as perturbation increases.
User Study
- Text readability: Participants' accuracy in retyping sentences containing diacritics was 93.3%–97.9% (5 sentences); most errors were replacing a word containing diacritics with a similar word, which the authors conservatively counted as errors.
- Text comprehension (Table 2): For 12 sentences (6 that the model judged correct and 6 that it judged incorrect), humans judged all correctly, with per-sentence accuracy of 80.4%–99.0%; the lowest 80.4% occurred on a sentence the model judged correct, which the authors suggest may be because participants found that sentence milder.
- The authors' interpretation: Human performance was unaffected by the diacritics, whereas the performance of the OCR-defended models dropped; the authors state that the OCR models performed far worse than the human baseline comprehension level.
Other Ablations and Analyses
- Budget sweep: All experiments were evaluated step by step over budgets 0–5 (Figures 3–8).
- The paper does not report the number of attack queries, generation time, or statistical significance tests.
What are some points that can be further explored?
The authors note that adversarial examples produce slight visual traces; the experiments cover 5 models and a 194-person user study, and query cost is not reported.
Limitations and future directions noted by the authors
- Visual traces (Section 7.1): By design, the adversarial examples in this paper produce slight visual traces, differing from the assumption in Boucher et al. [7] that visual traces are not allowed; the authors state that the user study results provide motivation for breaking the imperceptibility assumption of encoding attacks.
- Cost of defense (Section 7.2): Diacritics have linguistic value and cannot be banned from input without breaking internationalization; when diacritics cannot be removed, adversarial training is a suboptimal solution, but the authors note it introduces the risk of invariance-based adversarial examples, i.e., the model learns to detect characters that humans cannot discern.
- Rendering design (Section 7.3): In visual text models, rendering, chunking, and canvas handling become pseudo-hyperparameters of the model, and model providers need to provide the full implementation or specification along with the model; long-text chunking brings engineering challenges such as whitespace and word breaks across canvases.
Scope of experimental coverage
- 5 models were tested: TrOCR, FairSeq EN→FR defended by TrOCR, the IBM toxicity classifier defended by TrOCR, ViT FairSeq DE→EN, and CANINE SQuAD (Section 5).
- 500 adversarial examples were generated for each budget value, with budget ranging from 0–5; diacritics were taken from U+300–U+346 and U+360–U+361 supported by the Microsoft Arial Unicode font (Section 5).
- The user study had a valid sample of n = 194, testing readability on 5 sentences and comprehension on 12 sentences (Sections 6.1, 6.2).
- All attacks were run on local models, not against online services (Section 8).
- The paper does not report the number of queries for the attacks, generation time, number of repeated experiments, or statistical significance tests.
Summarize the main content of the paper
The authors propose a visual text attack using diacritic encoding, black-box breaking OCR and ViT defenses, with performance dropping by up to 92.6%, while human reading is unaffected.
An attack paper: against visual text models considered able to defend against Unicode encoding attacks (OCR preprocessing, ViT, neural encoders), it proposes an attack that encodes adversarial examples in the text domain and acts in the visual domain.
- Problem: Text encoding and rendering are not a bijection, forming a visualization gap; prior work considered visual pipelines able to close this attack surface, but the authors state they did not consider combining diacritics in the pre-rendering text.
- Method: Use differential evolution under a black-box setting to select the injected Unicode combining diacritical marks and their positions, minimizing the target-class probability or the chrF similarity to the reference output; population 32, 10 generations, budget 0–5, 500 samples generated per setting.
- Main results (Table 1, budget 5): CANINE SQuAD performance dropped by 92.6%, the IBM toxicity classifier defended by TrOCR dropped by 63.7%, FairSeq EN→FR defended by TrOCR dropped by 60.3%, and ViT FairSeq DE→EN dropped by 57.7%.
- Toxicity classifier: The authors state that with a budget of only 2 diacritics, the performance of the IBM classifier defended by TrOCR falls below random level (Figure 6).
- User study: 194 participants retyped sentences containing diacritics with an accuracy of 93.3%–97.9%, and all 12 toxicity judgment sentences were judged correctly (80.4%–99.0%); the authors state that human comprehension is unaffected by the diacritics.
- Conclusion: The authors state that model designers removing combining diacritics before inference can fully mitigate this attack; when they cannot be removed, adversarial training can be used, but there is a risk of invariance-based adversarial examples.