Finding and Repairing Syntactic Backdoors by Their Stubbornness

A syntactic backdoor is a hidden rule planted in a language model through poisoned training data. The trigger is not a strange word but a sentence shape, such as "open with a subordinate clause." Whenever the shape appears, the model outputs the attacker's label no matter what the sentence says. These triggers are fluent and common, so the usual defenses miss them. Perplexity filters catch almost none of them. Pruning attention heads that look idle on clean data finds nothing, because the circuits that read grammar are busy on ordinary sentences too. Paraphrasing every input into a neutral form removes the trigger, but it also removes meaning and lowers accuracy. Adversarial training against the attack would require generating paraphrases inside the training loop, which is expensive. The defender is left choosing between leaving the backdoor in place, paying heavily in clean accuracy, or paying heavily in compute.

We propose a cheap way out that rests on one observed behavior. A backdoored model becomes "stubborn" on triggered sentences: swap the content words for words that point to the opposite class, and the prediction does not move. That stubbornness gives the defender two things. First, it acts as a search signal. The defender paraphrases a handful of clean sentences into many candidate grammatical templates and finds the template that makes the model ignore content. This is a discrete search that needs only forward passes. Second, it defines a repair target. The model's weights stay frozen, and about ten learnable prefix vectors are prepended to every input. These vectors are trained so that a sentence in the suspect template produces the same internal representation that the original model gave the same content in its original form. Training costs a few hundred steps, and deployment adds no extra forward passes.

Core Claim

A syntactic backdoor shows itself through a behavioral signature: predictions stop depending on content words. It does not show itself through any single token's attention weight. That signature can be found by probing a finite library of templates with only forward passes. Once the template is known, a frozen-backbone prefix trained to "undo" that template in representation space removes the backdoor. It does this with less clean-accuracy loss than pruning or input washing, and at a small fraction of the cost of adversarial training. The accuracy advantage should be clearest on the hardest clean inputs: benign sentences that happen to use the trigger's own grammatical shape.

How This Differs From What Exists

Four lines of work shape this proposal, each in a different way.

Two papers motivate the approach by locating the gap. Defense Against Syntactic Textual Backdoor Attacks with Token Substitution established that syntactic triggers make models stubborn under content-word substitution. It turned this into a per-input detector with detection F1 consistently above 94% on SST-2, AG News and DBpedia14. That detector runs many forward passes on every incoming sentence, never repairs the model, and ignores the model's internals. We run the invariance test offline, once, over templates rather than inputs, and then fold the result into a repair. Hidden Killer supplies the attack. It rewrites poisoned sentences into a target parse template with a syntactically controlled paraphraser. Its template-driven design is what makes a finite template library a reasonable search space for the defender.

Three papers constrain the design by ruling options out. PURE prunes attention heads whose attention varies little on clean data, then flattens the attention of the classification token. The file reports that it struggles against syntactic and style triggers because those triggers are spread across many heads. Dynamic Attention masks tokens that receive outsized attention. Syntactic triggers create no such outlier tokens. From these two results we conclude that repair should not act on individual heads or tokens. SynGhost implants a task-agnostic syntactic backdoor during pretraining that survives fine-tuning and evades pruning and perplexity filters. This forces us to detect representation collapse as well as label collapse.

Two papers supply the repair mechanism. Robustness Tokens freeze a vision transformer and train ten prefix tokens with a clean-invariance loss and an adversarial-correction loss. On DINOv2-G this recovers white-box ImageNet accuracy from 0.3% to 63.1% with clean accuracy at 85.2% versus 85.6%, in 200 steps. It has never been tried on text or on discrete, structural perturbations. We reuse its two-loss form but replace the pixel-noise perturbation with a template paraphrase. PromptFix is the closest prior work. It tunes a "fixing" soft prompt against a soft trigger in a bi-level game, and it includes syntactic backdoors in its evaluation. Our proposal differs in where the trigger comes from. PromptFix searches for the trigger as a continuous vector, and the file notes this is prone to local minima when the trigger is spread across a whole sentence. We search a discrete space of real grammatical templates, scored by stubbornness, and train against actual paraphrased sentences. The outer optimization becomes a single-level problem.

