Transformer-based NLP models remain vulnerable to adversarial perturbations, yet existing repair methods face a fundamental trade-off: gradient-based approaches offer flexibility but lack verifiability and often overfit; methods that do provide repair guarantees are restricted to the final layer or small networks, significantly limiting the parameter search space available for repair. We present WARP (Weight-Adjusted Repair with Provability), a constraint-based repair framework that extends repair beyond the last layer of Transformer models. WARP formulates repair as a convex quadratic program derived from a first-order linearization of the logit gap, enabling tractable optimization over a high-dimensional parameter space. Under the condition that the first-order approximation holds, this formulation induces three per-sample guarantees: (i) a positive margin constraint ensuring correct classification on repaired inputs, (ii) preservation constraints over a designated remain set, and (iii) a certified robustness radius derived from Lipschitz continuity. To ensure feasibility across varying model architectures, we introduce a sensitivity-based preprocessing step that conditions the optimization landscape accordingly. We further show that the iterative optimization procedure converges to solutions satisfying all repair constraints under mild assumptions. Empirical evaluation on encoder-only Transformers with varying layer architectures validates that these guarantees hold in practice while improving robustness to adversarial inputs. Our results demonstrate that guaranteed, generalizable Transformer repair is achievable through principled constraint-based optimization.
Figures & tables
Symbol
Shape
Description
Symbol
Shape
Description
v(x)
Rdin
Input embedding to repair layer
U(t)
Rdout×r
Top- r left singular vectors of W(t)
W
Rdout×din
Repair-layer weight (only modified param.)
B
Rr×din
Coefficient matrix for low-rank update
b
Rdout
Repair-layer bias (fixed)
β
Rrdin
Vectorisation of B ; QP decision variable
Wc
RC×dout
Classification head (fixed)
κ(v)
scalar
Gap Sensitivity Norm (GSN)
bc
RC
Classification bias (fixed)
γs,γh
scalar
Repair / remain gap margins
W
Rdout×din
Final converged repair-layer weight
ρ,λ
scalar
Regularisation / slack-penalty coeff.
Table 1: Principal notation used in § 3 .
Task
Model
∣S∣
∣P∣
∣Gen∣
∣AtkGen∣
SST-2
DistilBERT
108
800 †
2,000 †
1,207
BERT
105
800 †
2,000 †
1,207
RTE
DistilBERT
47
200 ‡
500 ‡
222
BERT
50
200 ‡
500 ‡
222
Table 2: Dataset configurations. ∣S∣ : repair set; ∣P∣ : remain set; ∣Gen∣ : general accuracy evaluation set; ∣AtkGen∣ : attack generalization set. † Yelp Polarity test split ( Zhang et al., 2015 ) . ‡ RTE training split.
Task
Model
Repair Layer
Activation Function
Type
Init. κ
SST-2
DistilBERT
pre_classifier ( 768×768 )
ReLU
A
5.43
BERT
bert.pooler.dense ( 768×768 )
tanh
B
0.58
RTE
DistilBERT
pre_classifier ( 768×768 )
ReLU
A
4.79
BERT
bert.pooler.dense ( 768×768 )
tanh
B
0.52
Table 3: Model configurations. GSN κ is measured at initialisation (pre-GSN-FT). Type A repair layers are fully updated during downstream fine-tuning (high initial κ ); Type B receive minimal task-specific gradient updates (low initial κ ).
Model
Method
Repair Acc ↑
Remain Acc ↑
General Acc ↑
Atk. Gen ↑
SST-2 (sentiment classification)
DistilBERT
Original
5.6%
98.1%
98.2%
22.3%
Same-layer LoRA ( r=2 )
75.9%
99.0%
97.5%
56.7%
All-layers Full FT
100.0%
99.5%
93.6%
50.2%
WARP (ours)
100.0%
100.0%
91.4%
69.0%
BERT
Original
1.0%
98.2%
98.5%
23.2%
Table 4: Main experimental results on SST-2 and RTE. “Repair Acc” is the accuracy on the repair set S ; “Remain Acc” on the remain set P ; “General Acc” on the held-out evaluation set; “Atk. Gen” is the mean accuracy across six adversarial attack methods (higher is better for all metrics). All sets are defined with respect to the post-GSN-FT weights; see § 4.1 .
SST-2
RTE
DistilBERT
BERT
DistilBERT
BERT
Cert. 1
Samples with gap ≥γs
108/108
105/105
47/47
50/50
gap min / mean / max
1.000/1.291/2.360
1.000/1.431/2.814
1.000/1.244/2.662
1.000/1.866/4.843
Cert. 2
Samples with remain gap ≥γh
798/800
786/800
200/200
200/200
remain gap min / mean
0.300/1.059
0.300/1.915
0.300/0.946
0.300/0.951
Cert. 3
ε∗ min/median/mean/max
0.172/0.211/0.222/0.405
0.014/0.016/0.020/0.039
0.283/0.305/0.352/0.753
0.022/0.028/0.041/0.106
Table 5: Repair certificate verification (WARP, after QP repair).
SST-2
RTE
DistilBERT
BERT
DistilBERT
BERT
Pre
Post
Pre
Post
Pre
Post
Pre
Post
GSN κ
5.43
7.43
0.58
1.31
4.79
8.48
0.52
1.60
Atk. Gen
22.3%
20.9%
23.2%
22.5%
37.4%
37.7%
39.3%
42.8%
Best step
—
4
—
20
—
23
—
27
∥W∥2
1.506
2.238
13.408
13.423
1.140
2.949
13.413
13.558
Table 6: Effect of GSN-FT. Attack generalization is reported before and after GSN-FT to confirm that generalization gains originate from the QP step rather than preprocessing.
Appendix figures & tables8 assets
Supplementary material from the paper’s appendix.
Appendix
Symbol
Description
Value
r
Rank of weight perturbation
2
γs
Repair set gap margin target
1.0
γh
Remain set gap margin lower bound
0.3
λ
Slack penalty coefficient
50.0
ρ
regularization coefficient
2.0
T
Maximum iterations
300
Appendix
Table 7: QP repair hyperparameters.
Parameter
Value
Max steps TFT
30
Learning rate
1×10−3
Batch size
32
Auxiliary set size Naux
8
Trainable parameters
repair layer W + classification head Wc (592,130 total)
Checkpoint selection criterion
step with maximum GSN κ
Appendix
Table 8: GSN-FT hyperparameters.
SST-2
RTE
DistilBERT
BERT
DistilBERT
BERT
Multiplier k
Flipped
Cum.%
Flipped
Cum.%
Flipped
Cum.%
Flipped
Cum.%
≤1×
0/108
0.0%
0/105
0.0%
0/47
0.0%
0/50
0.0%
≤20×
37/108
34.3%
0/105
0.0%
13/47
27.7%
0/50
0.0%
≤25×
78/108
72.2%
0/105
0.0%
34/47
72.3%
0/50
0.0%
≤35×
107/108
99.1%
0/105
0.0%
47/47
100.0%
0/50
0.0%
Appendix
Table 9: Expanding-radius Monte Carlo stress test (tightness ratio: smallest multiplier k such that a flip is observed within k×ε∗ ).
Distance band ( d/εnearest∗ )
Samples
Accuracy
≤20×
5
100.0%
20× – 25×
49
87.8%
25× – 30×
180
82.2%
30× – 35×
267
74.5%
35× – 40×
271
68.6%
40× – 50×
324
60.5%
Appendix
Table 10: Accuracy of the repaired DistilBERT model (SST-2) on adversarial samples grouped by distance to the nearest repaired embedding as a multiple of ε∗ .
Adversarial robustness of language models studies how to keep their outputs and decisions reliable under manipulative prompts, input changes, and malicious fine-tuning.