R OBUSTNESS V ERIFICATION FOR T RANSFORMERS
A BSTRACT
Robustness veriﬁcation that aims to formally certify the prediction behavior of neural networks has become an important tool for understanding model behavior and obtaining safety guarantees.
However, previous methods can usually only handle neural networks with relatively simple architectures.
In this paper, we consider the robustness veriﬁcation problem for Transformers.
Transformers have complex self-attention layers that pose many challenges for veriﬁcation, including cross-nonlinearity and cross-position dependency, which have not been discussed in previous works.
We resolve these challenges and develop the ﬁrst robustness veriﬁcation algorithm for Transformers.
The certiﬁed robustness bounds computed by our method are signiﬁcantly tighter than those by naive Interval Bound
Propagation.
These bounds also shed light on interpreting Transformers as they consistently reﬂect the importance of different words in sentiment analysis.
I NTRODUCTION
Deep neural networks have been successfully applied to many domains.
However, these blackbox models are generally difﬁcult to analyze and their behavior is not guaranteed.
Moreover, it has been shown that the predictions of deep networks become unreliable and unstable when tested in unseen situations, e.g., in the presence of small adversarial perturbations to the input (Szegedy et al., 2013; Goodfellow et al., 2014; Lin et al., 2019).
Therefore, neural network veriﬁcation has become an important tool for analyzing and understanding the behavior of neural networks, with applications in safety-critical applications (Katz et al., 2017; Julian et al., 2019; Lin et al., 2019), model explanation (Shih et al., 2018) and robustness analysis (Tjeng et al., 2019;
Wang et al., 2018c;
Gehr et al., 2018; Wong & Kolter, 2018; Singh et al., 2018; Weng et al., 2018; Zhang et al., 2018).
Formally, a neural network veriﬁcation algorithm aims to provably characterize the prediction of a network within some input space.
For example, given a K -way classiﬁcation model f : R d → R K , where f i ( x ) stands for the predicted score of class i , we can verify some linear speciﬁcation (deﬁned by a vector c ) as below:
[Equation]
where S is a predeﬁned input space.
In the robustness veriﬁcation problem , S = { x | (cid:107) x − x 0 (cid:107) p ≤ (cid:15) } is deﬁned as some small (cid:96) p -ball around the original example x 0 , and setting up c = 1 y 0 −
1 y enables us to verify whether the logit output of class y 0 is always greater than another class y for any input within S .
This is a nonconvex optimization problem which makes computing the exact solution challenging, and thus several algorithms are recently proposed to ﬁnd the lower bounds of
Eq.
(1) in order to efﬁciently obtain a safety guarantee (Gehr et al., 2018;
Weng et al., 2018; Zhang et al., 2018; Singh et al., 2019).
Moreover, extensions of these algorithms can be used for verifying properties beyond robustness, such as rotation or shift invariant (Singh et al., 2019), conservation of energy (Qin et al., 2019) and model correctness (Yang & Rinard, 2019).
However, most of existing veriﬁcation methods focus on relatively simple neural network architectures, such as feed-forward and recurrent neural networks, while they cannot handle complex structures.
In this paper, we develop the ﬁrst robustness veriﬁcation algorithm for Transformers (Vaswani et al., 2017) with self-attention layers.
Transformers have been widely used in natural language processing (Devlin et al., 2019; Yang et al., 2019; Liu et al., 2019) and many other domains (Parmar et al., 2018; Kang & McAuley, 2018; Li et al., 2019b; Su et al., 2019; Li et al., 2019a).
For frames under perturbation in the input sequence, we aim to compute a lower bound (cid:15) such that when these frames are perturbed within (cid:96) p -balls centered at the original frames respectively and with a radius of (cid:15) , the model prediction is certiﬁed to be unchanged.
To compute such bounds efﬁciently, we adopt the linear-relaxation framework (Weng et al., 2018;
Zhang et al., 2018) – we recursively propagate and compute linear lower and upper bounds for each neuron w.r.t the input within the perturbation space S .
We resolve several particular challenges in verifying Transformers.
First , Transformers with selfattention layers have a complicated architecture.
Unlike simpler networks, they cannot be written as multiple layers of afﬁne transformations or element-wise activation functions.
Therefore, we need to propagate linear bounds differently for self-attention layers.
Second , dot products, softmax, and weighted summation in self-attention layers involve multiplication or division of two variables both under perturbation, namely cross-nonlinearity, which is not present in feed-forward networks.
Ko et al.
(2019) proposed a gradient descent based approach to ﬁnd linear bounds, however it is inefﬁcient and poses a computational challenge for Transformer veriﬁcation since self-attention is the core of Transformers.
In contrast, we derive closed-form linear bounds that can be computed in O (1) complexity.
Third , in the computation of self-attention, output neurons in each position depend on all input neurons from different positions (namely cross-position dependency ), unlike the case in recurrent neural networks where outputs depend on only the hidden features from the previous position and the current input.
Previous works (Zhang et al., 2018; Weng et al., 2018;
Ko et al., 2019) have to track all such dependency and thus is costly in time and memory.
To tackle this, we introduce an efﬁcient bound propagating process in a forward manner specially for self-attention layers, enabling the tighter backward bounding process for other layers to utilize bounds computed by the forward process.
In this way, we avoid cross-position dependency in the backward process which is relatively slower but produces tighter bounds.
Combined with the forward process, the complexity of the backward process is reduced by O ( n ) for input length n , while the computed bounds remain comparably tight.
Our contributions are summarized below:
• We propose an effective and efﬁcient algorithm for verifying the robustness of Transformers with self-attention layers.
To our best knowledge, this is the ﬁrst method for verifying Transformers.
• We resolve key challenges in verifying Transformers, including cross-nonlinearity and cross-position dependency.
Our bounds are signiﬁcantly tighter than those by adapting Interval Bound Propagation (IBP) (Mirman et al., 2018; Gowal et al., 2018).
• We quantitatively and qualitatively show that the certiﬁed bounds computed by our algorithm consistently reﬂect the importance of input words in sentiment analysis, which justiﬁes that these bounds are meaningful in practice and they shed light on interpreting Transformers.
R ELATED W ORK
Robustness Veriﬁcation for Neural Networks.
Given an input x 0 and a small region B p ( x 0 , (cid:15) ) :
= { x | (cid:107) x − x 0 (cid:107) p ≤ (cid:15) } , the goal of robustness veriﬁcation is to verify whether the prediction of the neural network is unchanged within this region.
This problem can be mathematically formulated as Eq.
If Eq.
(1) can be solved optimally, then we can derive the minimum adversarial perturbation of x by conducting binary search on (cid:15) .
Equivalently, we obtain the maximum (cid:15) such that any perturbation within B p ( x 0 , (cid:15) ) cannot change the predicted label.
Several works focus on solving Eq.
(1) exactly and optimally, using mixed integer linear programming (MILP) (Tjeng et al., 2019; Dutta et al., 2018), branch and bound (BaB) (Bunel et al., 2018), and satisﬁability modulo theory (SMT) (Ehlers, 2017; Katz et al., 2017).
Unfortunately, due to the nonconvexity of model f , solving Eq.
(1) is NP-hard even for a simple ReLU network (Katz et al., 2017).
Therefore, we can only expect to compute a lower bound of Eq.
(1) efﬁciently by using relaxations.
Many algorithms can be seen as using convex relaxations for non-linear activation functions (Salman et al., 2019), including using duality (Wong & Kolter, 2018;
Dvijotham et al., 2018), abstract domains (Gehr et al., 2018; Singh et al., 2018; Mirman et al., 2018; Singh et al., 2019), layer-by-layer reachability analysis (Wang et al., 2018b; Weng et al., 2018; Zhang et al., 2018;
Gowal et al., 2018) and semi-deﬁnite relaxations (Raghunathan et al., 2018; Dvijotham et al., 2019).
Additionally, robustness veriﬁcation can rely on analysis on local Lipschitz constants (Hein & Andriushchenko, 2017; Zhang et al., 2019).
However, existing methods are mostly limited to verifying networks with relatively simple architectures, such as feed-forward networks and RNNs (Wang et al., 2018a;
Akintunde et al., 2019;
Ko et al., 2019), while none of them are able to handle Transformers.
Transformers and Self-Attentive Models.
Transformers (Vaswani et al., 2017) based on selfattention mechanism, further with pre-training on large-scale corpora, such as BERT (Devlin et al., 2019), XLNet (Yang et al., 2019), RoBERTa (Liu et al., 2019), achieved state-of-the-art performance on many NLP tasks.
Self-attentive models are also useful beyond NLP, including VisualBERT on vision and language applications (Li et al., 2019b; Su et al., 2019), image transformer for image generation (Parmar et al., 2018), acoustic models for speech recognition, sequential recommendation (Kang & McAuley, 2018) and graph embedding (Li et al., 2019a).
The robustness of NLP models has been studied, especially many methods have been proposed to generate adversarial examples (Papernot et al., 2016; Jia & Liang, 2017; Zhao et al., 2017; Alzantot et al., 2018; Cheng et al., 2018; Ebrahimi et al., 2018; Shi et al., 2019).
In particular, Hsieh et al.
(2019) showed that Transformers are more robust than LSTMs.
However, there is not much work on robustness veriﬁcation for NLP models.
Ko et al.
(2019) veriﬁed RNN/LSTM.
Jia et al.
Huang et al.
(2019) used Interval Bound Propagation (IBP) for certiﬁed robustness training of CNN and LSTM.
In this paper, we propose the ﬁrst veriﬁcation method for Transformers.
M ETHODOLOGY
We aim to verify the robustness of a Transformer whose input is a sequence of frames X
= [ x (1) , x (2) , · · · , x ( n ) ] .
We take binary text classiﬁcation as a running example, where x ( i ) is a word embedding and the model outputs a score y c
( X ) for each class c ( c ∈ { 0 , 1 } ).
Nevertheless, our method for verifying Transformers is general and can also be applied in other applications.
For a clean input sequence X 0 =
[ x (1)0 , x (2)0 , · · · , x ( n ) 0 ] correctly classiﬁed by the model, let P = { r 1 , r 2 , · · · , r t } (1 ≤ r k ≤ n ) be the set of perturbed positions, where t is the number of perturbed positions.
Thus the perturbed input belongs to S (cid:15) :
= { X =
[ x (1) , x (2) , · · · , x ( n ) ] : (cid:107) x ( r k ) − x ( r k )(cid:107) p ≤ (cid:15), 1 ≤ k ≤ t, x ( i ) =
x ( i ) 0 , ∀ i / ∈ P } .
Assuming that c is the gold class, the goal of robustness veriﬁcation is to compute
[Equation]
If δ (cid:15) ( X ) > 0 , the output score of the correct class is always larger than the incorrect one for any input within S (cid:15) .
As mentioned previously, computing the exact values of δ (cid:15) ( X ) is NP-hard, and thus our goal is to efﬁciently compute a lower bound δ L(cid:15)
( X ) ≤ δ (cid:15) ( X ) .
3. B ASE F RAMEWORK
We obtain δ L(cid:15)
( X ) by computing the bounds of each neuron when X is perturbed within S (cid:15) ( δ L(cid:15) can be regarded as a ﬁnal neuron).
A Transformer layer can be decomposed into a number of sub-layers, where each sub-layer contains neurons after some operations.
These operations can be categorized into three categories: 1) linear transformations, 2) unary nonlinear functions, and 3) operations in self-attention.
Each sub-layer contains n positions in the sequence and each position contains a group of neurons.
We assume that the Transformer we verify has m sub-layers in total, and the value of the j -th neuron at the i -th position in the l -th sub-layer is Φ ( l,i ) j
( X ) , where Φ ( l,i ) ( X ) is a vector for the speciﬁed sub-layer and position.
Specially, Φ (0 ,i ) =
x ( i ) taking l = 0 .
We aim to compute a global lower bound f ( l,i ) ,L j and a global upper bound f ( l,i ) ,U j of Φ ( l,i ) j ( X ) for X ∈ S (cid:15) .
We compute bounds from the ﬁrst sub-layer to the last sub-layer.
For neurons in the l -th layer, we aim to represent their bounds as linear functions of neurons in a previous layer, the l (cid:48) -th layer:
[Equation]
where Λ ( l,i,l (cid:48) ,k ) ,L , ∆ ( l,i,l (cid:48) ) ,L and Λ ( l,i,l (cid:48) ,k ) ,U , ∆ ( l,i,l (cid:48) ) ,U are parameters of linear lower and upper bounds respectively.
Using linear bounds enables us to efﬁciently compute bounds with a reasonable tightness.
We initially have Λ ( l,i,l,i ) ,L = Λ ( l,i,l,i ) ,U
=
I and ∆ ( l,i,l ) ,L = ∆ ( l,i,l ) ,U = 0 .
Thereby the right-hand-side of Eq.
(2) equals to Φ ( l,i )
j ( X ) when l (cid:48)
= l .
Generally, we use a backward process to propagate the bounds to previous sub-layers, by substituting Φ ( l (cid:48) ,i ) with linear functions of previous neurons.
It can be recursively conducted until the input layer l (cid:48)
= 0 .
Since Φ (0 ,k ) =
x ( k ) =
x ( k ) 0 ( ∀ k / ∈ P ) is constant, we can regard the bounds as linear functions of the perturbed embeddings Φ (0 ,r k ) =
x ( r k ) (1 ≤ k ≤ t ) , and take the global bounds for x ( r k ) ∈
B p ( x ( r k ), (cid:15) ) : f ( l,i ) ,L j = − (cid:15) t (cid:88) k
= (cid:107)
[Equation]
,L
[Equation]
: (cid:107)
[Equation]
+ n (cid:88) k
[Equation] [Equation]
[Equation]
) f (
[Equation]
j = (cid:15) t (cid:88) k
= (cid:107) Λ ( l
[Equation]
where 1 /p + 1 /q = 1 with p, q ≥ 1 .
These steps resemble to CROWN (Zhang et al., 2018) which is proposed to verify feed-forward networks.
We further support verifying self-attentive Transformers which are more complex than feed-forward networks.
Moreover, unlike CROWN that conducts a fully backward process, we combine the backward process with a forward process (see Sec. 3.3) to reduce the computational complexity of verifying Transformers.
3. L INEAR T RANSFORMATIONS AND U NARY N ONLINEAR F UNCTIONS
Linear transformations and unary nonlinear functions are basic operations in neural networks.
We show how bounds Eq.
(2) at the l (cid:48) -th sub-layer are propagated to the ( l (cid:48) − 1) -th layer.
Linear Transformations
If the l (cid:48) -th sub-layer is connected with the ( l (cid:48) − 1) -th sub-layer with a linear transformation Φ ( l (cid:48) ,k ) ( X )
=
W ( l (cid:48) )
Φ ( l (cid:48) − 1 ,k ) ( X ) + b ( l (cid:48) )
where W ( l (cid:48) ) , b ( l (cid:48) ) are parameters of the linear transformation, we propagate the bounds to the ( l (cid:48) − 1) -th layer by substituting Φ ( l (cid:48) ,k ) ( X ) : Λ ( l,i,l (cid:48) − 1 ,k ) ,L/U = Λ ( l,i,l (cid:48) ,k ) ,L/U W ( l (cid:48) ) , ∆ ( l,i,l (cid:48) − 1) ,L/U =
∆
( l,i,l (cid:48) ) ,L/U + (cid:32)
[Equation]
where “ L/U ” means that the equations hold for both lower bounds and upper bounds respectively.
Unary Nonlinear Functions
If the l (cid:48) -th layer is obtained from the ( l (cid:48) − 1) -th layer with an unary nonlinear function Φ ( l (cid:48) ,k )
j
[Equation] [Equation]
( X )) , to propagate linear bounds over the nonlinear function, we ﬁrst bound σ ( l (cid:48) )
(Φ ( l (cid:48) − 1 ,k ) j ( X )) with two linear functions of Φ ( l (cid:48) − 1 ,k )
j
[Equation]
: α
[Equation]
where α ( l (cid:48) ,k ) ,L/U j , β ( l (cid:48) ,k ) ,L/U j are parameters such that the inequation holds true for all Φ ( l (cid:48) − 1 ,k )
j ( X ) within its bounds computed previously.
Such linear relaxations can be done for different functions, respectively.
We provide detailed bounds for functions involved in Transformers in Appendix B.
We then back propagate the bounds:
[Equation]
Λ ( l,i,l (cid:48) ,k ) ,L/U : ,j, + + α ( l (cid:48) ,k ) ,U/L j Λ ( l,i,l (cid:48) ,k ) ,L/U : ,j, − , ∆ ( l,i,l (cid:48) − 1) ,L/U j = ∆ ( l,i,l (cid:48) ) ,L/U j + (cid:32) n (cid:88) k
= β ( l (cid:48) ,k ) ,L/U j Λ ( l,i,l (cid:48) ,k ) ,L/U : ,j, + + β ( l (cid:48) ,k ) ,U/L j Λ ( l,i,l (cid:48) ,k ) ,L/U : ,j, − (cid:33) , where Λ ( l,i,l (cid:48) ,k ) ,L/U : ,j, + and Λ ( l,i,l (cid:48) ,k ) ,L/U : ,j, − mean to retain positive and negative elements in vector Λ ( l,i,l (cid:48) ,k ) ,L/U : ,j respectively and set other elements to 0.
3. S ELF -A TTENTION M ECHANISM
Self-attention layers are the most challenging parts for verifying Transformers.
We assume that Φ ( l − 1 ,i ) ( X ) is the input to a self-attention layer.
We describe our method for computing bounds for one attention head, and bounds for different heads of the multi-head attention in Transformers can be easily concatenated.
Φ ( l − 1 ,i ) ( X ) is ﬁrst linearly projected to queries q ( l,i ) ( X ) , keys k ( l,i ) ( X ) , and values v ( l,i ) ( X ) with different linear projections, and their bounds can be obtained as described in Sec. 3.2.
We also keep their linear bounds that are linear functions of the perturbed embeddings.
For convenience, let x ( r ) =
x ( r 1 ) ⊕ x ( r 2 ) ⊕ · · · x ( r t ) , where ⊕ indicates vector concatenation, and thereby we represent the linear bounds as linear functions of x ( r ) :
Ω ( l,i ) ,q/k/v,L j, :
[Equation]
where q/k/v and q / k / v mean that the inequation holds true for queries, keys and values respectively.
We then bound the output of the self-attention layer starting from q ( l,i ) ( X ) , k ( l,i ) ( X ) , v ( l,i ) ( X ) .
Bounds of Multiplications and Divisions We bound multiplications and divisions in the selfattention mechanism with linear functions.
We aim to bound bivariate function z
= xy or z = xy ( y > 0) with two linear functions
z L = α L x + β L y + γ L and z U =
α
U x + β U y + γ U , where x ∈ [ l x , u x ] , y ∈
[ l y , u y ] are bounds of x, y obtained previously.
For z = xy , we derive optimal parameters: α L = l y , α U =
u y , β L = β U =
l x , γ L = − l x l y , γ U = − l x u y .
We provide a proof in
Appendix C. However, directly bounding z
= xy is tricky; fortunately, we can bound it indirectly by ﬁrst bounding a unary function y = 1 y
and then bounding the multiplication z = xy .
A Forward Process For the self-attention mechanism, instead of using the backward process like
CROWN (Zhang et al., 2018), we compute bounds with a forward process which we will show later that it can reduce the computational complexity.
Attention scores are computed from q ( l,i ) ( X ) and k ( l,i )
( X ) : S ( l ) i,j = ( q ( l,i ) ( X ))
T k ( l,j ) ( X ) =
(cid:80) d qk k =1 q ( l,
[Equation]
k
[Equation]
X
[Equation]
( X ) , where d qk is the dimension of q ( l,i ) ( X ) and k ( l,j ) ( X ) .
For each multiplication q ( l,i ) k
( X ) k
( l,j ) k
( X ) , it is bounded by:
[Equation]
We then obtain the bounds of S ( l ) i,j : Ω ( l,i ) ,s,L j, : x ( r ) + Θ ( l,i ) ,s,L j ≤ S ( l ) i,j ≤ Ω ( l,i ) ,s,U j, : x ( r ) + Θ ( l,i ) ,s,U j , Ω ( l,i ) ,s,L/U j, : =
α ( l,i,j ) ,L/U k
( (cid:88)
α ( l,i,j ) ,L/U k >Ω ( l,i ) ,q,L/U k, : + (cid:88)
α ( l,i,j ) ,L/U k <Ω ( l,i ) ,q,U/L k, : )
+ β ( l,i,j ) ,L/U k
( (cid:88) β ( l,i,j ) ,L/U k >Ω ( l,j ) ,k,L/U k, : + (cid:88) β
( l,i,j ) ,L/U k <Ω ( l,j ) ,k,U/L k, : ) , Θ ( l,i ) ,s,L/U j
= α ( l,i,j ) ,L/U k
( (cid:88)
α ( l,i,j ) ,L/U k >Θ ( l,i ) ,q,L/U k
+ (cid:88) α ( l,i,j ) ,L/U k <Θ ( l,i ) ,q,U/L k )+ β ( l,i,j ) ,L/U k
( (cid:88) β ( l,i,j ) ,
L/U k >Θ ( l,j ) ,k,L/U k + (cid:88) β ( l,i,j ) ,L/U k <Θ ( l,j ) ,k,U/L k )
+ d qk (cid:88) k
= γ ( l,i,j ) ,L/U k .
In this way, linear bounds of q ( l,i ) ( X ) and k ( l,i ) ( X ) are forward propagated to S ( l ) i,j .
Attention scores are normalized into attention probabilities with a softmax, i.e. ˜ S ( l ) i,j = exp( S ( l ) i,j ) / ( (cid:80) nk
=1 exp( S ( l ) i,k )) , where ˜ S ( l ) i,j is a normalized attention probability.
exp( S ( l ) i,j ) is an unary nonlinear function and can be bounded by α ( l ) ,L/U i,j
S ( l ) i,j + β ( l ) ,L/U i,j .
So we forward propagate bounds of S ( l ) i,j to bound exp( S ( l ) i,j ) with Ω ( l,i ) ,e,L/U j, : x ( r ) + Θ ( l,i ) ,e,L/U j , where: (cid:26) Ω ( l,i ) ,e,L/U j, : = α ( l ) ,L/U i,j Ω ( l,i ) ,s,L/U j, : Θ ( l,i ) ,e,L/U j = α ( l ) ,L/U i,j Θ ( l,i ) ,s,L/U j + β ( l ) ,L/U i,j α ( l ) ,L/U i,j ≥ 0 , Ω ( l,i ) ,e,L/U j, : = α ( l ) ,L/U i,j Ω ( l,i ) ,s,U/L j, : Θ ( l,i ) ,e,L/U j = α ( l ) ,L/U i,j Θ ( l,i ) ,s,U/L j + β ( l ) ,L/U i,j α ( l ) ,L/U i,j < 0 .
By summing up bounds of each exp( S ( l ) i,k ) , linear bounds can be further propagated to (cid:80) nk
=1 exp( S ( l ) i,k ) .
With bounds of exp( S ( l ) i,j ) and (cid:80) nk =1 exp( S ( l ) i,k ) ready, we forward propagate the bounds to ˜ S ( l ) i,j with a division similarly to bounding q ( l,i ) k
( X ) k
( l,j ) k
( X ) .
The output of the self-attention Φ ( l,i ) ( X ) is obtained with a summation of v ( l,j ) ( X ) weighted by attention probability ˜ S ( l ) i,k : Φ ( l,
i
[Equation]
j
[Equation]
( X ) , which can be regarded as a dot product of ˜ S ( l ) i and ˜ v ( l,j ) k
( X ) , where ˜ v ( l,j ) k
( X ) =
v ( l,k ) j
( X ) whose bounds can be obtained from those of v ( l,k )
j
( X ) with a transposing.
Therefore, bounds of ˜ S ( l ) i,k and ˜ v ( l,j ) k
( X ) can be forward propagated to Φ ( l,i ) ( X ) similarly to bounding S ( l ) i,j .
In this way, we obtain the output bounds of the self-attention:
[Equation]
Recall that x ( r ) is a concatenation of x ( r 1 ) , x ( r 2 ) , · · · , x ( r t ) .
We can split Ω ( l (cid:48) ,i ) , Φ ,L/U j, : into t vectors with equal dimensions, Ω ( l (cid:48) ,i, 1) , Φ ,L/U j, : , Ω ( l
[Equation]
,i, 2) , Φ ,L/U j
[Equation]
: , · · · , Ω (
[Equation]
(cid:48) ,i,
[Equation]
, Φ ,L/
[Equation]
j, : , such that Eq.
(5) becomes t
[Equation]
Backward Process to Self-Attention Layers When computing bounds for a later sub-layer, the lth sub-layer, using the backward process, we directly propagate the bounds at the the closest previous self-attention layer assumed to be the l (cid:48) -th layer, to the input layer, and we skip other previous sublayers.
The bounds propagated to the l (cid:48) -th layer are as Eq.
We substitute Φ ( l (cid:48) ,k ) ( X ) with linear bounds in Eq.
[Equation]
We take global bounds as Eq.
(3) and Eq.
(4) to obtain the bounds of the l -th layer.
Advantageous of Combining the Backward Process with a Forward Process Introducing a forward process can signiﬁcantly reduce the complexity of verifying Transformers.
With the backward process only, we need to compute Λ ( l,i,l (cid:48) ,k ) and ∆ ( l,i,l (cid:48) )
( l (cid:48) ≤ l ) , where the major cost is on Λ ( l,i,l (cid:48) ,k ) and there are O ( m 2 n 2 ) such matrices to compute.
The O ( n 2 ) factor is from the dependency between all pairs of positions in the input and output respectively, which makes the algorithm inefﬁcient especially when the input sequence is long.
In contrast, the forward process represents the bounds as linear functions of the perturbed positions only instead of all positions by computing Ω ( l,i ) and Θ ( l,i ) .
Imperceptible adversarial examples may not have many perturbed positions (Gao et al., 2018;
Ko et al., 2019), and thus we may assume that the number of perturbed positions, t , is small.
The major cost is on Ω ( l,i ) while there are only O ( mn ) such matrices and the sizes of Λ ( l,i,l (cid:48) ,k ) and Ω ( l,i ) are relatively comparable for a small t .
We combine the backward process and the forward process.
The number of matrices Ω in the forward process is O ( mn ) , and for the backward process, since we do not propagate bounds over self-attention layers and there is no crossposition dependency in other sub-layers, we only compute Λ ( l,i,l (cid:48) ,k ) such that i = k , and thus the number of matrices Λ is reduced to O ( m 2 n ) .
Therefore, the total number of matrices Λ and Ω we compute is O ( m 2 n ) and is O ( n ) times smaller than O ( m 2 n 2 ) when only the backward process is used.
Moreover, the backward process makes bounds tighter compared to solely the forward one, as we explain in Appendix D.
E XPERIMENTS
To demonstrate the effectiveness of our algorithm, we compute certiﬁed bounds for several sentiment classiﬁcation models and perform an ablation study to show the advantage of combining the backward and forward processes.
We also demonstrate the meaningfulness of our certiﬁed bounds with an application on identifying important words.
4. D ATASETS AND M ODELS
We use two datasets: Yelp (Zhang et al., 2015) and SST (Socher et al., 2013).
Yelp consists of 560,000/38,000 examples in the training/test set and SST consists of 67,349/872/1,821 examples in the training/development/test set.
Each example is a sentence or a sentence segment (for the training data of SST only) labeled with a binary sentiment polarity.
We verify the robustness of Transformers trained from scratch.
For the main experiments, we consider N -layer models ( N ≤ 3 ), with 4 attention heads, hidden sizes of 256 and 512 for self-attention and feed-forward layers respectively, and we use ReLU activations for feed-forward layers.
We remove the variance related terms in layer normalization, making Transformers veriﬁcation bounds tighter while the clean accuracies remain comparable (see Appendix E for discussions).
Although our method can be in principal applied to Transformers with any number of layers, we do not use large-scale pre-trained models such as BERT because they are too challenging to be tightly veriﬁed with the current technologies.
4. C ERTIFIED B OUNDS
[Table] [Table]
We compute certiﬁed lower bounds for different models on different datasets.
We include 1-position perturbation constrained by (cid:96) 1 /(cid:96) 2 /(cid:96) ∞ -norms and 2-position perturbation constrained by (cid:96) 2 -norm.
We compare our lower bounds with those computed by the Interval Bound Propagation (IBP)
(Gowal et al., 2018) baseline.
For 1-position perturbation, we also compare with upper bounds computed by enumerating all the words in the vocabulary and ﬁnding the word closest to the original one such that the word substitution alters the predicted label.
This method has an exponential complexity with respect to the vocabulary size and can hardly be extended to perturbations on 2 or more positions; thus we do not include upper bounds for 2-position perturbation.
For each example, we enumerate possible options of perturbed positions (there are (cid:0) nt (cid:1) options), and we integrate results from different options by taking the minimum or average respectively.
We report the average results on 10 correctly classiﬁed random test examples with sentence lengths no more than 32 for 1-position perturbation and 16 for 2-position perturbation.
Table 1 and Table 2 present the results for 1-position and 2position perturbation respectively.
Our certiﬁed lower bounds are signiﬁcantly larger and thus tighter than those by IBP.
For 1-position perturbation, the lower bounds are consistently smaller than the upper bounds, and the gap between the upper bounds and our lower bounds is reasonable compared with that in previous work on veriﬁcation of feed-forward networks, e.g., in (Weng et al., 2018;
Zhang et al., 2018)
the upper bounds are in the order of 10 times larger than lower bounds.
This demonstrates that our proposed method can compute robustness bounds for Transformers in a similar quality to the bounds of simpler neural networks.
4. E FFECTIVENESS OF C OMBINING THE B ACKWARD P ROCESS WITH A F ORWARD P ROCESS
[Table]
In the following, we show the effectiveness of combining the backward process with a forward process.
We compare our proposed method ( Backward & Forward ) with two variations: 1) FullyForward propagates bounds in a forward manner for all sub-layers besides self-attention layers; 2)
Fully-Backward computes bounds for all sub-layers including self-attention layers using the backward bound propagation and without the forward process.
We compare the tightness of bounds and computation time of the three methods.
We use smaller models with the hidden sizes reduced by 75%, and we use 1-position perturbation only, to accommodate Fully-Backward with large computational cost.
Experiments are conducted on an NVIDIA TITAN X GPU.
Table 3 presents the results.
Bounds by Fully-Forward are signiﬁcantly looser while those by Fully-Backward and Backward &
Forward are comparable.
Meanwhile, the computation time of Backward & Forward is signiﬁcantly shorter than that of Fully-Backward .
This demonstrates that our method of combining the backward and forward processes can compute comparably tight bounds much more efﬁciently.
4. I DENTIFYING W ORDS I MPORTANT TO P REDICTION
The certiﬁed lower bounds can reﬂect how sensitive a model is to the perturbation of each input word.
Intuitively, if a word is more important to the prediction, the model is more sensitive to its perturbation.
Therefore, the certiﬁed lower bounds can be used to identify important words.
In the following, we conduct an experiment to verify whether important words can be identiﬁed by our certiﬁed lower bounds.
We use a 1-layer Transformer classiﬁer under 1-position perturbation constrained by (cid:96) 2 -norm.
We compare our method with two baselines that also estimate local vulnerability: 1) Upper uses upper bounds; 2) Gradient identiﬁes the word whose embedding has the largest (cid:96) 2 -norm of gradients as the most important and vice versa.
Quantitative Analysis on SST SST contains sentiment labels for all phrases on parse trees, where the labels range from very negative (0) to very positive (4), and 2 for neutral.
For each word,
[Table]
assuming its label is x we take | x − 2 | , i.e., the distance to the neutral label, as the importance score , since less neutral words tend to be more
We evaluate on 100 random test input sentences and compute the average importance scores of the most or least important words identiﬁed from the examples.
In Table 4, compared to the baselines (“Upper” and “Grad”), the average importance score of the most important words identiﬁed by our lower bounds are the largest, while the least important words identiﬁed by our method have the smallest average score.
This demonstrates that our method identiﬁes the most and least important words more accurately compared to baseline methods.
Qualitative Analysis on Yelp We further analyze the results on a larger dataset, Yelp.
Since Yelp does not provide per-word sentiment labels, importance scores cannot be computed as on SST.
Thus, we demonstrate a qualitative analysis.
We use 10 random test examples and collect the words identiﬁed as the most and least important word in each example.
In Table 4, most words identiﬁed as the most important by certiﬁed lower bounds are exactly the words reﬂecting sentiment polarities (boldfaced words), while those identiﬁed as the least important words are mostly stopwords.
Baseline methods mistakenly identify more words containing no sentiment polarity as the most important.
This again demonstrates that our certiﬁed lower bounds identify word importance better than baselines and our bounds provide meaningful interpretations in practice.
While gradients evaluate the sensitivity of each input word, this evaluation only holds true within a very small neighborhood (where the classiﬁer can be approximated by a ﬁrst-order Taylor expansion) around the input sentence.
Our certiﬁed method gives valid lower bounds that hold true within a large neighborhood speciﬁed by a perturbation set S , and thus it provides more accurate results.
C ONCLUSION
We propose the ﬁrst robustness veriﬁcation method for Transformers, and tackle key challenges in verifying Transformers, including cross-nonlinearity and cross-position dependency.
Our method computes certiﬁed lower bounds that are signiﬁcantly tighter than those by IBP.
Quantitative and qualitative analyses further show that our bounds are meaningful and can reﬂect the importance of different words in sentiment analysis.
A CKNOWLEDGEMENT
This work is jointly supported by Tsinghua Scholarship for Undergraduate Overseas Studies, Tsinghua University Initiative Scientiﬁc Research Program, Tsinghua University DCST Student Academic Training Program, and NSF IIS1719097 and IIS1927554.
A I LLUSTRATION OF D IFFERENT B OUNDING P ROCESSES
Figure 1 illustrates a comparison of the Fully-Forward, Fully-Backward and Backward & Forward processes, for a 2-layer Transformer as an example.
For Fully-Forward, there are only forward processes connecting adjacent layers and blocks.
For Fully-Backward, there are only backward processes, and each layer needs a backward bound propagation to all the previous layers.
For our
Backward & Forward algorithm, we use backward processes for the feed-forward parts and forward processes for self-attention layers, and for layers after self-attention layers, they no longer need backward bound propagation to layers prior to self-attention layers.
In this way, we resolve the cross-position dependency in verifying Transformers while still keeping bounds comparably tight as those by using fully backward processes.
Empirical comparison of the three frameworks are presented in Sec. 4.3.
B L INEAR B OUNDS OF U NARY N ONLINEAR F UNCTIONS
We show in Sec. 3.2 that linear bounds can be propagated over unary nonlinear functions as long as the unary nonlinear functions can be bounded with linear functions.
Such bounds are determined for each neuron respectively, according to the bounds of the input for the function.
Speciﬁcally, for a unary nonlinear function σ ( x ) , with the bounds of x obtained previously as x ∈ [ l, u ] , we aim to derive a linear lower bound α L x + β L and a linear upper bound α U x + β U , such that
[Equation]
where parameters α L , β L , α U , β U are dependent on l, u and designed for different functions σ ( x ) respectively.
We introduce how the parameters are determined for different unary nonlinear functions involved in Transformers such that the linear bounds are valid and as tight as possible.
Bounds of ReLU and tanh has been discussed by Zhang et al.
and we further derive bounds of e x ,x , x 2 , √ x . x 2 and √ x are only used when the layer normalization is not modiﬁed for experiments to study the impact of our modiﬁcation.
For the following description, we deﬁne the endpoints of the function to be bounded within range ( l, r ) as ( l, σ ( l )) and ( u, σ ( u )) .
We describe how the lines corresponding to the linear bounds of different functions can be determined, and thereby parameters α L , β L , α U , β U can be determined accordingly.
ReLU For ReLU activation, σ ( x ) = max( x, 0) .
ReLU is inherently linear on segments ( −∞ , 0] and [0 , ∞ ) respectively, so we make the linear bounds exactly σ ( x ) for u ≤ 0 or l ≥ 0 ; and for l < 0 < u , we take the line passing the two endpoints as the upper bound; and we take σ L ( x )
=when u < | l | and σ L ( x ) = 1 when u ≥ | l | as the lower bound, to minimize the gap between the lower bound and the original function.
Tanh For tanh activation, σ ( x ) = 1 − e − 2 x 1+ e − 2 x .
tanh is concave for l ≥ 0 , and thus we take the line passing the two endpoints as the lower bound and take a tangent line passing (( l + u ) / 2 , σ (( l + u ) / 2) as the upper bound.
For u ≤ 0 , tanh is convex, and thus we take the line passing the two endpoints as the upper bound and take a tangent line passing (( l + u ) / 2 , σ (( l + u ) / 2) as the lower bound.
For l < 0 < u , we take a tangent line passing the right endpoint and ( d L , σ ( d L ))
( d L ≤ 0) as the lower bound, and take a tangent line passing the left endpoint and ( d U , σ ( d U ))
( d U ≤ 0) as the upper bound.
d L and d U can be found with a binary search.
Exp σ ( x ) =
exp ( x ) =
e x is convex, and thus we take the line passing the two endpoints as the upper bound and take a tangent line passing ( d, σ ( d )) as the lower bound.
Preferably, we take d = ( l + u ) / 2 .
However, e x is always positive and used in the softmax for computing normalized attention probabilities in self-attention layers, i.e., exp ( S ( l ) i,j ) and (cid:80) nk
=1 exp ( S ( l ) i,k ) .
(cid:80) nk
=1 exp ( S ( l ) i,k ) appears in the denominator of the softmax, and to make reciprocal function 1 x ﬁnitely bounded, the range of x should not pass 0.
Therefore, we impose a constraint to force the lower bound function to be always positive, i.e., σ L ( l ) > 0 , since σ L ( l ) is monotonously increasing.
σ L d ( x ) =
e d ( x − d )+ e d is the tangent line passing ( d, σ ( d )) .
So the constraint σ Ld ( l ) > 0 yields d < l + 1 .
Hence we take d = min(( l + u ) / 2 , l + 1 − ∆ d ) where ∆ d is a small real value to ensure that d < l + 1 such as ∆ d = 10 − 2 .
Reciprocal For the reciprocal function, σ ( x ) = 1 x .
It is used in the softmax and layer normalization and its input is limited to have l > 0 by the lower bounds of exp ( x ) , and √ x .
With l > 0 , σ ( x ) is convex.
Therefore, we take the line passing the two endpoints as the upper bound.
And we take the tangent line passing (( l + u ) / 2 , σ (( l + u ) / 2)) as the lower bound.
Square For the square function, σ ( x ) = x 2 .
It is convex and we take the line passing the two endpoints as the upper bound.
And we tan a tangent line passing ( d, σ ( d ))
( d ∈ [ l, u ]) as the lower bound.
We still prefer to take d = ( l + u ) / 2 .
x 2 appears in the variance term of layer normalization and is later passed to a square root function to compute a standard derivation.
To make the input to the square root function valid, i.e., non-negative, we impose a constraint σ L ( x ) ≥ 0( ∀ x ∈ [ l, u ]) .
σ Ld ( x ) = 2 d ( x − d ) + d 2 is the tangent line passing ( d, σ ( d )) .
For u ≤ 0 , x 2 is monotonously decreasing, the constraint we impose is equivalent to σ L ( u ) = 2 du − d 2 ≥ 0 , and with d ≤ 0 , we have d ≥ 2 u .
So we take d = max(( l + u ) / 2 , 2 u ) .
For l ≥ 0 , x 2 is monotonously increasing, and thus the constraint we impose is equivalent to σ L ( l ) = 2 dl − d 2 ≥ 0 , and with d ≥ 0 , we have d ≤ 2 l .
So we take d = max(( l + u ) / 2 , 2 l ) .
σ Ld (0) = − d 2 is negative for d (cid:54) = 0 and is zero for d = 0 .
And for l < 0 < u , the constraint we impose is equivalent to σ L (0) =
− d 2 ≥ 0 , and thus we take d = 0 .
Square root For the square root function, σ ( x ) = √ x .
It is used the to compute a standard derivation in layer normalization and its input is limited to be positive by the lower bounds of xand a smoothing constant, and thus l > 0 .
σ ( x ) is concave, and thus we take the line passing the two endpoints as the lower bound and take the tangent line passing (( l + u ) / 2 , σ (( l + u ) / 2))
as the upper bound.
C L INEAR B OUNDS OF M ULTIPLICATIONS AND D IVISIONS
We provide a mathematical proof of optimal parameters for linear bounds of multiplications used in Sec. 3.3.
We also show that linear bounds of division can be indirectly obtained from bounds of multiplications and the reciprocal function.
For each multiplication, we aim to bound z = xy with two linear bounding planes
z L = α L x + β L y + γ L and z U =
α
U x + β U y + γ U , where x and y are both variables and x ∈ [ l x , u x ] , y ∈
[ l y , u y ] are concrete bounds of x, y obtained from previous layers, such that:
[Equation]
Our goal is to determine optimal parameters of bounding planes, i.e., α L , β L , γ L , α U , β
[Equation]
[Equation]
, such that the bounds are as tight as possible.
C. L OWER B OUND OF M ULTIPLICATIONS
We deﬁne a difference function F L ( x, y ) which is the difference between the original function z = xy and the lower bound z L = α L x + β L y + γ L :
[Equation]
To make the bound as tight as possible, we aim to minimize the integral of the difference function
F L ( x, y ) on our concerned area ( x, y ) ∈
[ l x , u x ] × [ l y , u y ] , which is equivalent to maximizing
[Equation]
while F L ( x, y ) ≥ 0 ( ∀ ( x, y ) ∈
[ l x , u x ] × [ l y , u y ]) .
For an optimal bounding plane, there must exist a point ( x 0 , y 0 ) ∈
[ l x , u x ] × [ l y , u y ] such that F L ( x 0 , y 0 ) =
(otherwise we can validly increase γ L to make V L larger).
To ensure that F L ( x, y ) ≥ 0 within the concerned area, we need to ensure that the minimum value of F L ( x, y ) is non-negative.
We show that we only need to check cases when ( x, y ) is any of ( l x , l y ) , ( l x , u y ) , ( u x , l y ) , ( u x , u y ) , i.e., points at the corner of the considered area.
The partial derivatives of F L are:
[Equation]
If there is ( x 1 , y 1 ) ∈ ( l x , u x ) × ( l y , u y ) such that F L ( x 1 , y 1 ) ≤ F ( x, y ) ( ∀ ( x, y ) ∈
[ l x , u x ] × [ l y , u y ]) , ∂F L ∂x ( x 1 , y 1 ) =
∂F L ∂y ( x 1 , y 1 ) = 0 should hold true.
Thereby ∂F L ∂x ( x, y ) , ∂F L ∂y ( x, y ) < 0 ( ∀ ( x, y ) ∈
[ l x , x 1 ) ×
[ l y , y 1 )) , and thus F L ( l x , l y ) <
F L ( x 1 , y 1 ) and ( x 1 , y 1 ) cannot be the point with the minimum value of F L ( x, y ) .
On the other hand, if there is ( x 1 , y 1 )( x 1 = l x , y 1 ∈ ( l y , u y )) , i.e., on one border of the concerned area but not on any corner, ∂F L ∂y ( x 1 , y 1 ) = 0 should hold true.
Thereby, ∂F L ∂y ( x, y ) =
∂F L ∂y ( x 1 , y )
=
( ∀ ( x, y ) , x = x 1 = l x ) , and F L ( x 1 , y 1 ) =
F L ( x 1 , l y ) =
F L ( l x , l y ) .
This property holds true for the other three borders of the concerned area.
Therefore, other points within the concerned area cannot have smaller function value F L ( x, y ) , so we only need to check the corners, and the constraints on F L ( x, y ) become
[Equation]
which is equivalent to
[Equation]
We substitute γ L in Eq.
(7) with Eq.
(8), yielding
[Equation]
where V
= ( u x − l x )( u y − l y ).
We have shown that the minimum function value F L ( x, y ) within the concerned area cannot appear in ( l x , u x ) × ( l y , u y ) , i.e., it can only appear at the border.
When ( x 0 , y 0 ) is a point with a minimum function value F L ( x 0 , y 0 )
= 0 , ( x 0 , y 0 ) can also only be chosen from the border of the concerned area.
At least one of x 0 = l x and x 0 = u x holds true.
If we take x 0 = l x :
[Equation]
And from Eq.
(8) we obtain
[Equation]
Then
[Equation]
Therefore, α L ≤ l y .
To maximize V L 1 , since now only α L is unknown in V L 1 and the coefﬁcient of α L is V 0 ( u x − l x ) ≥ 0 , we take α L = l y , and then
V L 1 =
[Equation] [Equation]
l x u
[Equation]
) is a constant.
For the other case if we take x 0 = u x :
[Equation] [Equation]
Therefore, α L ≥ u y .
We take α L = u y similarly as in the case when x 0 = l x , and then
[Equation]
We notice that V L 1 = V L 2 , so we can simply adopt the ﬁrst one.
We also notice that V L 1 , V L 2 are independent of y 0 , so we may take any y 0 within [ l y , u y ] such as y
= l y .
Thereby, we obtain the a group of optimal parameters of the lower bounding plane:
[Equation]
C. U PPER B OUND OF M ULTIPLICATIONS
We derive the upper bound similarly.
We aim to minimize
[Equation]
, where V 0 = ( u x − l x )( u y − l y ).
If we take x 0 = l x :
[Equation]
Then
[Equation]
Therefore, α U ≥ u y .
To minimize V U 1 , we take α U = u y , and then
V U 1 =
V
( l x l y + u x u y ) .
[Equation]
Therefore,
[Equation]
Therefore,
[Equation]
To minimize V U 2 , we take α U =
l y , and then
[Equation]
Since V U 1 = V U 2 , we simply adopt the ﬁrst case.
And V U 1 , V U 2 are independent of y 0 , so we may take any y 0 within [ l y , u y ] such as y
= l y .
Thereby, we obtain a group of optimal parameters of the upper bounding plane:
[Equation]
C. L INEAR B OUNDS OF D IVISIONS
We have shown that closed-form linear bounds of multiplications can be derived.
However, we ﬁnd that directly bounding z = xy is tricky.
If we try to derive a lower bound z L = α L xβ L y + γ for z = xy as shown in Appendix C.1, the difference function is
[Equation]
The partial derivatives of F L are:
[Equation]
If there is ( x 1 , y 1 ) ∈ ( l x , u x ) × ( l y , u y ) such that ∂F L ∂x ( x, y ) =
∂F L ∂y ( x, y ) = 0 , unlike that the case for multiplications, none of areas [ l x , x 1 ) ×
[ l y , y 1 ) , [ l x , x 1 ) ×
( y 1 , u y ] , ( x 1 , u x ] × [ l y , y 1 ) and ( x 1 , u x ] × ( y 1 , u y ] has a guarantee that ∂F L ∂x ( x, y ) =
∂F L ∂y ( x, y ) < 0 for all ( x, y ) with in the area.
It is possible that ( x 1 , y 1 ) does have a minimum function value F L ( x 1 , y 1 ) among all ( x, y ) ∈
[ l x , u x ] × [ l y , u y ] , i.e., a minimum function value of F L ( x, y ) for ( x, y ) within the concerned area may appear at a point other than the corners.
For example, for l x =0 . 05 , u x =0 .
15 , l y =0 .
05 , u y = 0 .
15 , α = 10 , β = − 20 , γ = 2 , the minimum function value of F L ( x, y ) for ( x, y ) ∈ [0 . 05 , 0 . 15] × [0 . 05 , 0 . 15] appears at (0 . 1 , 0 . 1) which is not a corner of [0 . 05 , 0 . 15] × [0 .
This makes it more difﬁcult to derive closed-form parameters such that the constraints on F L ( x, y ) are satisﬁed.
Fortunately, we can bound z =
xy indirectly by utilizing the bounds of multiplications and reciprocal functions.
We bound z = xy by ﬁrst bounding a unary function y = 1 y
and then bounding the multiplication z = xy .
D T IGHTNESS OF B OUNDS BY THE B ACKWARD P ROCESS AND F ORWARD P ROCESS
We have discussed that combining the backward process with a forward process can reduce computational complexity, compared to the method with the backward process only.
But we only use the forward process for self-attention layers and do not fully use the forward process for all sublayers, because bounds by the forward process can be looser than those by the backward process.
We compare the tightness of bounds by the forward process and the backward process respectively.
To illustrate the difference, for simplicity, we consider a m -layer feed-forward network Φ (0)
=
x , y ( l ) = W ( l ) Φ ( l − 1) ( x ) + b ( l ) , Φ ( l ) ( x ) = σ ( y ( l ) ( x ))
(0 < l ≤ m ) , where x is the input vector, W ( l ) and b ( l ) are the weight matrix and the bias vector for the l -th layer respectively, y ( l ) ( x ) is the pre-activation vector of the l -th layer, Φ ( l ) ( x ) is the vector of neurons in the l -th layer, and σ ( · ) is an activation function.
Before taking global bounds, both the backward process and the forward process bound Φ ( l ) j ( x ) with linear functions of x .
When taking global bounds as Eq.
(3) and Eq.
(4), only the norm of weight matrix is directly related to the (cid:15) in binary search for certiﬁed lower bounds.
Therefore, we try to measure the tightness of the computed bounds using the difference between weight matrices for lower bounds and upper bounds respectively.
We show how it is computed for the forward process and the backward process respectively.
D. T HE F ORWARD P ROCESS
For the forward process, we bound each neuron Φ ( l ) j ( x ) with linear functions:
[Equation]
To measure the tightness of the bounds, we are interested in Ω ( l ) ,L , Ω ( l ) ,U , and also Ω ( l ) ,U − Ω ( l ) ,L .
Initially,
[Equation]
We can forward propagate the bounds of Φ ( l − 1) ( x ) to y ( l ) ( x ) :
[Equation]
L
[Equation]
where
[Equation]
With the global bounds of y ( l ) ( x ) that can be obtained with Eq.
(3) and Eq.
(4), we bound the activation function:
[Equation]
And then bounds can be propagated from Φ ( l − 1) ( x ) to Φ ( l ) ( x ) :
[Equation]
Therefore,
[Equation]
illustrates how the tightness of the bounds is changed from earlier layers to later layers.
D. T HE B ACKWARD P ROCESS AND D ISCUSSIONS
For the backward process, we bound the neurons in the l -th layer with linear functions of neurons in a previous layer, the l (cid:48) -th layer:
[Equation]
We have shown in Sec.
3.1 how such bounds can be propagated to l (cid:48)
= 0 , for the case when the input is sequential.
For the nonsequential case we consider here, it can be regarded as a special case when the input length is 1.
So we can adopt the method in Sec.
3.1 to propagate bounds for the feed-forward network we consider here.
We are interested in Λ ( l,l (cid:48) )
,L , Λ ( l,l (cid:48) ) ,U and also Λ ( l,l (cid:48) ) ,U − Λ ( l,l (cid:48) ) ,L .
Weight matrices of linear bounds before taking global bounds are Λ ( l, 0) ,L and Λ ( l, 0) ,U which are obtained by propagating the bounds starting from Λ ( l,l ) ,L = Λ ( l,l ) ,U
= I .
According to bound propagation described in Sec. 3.2,
[Equation]
illustrates how the tightness bounds can be measured during the backward bound propagation until l (cid:48)
= 0 .
There is a W ( l (cid:48) ) in Eq.
(10) instead of | W ( l (cid:48) )
| in Eq.
The norm of ( Ω ( l ) ,U j, : − Ω ( l ) ,L j, : ) in Eq.
(9) can quickly grow large as l increases during the forward propagation when (cid:107) W ( l ) j (cid:107) is greater than 1, while this generally holds true for neural networks to have (cid:107) W ( l ) j (cid:107) greater than 1 in feedforward layers.
While in Eq.
(10), W ( l (cid:48) )
j can have both positive and negative elements and tends to allow cancellations for different W ( l (cid:48) )
j,i , and thus the norm of ( Λ ( l,l (cid:48) − 1) ,U : ,j − Λ ( l,l (cid:48) − 1) ,L : ,j ) tends to be smaller.
Therefore, the bounds computed by the backward process tend to be tighter than those by the forward framework, which is consistent with our experiment results in Table 3.
E I MPACT OF M ODIFYING THE L AYER N ORMALIZATION
The original Transformers have a layer normalization after the embedding layer, and two layer normalization before and after the feed-forward part respectively in each Transformer layer.
We modify the layer normalization, f ( x ) =
w ( x − µ ) /σ
+ b , where x is d -dimensional a vector to be normalized, µ and σ are the mean and standard derivation of { x i } respectively, and w and b are gain and bias parameters respectively.
σ = (cid:113) (1 /d )
(cid:80) di
=1 ( x i − µ ) 2 + (cid:15) s where (cid:15) s is a smoothing constant.
It involves ( x i − µ ) 2 whose linear lower bound is loose and exactly 0 when the range of the x i − µ crosses 0.
When the (cid:96) p -norm of the perturbation is relatively larger, there can be many x i − µ with ranges crossing 0, which can cause the lower bound of σ to be small and thereby the upper bound of f i ( x ) to be large.
This can make the certiﬁed bounds loose.
To tackle this, we modify the layer normalization into f ( x ) =
w ( x − µ )+ b by removing the standard derivation term.
We use an experiment to study the impact of this modiﬁcation.
We compare the clean accuracies and certiﬁed bounds of the models with modiﬁed layer normalization to models with standard layer normalization and with no layer normalization respectively.
Table 5 presents the results.
Certiﬁed lower bounds of models with no layer normalization or our modiﬁcation are signiﬁcantly tighter than those of corresponding models with the standard layer normalization.
Meanwhile, the clean accuracies of the models with our modiﬁcation are comparable with those of the models with the standard layer normalization (slightly lower on Yelp and slightly higher on SST).
This demonstrates that it appears to be worthwhile to modify the layer normalization in Transformers for easier veriﬁcation.
[Table]