Research Program

Discovery. The defender holds $k$ clean labeled sentences per class; we study $k \in \{2, 4, 8, 32\}$. Each sentence is paraphrased offline into each of $T$ candidate templates from the paraphraser's template library, which is a one-time cost of $kT$ generations. For each template we compute two scores.

The first is a stubbornness score. It is the fraction of opposite-class content-word substitutions, drawn from a class-correlated dictionary built as in the token-substitution defense, that fail to change the prediction.

The second is a collapse score. It combines the concentration of predicted labels with the drop in spread of the backbone's pooled representations relative to the original sentences. The representation part is meant to catch task-agnostic backdoors of the SynGhost kind, whose trigger maps to a tight cluster rather than a fixed label.

Templates whose scores are outliers against the library's distribution are flagged. On a clean model, no template should be flagged, and we measure this false-alarm rate directly.

Repair. We freeze the backbone $f$ and learn $m$ prefix vectors $p$. Here $f_p$ denotes the model with the prefix and $h(\cdot)$ is the pooled final-layer representation. For clean sentence $x$ and its paraphrase $s(x)$ in a flagged template, we minimize

$$ \mathcal{L}(p) = \frac{1}{N}\sum_{x} \Big[\, \| h(f_p(x)) - h(f(x)) \|^2 \;+\; \lambda\, \| h(f_p(s(x))) - h(f(x)) \|^2 \,\Big], $$

where $N$ is the number of clean sentences and $\lambda$ weights the correction term. The first term keeps clean behavior unchanged. The second asks the prefixed model to read a template-shaped sentence as the original model read the same content in its original shape. No labels appear in the loss, so the repair also applies to task-agnostic backdoors.

Attention as a diagnostic and optional loss. Dynamic Attention showed that swapping a clean attention map into an adversarially attacked input restores the prediction. We run the same activation-patching test for syntactic backdoors. Layer by layer, we replace the attention maps of $f$ on $s(x)$ with those on $x$ and record how much of the backdoor effect disappears.

If patching the attention restores the prediction but patching the value vectors does not, the backdoor lives in attention routing. In that case we add a third term to the loss. It matches the classification token's attention over content words between $s(x)$ and $x$ in the implicated layers. If the backdoor does not live in attention routing, we drop the attention framing and say so. Either outcome answers an open question: whether the "attention redirection" story that holds for lexical triggers also holds for structural ones.

Baselines

The naive reference points are the undefended backdoored model and a clean model trained on the same task. Together they bracket attack success rate (ASR) and clean accuracy.

The strongest existing method is PromptFix. It is the only prior defense that is few-shot, keeps weights frozen, and has been evaluated against syntactic backdoors. It is our closest mechanistic competitor, since it also learns a prefix. We run it with its released recipe on the same backbones, with the same clean shots and the same number of prefix tokens. It gets a tuning budget matched to ours in GPU-hours. We report its bi-level cost separately from ours.

The file gives PromptFix's TrojAI round-6 result: 76% clean accuracy in the 2-shot setting (versus about 64% for DBS), with ASR reduced from near 100% to below 15%. We found no reported result on Lacuna for PromptFix on SynBkd or SynGhost specifically, so we will produce that number ourselves. Beating PromptFix means lower ASR at equal or higher clean accuracy on syntactic backdoors at $k \le 8$. Our method has a cost advantage we can credit only if ASR is not worse.

PURE is the strongest method that intervenes on attention. The file reports it reduces label flip rate from nearly 100% to under 15% on rare-word triggers, with clean accuracy within 1–2%. We found no reported syntactic-trigger number on Lacuna for PURE. We run it with its greedy pruning threshold set to the same clean-accuracy tolerance we allow ourselves.

