NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Robustness Verification for Transformers

Zhouxing Shi, Huan Zhang, Kai-Wei Chang, Minlie Huang, Cho-Jui Hsieh

Overview

Deep neural networks are notoriously "brittle"—small, often imperceptible changes to an input (adversarial attacks) can easily flip a model's prediction. Robustness verification addresses this by mathematically proving that a model’s output will remain constant for any input within a specific "safety region" (usually an $\ell_p$-ball around the original input).

While verification techniques exist for simple feed-forward and recurrent networks, Transformers pose unique challenges. This paper introduces the first robustness verification algorithm specifically designed for Transformer architectures. By combining a novel forward-bounding process for self-attention layers with a traditional backward-bounding approach for other components, the authors provide provable safety guarantees against adversarial perturbations that are significantly tighter and more efficient than existing baseline methods.

The Challenge of Verifying Transformers

Transformers introduce complex architectural components that break standard verification methods:

  1. Cross-Nonlinearity: Self-attention involves multiplying two variables that are both under perturbation (e.g., Query $\times$ Key). In contrast, standard layers only multiply a perturbed variable by a fixed weight.
  2. Cross-Position Dependency: In a Transformer, every output neuron depends on every input neuron across all positions. This creates a computational explosion ($O(n^2)$ dependencies) that makes traditional "backward" verification algorithms prohibitively slow and memory-intensive.

A Hybrid Bounding Methodology

The authors build upon the linear-relaxation framework (specifically the CROWN algorithm). The core idea is to "sandwich" every nonlinear operation between two linear functions (lower and upper bounds).

The paper’s technical breakthrough is a hybrid bounding strategy:

  • Forward Process for Self-Attention: To handle the $O(n^2)$ dependencies of self-attention, the authors use a forward-propagating process. They derive closed-form linear bounds for the bivariate function $z = xy$ (used in dot products) and the softmax operation. This represents bounds as functions of only the perturbed input positions, drastically reducing complexity.
  • Backward Process for Other Layers: For standard linear and ReLU layers, they use a backward-propagating process, which is known to produce tighter bounds than forward methods.
  • Modified Layer Normalization: The authors found that the standard deviation term in LayerNorm makes verification extremely loose. They propose a simplified LayerNorm (removing the variance term) that maintains model accuracy while making the math much "friendlier" for verification.

Key Results

The researchers evaluated their method on two popular natural language processing benchmarks for sentiment analysis: Yelp (business reviews) and SST (movie reviews). They focused on 1-position and 2-position word substitution perturbations constrained by $\ell_1, \ell_2,$ and $\ell_\infty$ norms.

Superior Tightness and Proximity to Ground Truth

The proposed method produced certified lower bounds that were orders of magnitude tighter than naive Interval Bound Propagation (IBP). Furthermore, the certified bounds were reasonably close to the empirical "upper bounds" (found by actual adversarial searching), suggesting that the algorithm captures a significant portion of the model's true robustness.

Comparison of certified bounds against IBP and upper bounds

Computational Speedup

Purely backward verification is too slow for Transformers, while purely forward verification (like IBP) is too loose. The hybrid "Backward & Forward" approach hits the sweet spot. It reduces the complexity of the backward process by a factor of $O(n)$. In practice, it proved to be roughly 5-7 times faster than a fully-backward approach while maintaining nearly identical tightness.

Performance comparison of forward, backward, and hybrid bounding strategies

Additional Insights and Limitations

Verification as Interpretation: A fascinating side effect of this work is that the "certified bounds" actually act as a high-quality saliency map. Words with the tightest bounds (most sensitive to perturbation) were consistently the most meaningful sentiment words (e.g., "terrible," "perfect"), while stopwords had very loose bounds.

Architectural Constraints: The study highlights that certain standard deep learning components (like the variance term in LayerNorm) are "verification-unfriendly." Modifying these slightly can lead to much more robust and certifiable models without sacrificing performance.

Limitations and Future Work: * Model Scale: The experiments were limited to relatively small Transformers (up to 3 layers). Verifying massive, state-of-the-art models like BERT or GPT remains a significant challenge due to the accumulation of "slack" in the linear relaxations as the network gets deeper. * LayerNorm Modification: While the modified LayerNorm doesn't hurt accuracy on sentiment analysis, it remains to be seen if this holds for more complex tasks like machine translation. * Discrete Perturbations: The current framework operates on continuous embedding spaces. Extending this to handle the discrete nature of word substitutions more natively is a suggested path for future research.

Summary updated

BibTeX
@inproceedings{shi2020robustness,
  author = {Zhouxing Shi and Huan Zhang and Kai-Wei Chang and Minlie Huang and Cho-Jui Hsieh},
  title = {{Robustness Verification for Transformers}},
  booktitle = {International Conference on Learning Representations},
  year = {2020},
  url = {https://openreview.net/forum?id=WC58T-9n-T},
}
Figure