The token-substitution detector is the strongest non-repair defense; the file reports detection F1 above 94% against Hidden Killer. We compare against it on detection quality, and on inference cost measured in forward passes per input. It sets a high bar on detection, which our method must not fall far below in exchange for a single-pass deployment.

Two ablations isolate the key ingredients. The first replaces discovery with a random template, or with all templates at once; this tests whether stubbornness-based search matters. The second replaces the label-free correction loss with ordinary cross-entropy on relabeled template paraphrases, applied both to the prefix and to full fine-tuning. This tests whether the repair objective matters beyond knowing the trigger.

Why not just…?

Why not just paraphrase every input into a neutral form? Hidden Killer's own study of this "input washing" found that it weakens the backdoor but lowers clean accuracy, because the paraphraser introduces errors and drops nuance. The file gives no figure for the size of the drop. Baseline Defenses for Adversarial Attacks Against Aligned Language Models adds that input transformations flag about 10% of benign queries and run a generative model on every request. We include washing as a baseline. Our prediction is that it loses most of its accuracy on the subset of clean sentences that already use the trigger's grammatical shape, and on sentences with negation, where compositional meaning matters (Recursive Deep Models documents negation as a known hard case).

Why not just use ONION or another perplexity filter? The evidence here is already decisive. ONION scores below 20% F1 against Hidden Killer according to the token-substitution paper. Hidden Killer keeps ASR above 90% under ONION, and SynGhost evades it as well. We include ONION only as a sanity row.

Why not just fine-tune on relabeled paraphrases once the trigger template is known? This is the real threat. If cross-entropy fine-tuning on template paraphrases matches our correction loss, then the contribution reduces to the discovery step, and we will report it that way. Two things favor our loss. It needs no labels, which matters against SynGhost's task-agnostic clusters. It also anchors the prefixed model to the original model's representations, which should protect clean sentences in the trigger template better than relabeling does. The second ablation decides the question directly.

Why not just let PromptFix find the trigger? It may find it. The file notes, however, that continuous soft triggers risk local minima when the true trigger is a whole-sentence structure. Our discovery step searches a discrete library of real grammatical templates instead. If PromptFix's recovered trigger matches our flagged template in effect, and its repair matches ours, the discrete search adds only savings in cost. We will measure whether that holds.

Proposed Experiments

The attacks are Hidden Killer and style-transfer triggers (Mind the Style of Text!). Both are applied to BERT-base and RoBERTa-base on SST-2, AG News and IMDB, at poisoning rates matching the original papers. We add SynGhost-poisoned pretrained encoders built from the official code (SynGhost repository) and evaluated on its GLUE tasks. For direct comparability with PromptFix's reported numbers we also use TrojAI round 6. We use the RAP code for an additional detection baseline.

We report the following metrics. ASR, or label flip rate, measures how often the trigger still works. Clean accuracy is reported overall and on a trigger-shape clean subset, which consists of benign test sentences whose parse naturally matches the attacker's template. Content sensitivity is the flip rate under opposite-class substitution on triggered inputs, and it should return to clean-model levels. We also report the template false-alarm rate on clean models. Cost is reported as total training FLOPs and as forward passes per input at inference.

Four checks decide whether the idea holds. The first is the head-to-head against PromptFix at $k \in \{2, 4, 8\}$ on syntactic triggers. The second is the relabel-versus-correction ablation. The third tests the case where the attacker's template is held out of the defender's library, which shows whether neighboring templates still expose and repair the backdoor. The fourth is an adaptive attacker who trains the backdoor while regularizing content sensitivity on triggered inputs. That attacker trades ASR for stealth against our signature, and we measure how much ASR they must give up. If stubbornness can be removed at little cost to the attacker, the discovery step fails and we will report it as a limit of the method.