I NFO BERT: I MPROVING R OBUSTNESS OF L ANGUAGE M ODELS FROM A N I NFORMATION T HEORETIC P ERSPECTIVE
A BSTRACT
Large-scale pre-trained language models such as BERT and RoBERTa have achieved state-of-the-art performance across a wide range of NLP tasks.
Recent studies, however, show that such BERT-based models are vulnerable facing the threats of textual adversarial attacks.
We aim to address this problem from an information-theoretic perspective, and propose InfoBERT, a novel learning framework for robust ﬁne-tuning of pre-trained language models.
InfoBERT contains two mutual-information-based regularizers for model training: ( i ) an
Information Bottleneck regularizer, which suppresses noisy mutual information between the input and the feature representation; and ( ii ) an Anchored Feature regularizer, which increases the mutual information between local stable features and global features.
We provide a principled way to theoretically analyze and improve the robustness of language models in both standard and adversarial training.
Extensive experiments demonstrate that InfoBERT achieves stateof-the-art robust accuracy over several adversarial datasets on Natural Language
Inference (NLI) and Question Answering (QA) tasks.
Our code is available at https://github.com/AI-secure/InfoBERT .
I NTRODUCTION
Self-supervised representation learning pre-trains good feature extractors from massive unlabeled data, which show promising transferability to various downstream tasks.
Recent success includes large-scale pre-trained language models ( e.g., BERT, RoBERTa, and GPT-3 (Devlin et al., 2019;
Liu et al., 2019; Brown et al., 2020)), which have advanced state of the art over a wide range of
NLP tasks such as NLI and QA, even surpassing human performance.
Speciﬁcally, in the computer vision domain, many studies have shown that self-supervised representation learning is essentially solving the problem of maximizing the mutual information (MI) I ( X ; T ) between the input X and the representation T (van den Oord et al., 2018; Belghazi et al., 2018;
Hjelm et al., 2019; Chen et al., 2020).
Since MI is computationally intractable in high-dimensional feature space, many MI estimators (Belghazi et al., 2018) have been proposed to serve as lower bounds (Barber & Agakov, 2003; van den Oord et al., 2018) or upper bounds (Cheng et al., 2020) of MI.
Recently, Kong et al.
point out that the MI maximization principle of representation learning can be applied to not only computer vision but also NLP domain, and propose a uniﬁed view that recent pre-trained language models are maximizing a lower bound of MI among different segments of a word sequence.
On the other hand, deep neural networks are known to be prone to adversarial examples (Goodfellow et al., 2015; Papernot et al., 2016; Eykholt et al., 2017; Moosavi-Dezfooli et al., 2016), i.e., the outputs of neural networks can be arbitrarily wrong when human-imperceptible adversarial perturbations are added to the inputs.
Textual adversarial attacks typically perform word-level substitution (Ebrahimi et al., 2018;
Alzantot et al., 2018;
Ren et al., 2019) or sentence-level paraphrasing (Iyyer et al., 2018; Zhang et al., 2019) to achieve semantic/utility preservation that seems innocuous to human, while fools NLP models.
Recent studies (Jin et al., 2020; Zang et al., 2020; Nie et al., 2020; Wang et al., 2020) further show that even large-scale pre-trained language models (LM) such as BERT are vulnerable to adversarial attacks, which raises the challenge of building robust real-world LM applications against unknown adversarial attacks.
We investigate the robustness of language models from an information theoretic perspective, and propose a novel learning framework InfoBERT, which focuses on improving the robustness of language representations by ﬁne-tuning both local features (word-level representation) and global features (sentence-level representation) for robustness purpose.
InfoBERT considers two MI-based regularizers: ( i ) the Information Bottleneck regularizer manages to extract approximate minimal sufﬁcient statistics for downstream tasks, while removing excessive and noisy information that may incur adversarial attacks; ( ii ) the Anchored Feature regularizer carefully selects useful local stable features that are invulnerable to adversarial attacks, and maximizes the mutual information between local stable features and global features to improve the robustness of the global representation.
In this paper, we provide a detailed theoretical analysis to explicate the effect of InfoBERT for robustness improvement, along with extensive empirical adversarial evaluation to validate the theory.
Our contributions are summarized as follows.
( i )
We propose a novel learning framework InfoBERT from the information theory perspective, aiming to effectively improve the robustness of language models.
( ii ) We provide a principled theoretical analysis on model robustness, and propose two MIbased regularizers to reﬁne the local and global features, which can be applied to both standard and adversarial training for different NLP tasks.
( iii ) Comprehensive experimental results demonstrate that InfoBERT can substantially improve robust accuracy by a large margin without sacriﬁcing the benign accuracy, yielding the state-of-the-art performance across multiple adversarial datasets on
NLI and QA tasks.
R ELATED W ORK
Textual Adversarial Attacks/Defenses Most existing textual adversarial attacks focus on wordlevel adversarial manipulation.
Ebrahimi et al.
(2018) is the ﬁrst to propose a whitebox gradientbased attack to search for adversarial word/character substitution.
Following work (Alzantot et al., 2018; Ren et al., 2019; Zang et al., 2020; Jin et al., 2020) further constrains the perturbation search space and adopts Part-of-Speech checking to make NLP adversarial examples look natural to human.
To defend against textual adversarial attacks, existing work can be classiﬁed into three categories: ( i )
Adversarial Training is a practical method to defend against adversarial examples.
Existing work either uses PGD-based attacks to generate adversarial examples in the embedding space of NLP as data augmentation (Zhu et al., 2020a), or regularizes the standard objective using virtual adversarial training (Jiang et al., 2020; Liu et al., 2020; Gan et al., 2020).
However, one drawback is that the threat model is often unknown, which renders adversarial training less effective when facing unseen attacks.
( ii ) Interval Bound Propagation (IBP) (Dvijotham et al., 2018) is proposed as a new technique to consider the worst-case perturbation theoretically.
Recent work (Huang et al., 2019; Jia et al., 2019) has applied IBP in the NLP domain to certify the robustness of models.
However, IBPbased methods rely on strong assumptions of model architecture and are difﬁcult to adapt to recent transformer-based language models.
( iii ) Randomized Smoothing (Cohen et al., 2019) provides a tight robustness guarantee in (cid:96) 2 norm by smoothing the classiﬁer with Gaussian noise.
Ye et al.
(2020) adapts the idea to the NLP domain, and replace the Gaussian noise with synonym words to certify the robustness as long as adversarial word substitution falls into predeﬁned synonym sets.
However, to guarantee the completeness of the synonym set is challenging.
Representation Learning MI maximization principle has been adopted by many studies on selfsupervised representation learning (van den Oord et al., 2018;
Belghazi et al., 2018; Hjelm et al., 2019; Chen et al., 2020).
Speciﬁcally, InfoNCE (van den Oord et al., 2018) is used as the lower bound of MI, forming the problem as contrastive learning (Saunshi et al., 2019; Yu et al., 2020).
However, Tian et al.
(2020) suggests that the InfoMax (Linsker, 1988) principle may introduce excessive and noisy information, which could be adversarial.
To generate robust representation, Zhu et al.
(2020b) formalizes the problem from a mutual-information perspective, which essentially performs adversarial training for worst-case perturbation, while mainly considers the continuous space in computer vision.
In contrast, InfoBERT originates from an information-theoretic perspective and is compatible with both standard and adversarial training for discrete input space of language models.
I NFO BERT
Before diving into details, we ﬁrst discuss the textual adversarial examples we consider in this paper.
We mainly focus on the dominant word-level attack as the main threat model, since it achieves higher attack success and is less noticeable to human readers than other attacks.
Due to the discrete nature of text input space, it is difﬁcult to measure adversarial distortion on token level.
Instead, because most word-level adversarial attacks (Li et al., 2019; Jin et al., 2020) constrain word perturbations via the bounded magnitude in the semantic embedding space, by adapting from Jacobsen et al.
(2019), we deﬁne the adversarial text examples with distortions constrained in the embedding space.
Deﬁnition 3.1.
( (cid:15) -bounded Textual Adversarial Examples).
Given a sentence x = [ x 1 ; x 2 ; ... ; x n ] , where x i is the word at the i -th position, the (cid:15) -bounded adversarial sentence x (cid:48)
=
[ x (cid:48) 1 ; x (cid:48) 2 ; ... ; x (cid:48) n ] for a classiﬁer F satisﬁes: (1) F ( x )
=
o ( x ) =
o ( x (cid:48) )
but
F ( x (cid:48) )
(cid:54) =
o ( x (cid:48) ) , where o ( · ) is the oracle ( e.g. , human decision-maker); (2)
||
t i − t (cid:48)
i || 2 ≤ (cid:15) for i = 1 , 2 , ..., n , where (cid:15) ≥ 0 and t i is the word embedding of x i .
3. I NFORMATION B OTTLENECK AS A R EGULARIZER
In this section, we ﬁrst discuss the general IB implementation, and then explain how IB formulation is adapted to InfoBERT as a regularizer along with theoretical analysis to support why IB regularizer can help improve the robustness of language models.
The IB principle formulates the goal of deep learning as an information-theoretic trade-off between representation compression and predictive power (Tishby & Zaslavsky, 2015).
Given the input source X , a deep neural net learns the internal representation T of some intermediate layer and maximizes the MI between T and label Y , so that
T subject to a constraint on its complexity contains sufﬁcient information to infer the target label Y .
Finding an optimal representation T can be formulated as the maximization of the Lagrangian
[Equation] [Equation]
) where β > 0 is a hyper-parameter to control the tradeoff, and I ( Y ; T ) is deﬁned as:
[Equation]
Since Eq.
(2) is intractable, we instead use the lower bound from Barber & Agakov (2003):
[Equation] [Equation]
where q ψ ( y | t ) is the variational approximation learned by a neural network parameterized by ψ for the true distribution p ( y | t ) .
This indicates that maximizing the lower bound of the ﬁrst term of IB
I ( Y ; T ) is equivalent to minimizing the task cross-entropy loss (cid:96) task =
H ( Y | T ) .
To derive a tractable lower bound of IB, we here use an upper bound (Cheng et al., 2020) of I ( X ; T )
I
[Equation]
dt .
By combining Eq.
(3) and (4), we can maximize the tractable lower bound ˆ L IB of IB in practice by:
[Equation]
with data samples { x ( i ) , y ( i ) } Ni =1 , where q ψ can represent any classiﬁcation model ( e.g. , BERT), and p ( t | x ) can be viewed as the feature extractor f
θ : X → T , where X and T are the support of the input source X and extracted feature T , respectively.
The above is a general implementation of IB objective function.
In InfoBERT, we consider T as the features consisting of the local word-level features after the BERT embedding layer f θ .
The following BERT self-attentive layers along with the linear classiﬁcation head serve as q ψ ( y | t ) that predicts the target Y given representation T .
Formally, given random variables X
=
[ X 1 ; X 2 ; ... ; X n ] representing input sentences with X i (word token at i -th index), let T =
[ T 1 ; ... ; T n ] =
f θ ([ X 1 ; X 2 ; ... ; X n ]) =
[ f θ ( X 1 ); f θ ( X 2 ); ... ; f θ ( X n )] denote the random variables representing the features generated from input X via the BERT embedding layer f θ , where T i ∈
R
d is the high-dimensional word-level local feature for word X i .
Due to the high dimensionality d of each word feature ( e.g. , 1024 for BERT-large), when the sentence length n increases, the dimensionality of features T becomes too large to compute I ( X ; T ) in practice.
Thus, we propose to maximize a localized formulation of IB L LIB deﬁned as:
[Equation]
Theorem 3.1.
(Lower Bound of L IB )
Given a sequence of random variables X
=
[ X 1 ; X 2 ; ... ; X n ] and a deterministic feature extractor f
θ , let T =
[ T 1 ; ... ; T n ] =
[ f θ ( X 1 ); f θ ( X 2 ); ... ; f θ ( X n )] .
Then the localized formulation of IB L LIB is a lower bound of L IB (Eq.
(1)), i.e.,
[Equation]
Theorem 3.1 indicates that we can maximize the localized formulation of L LIB as a lower bound of
IB L IB when I ( X ; T ) is difﬁcult to compute.
In Eq.
(6), if we regard the ﬁrst term ( I ( Y ; T ) ) as a task-related objective, the second term ( − nβ (cid:80) ni
=
I ( X i ; T i ) ) can be considered as a regularization term to constrain the complexity of representation T , thus named as Information Bottleneck regularizer .
Next, we give a theoretical analysis for the adversarial robustness of IB and demonstrate why localized IB objective function can help improve the robustness to adversarial attacks.
Following Deﬁnition 3.1, let T =
[ T 1 ; T 2 ; ... ; T n ] and T (cid:48) =
[ T (cid:48) 1 ; T (cid:48) 2 ; ... ; T (cid:48) n ] denote the features for the benign sentence X and adversarial sentence X (cid:48) .
The distributions of X and X (cid:48) are denoted by probability p ( x ) and q ( x ) with the support X and X (cid:48) , respectively.
We assume that the feature representation T has ﬁnite support denoted by T considering the ﬁnite vocabulary size in NLP.
Theorem 3.2.
(Adversarial Robustness Bound)
For random variables
X
=
[ X 1 ; X 2 ; ... ; X n ] and
X (cid:48)
=
[ X (cid:48) 1 ; X (cid:48) 2 ; ... ; X (cid:48) n ] , let T =
[ T 1 ; T 2 ; ... ; T n ] =
[ f θ ( X 1 ); f θ ( X 2 ); ... ; f θ ( X n )] and T (cid:48) =
[ T (cid:48) 1 ; T (cid:48) 2 ; ... ; T (cid:48) n ] =
[ f θ ( X (cid:48) 1 ); f θ ( X (cid:48) 2 ); ... ; f θ ( X (cid:48) n )] with ﬁnite support T , where f θ is a deterministic feature extractor.
The performance gap between benign and adversarial data | I ( Y ; T ) − I
( Y ; T (cid:48) )
| is bounded above by
[Equation]
where B 0 , B 1 , B 2 , B 3 and B 4 are constants depending on the sequence length n , (cid:15) and p ( x ) .
The sketch of the proof is to express the difference of |
I ( Y ; T ) − I
( Y (cid:48) ; T )
| in terms of I ( X i ; T i ) .
Speciﬁcally, Eq.
(25) factorizes the difference into two summands.
The ﬁrst summand, the conditional entropy | H ( T | Y ) − H ( T (cid:48) | Y ) | , can be bound by Eq.
(42) in terms of MI between benign/adversarial input and representation I
( X i ; T i ) and I ( X (cid:48)
i ; T (cid:48) i ) .
The second summand | H ( T ) − H ( T (cid:48) ) | has a constant upper bound (Eq. (85)), since language models have bounded vocabulary size and embedding space, and thus have bounded entropy.
The intuition of Theorem 3.2 is to bound the adversarial performance drop | I ( Y ; T ) − I
( Y ; T (cid:48) )
| by I
( X i ; T i ) .
As explained in Eq.
(3), I ( Y ; T ) and I ( Y ; T (cid:48) ) can be regarded as the model performance on benign and adversarial data.
Thus, the LHS of the bound represents such a performance gap.
The adversarial robustness bound of Theorem 3.2 indicates that the performance gap becomes closer
when I ( X i ; T i ) and I ( X (cid:48)
i ; T (cid:48) i ) decrease.
Note that our IB regularizer in the objective function
Eq.
(6) achieves the same goal of minimizing I ( X i ; T i ) while learning the most efﬁcient information features, or approximate minimal sufﬁcient statistics, for downstream tasks.
Theorem 3.2 also suggests that combining adversarial training with our IB regularizer can further minimize I ( X (cid:48)
i ; T (cid:48) i ) , leading to better robustness, which is veriﬁed in § 4.
3. A NCHORED F EATURE R EGULARIZER
In addition to the IB regularizer that suppresses noisy information that may incur adversarial attacks, we propose a novel regularizer termed “Anchored Feature Regularizer”, which extracts local stable features and aligns them with sentence global representations, thus improving the stability and robustness of language representations.
The goal of the local anchored feature extraction is to ﬁnd features that carry useful and stable information for downstream tasks.
Instead of directly searching for local anchored features, we start with searching for nonrobust and unuseful features.
To identify local nonrobust features, we perform adversarial attacks to detect which words are prone to changes under adversarial word substitution.
We consider these vulnerable words as features nonrobust to adversarial threats.
Therefore, global robust sentence representations should rely less on these vulnerable statistical clues.
On the other hand, by examining the adversarial perturbation on each local word feature, we can also identify words that are less useful for downstream tasks.
For example, stopwords and punctuation usually carry limited information, and tend to have smaller adversarial perturbations than words containing more effective information.
Although these unuseful features are barely changed under adversarial attacks, they contain insufﬁcient information and should be discarded.
After identifying the nonrobust and unuseful features, we treat the remaining local features in the sentences as useful stable features and align the global feature representation based on them.
During the local anchored feature extraction, we perform “virtual” adversarial attacks that generate adversarial perturbation in the embedding space, as it abstracts the general idea for existing wordlevel adversarial attacks.
Formally, given an input sentence x = [ x 1 ; x 2 ; ... ; x n ] with its corresponding local embedding representation t =
[ t 1 ; ... ; t n ] , where x and t are the realization of random variables X and T , we generate adversarial perturbation δ in the embedding space so that the task loss (cid:96) task increases.
The adversarial perturbation δ is initialized to zero, and the gradient of the loss with respect to δ is calculated by g ( δ )
=
∇ δ (cid:96) task ( q ψ ( t + δ ) , y ) to update δ ← (cid:81)
||
δ || F ≤ (cid:15) ( ηg ( δ ) / || g ( δ ) || F ) .
The above process is similar to one-step PGD with zero-initialized perturbation δ .
Since we only care about the ranking of perturbation to decide on robust features, in practice we skip the update of δ to save computational cost, and simply examine the (cid:96) 2 norm of the gradient g ( δ ) i of the perturbation on each word feature t i .
A feasible plan is to choose the words whose perturbation is neither too large (nonrobust features) nor too small (unuseful features), e.g. , the words whose perturbation rankings are among 50% ∼ 80% of all the words.
The detailed procedures are provided in Algorithm 1.
After local anchored features are extracted, we propose to align sentence global representations Z with our local anchored features T i .
In practice, we can use the ﬁnal-layer [CLS] embedding to represent global sentence-level feature Z .
Speciﬁcally, we use the information theoretic tool to increase the mutual information I ( T i ; Z ) between local anchored features T i and sentence global representations Z , so that the global representations can share more robust and useful information with the local anchored features and focus less on the nonrobust and unuseful ones.
By incorporating the term I ( T i ; Z ) into the previous objective function Eq.
(6), our ﬁnal objective function becomes:
[Equation]
where T k j are the local anchored features selected by Algorithm 1 and M is the number of local anchored features.
An illustrative ﬁgure can be found in Appendix Figure 2.
In addition, due to the intractability of computing MI, we use InfoNCE (van den Oord et al., 2018) as the lower bound of MI to approximate the last term I ( T k j ; Z ) :
[Equation]
where g ω ( · , · ) is a score function (or critic function) approximated by a neural network, t i are the positive samples drawn from the joint distribution P of local anchored features and global representations, and t (cid:48)
i are the negative samples drawn from the distribution of nonrobust and unuseful features ˜ P .
E XPERIMENTS
In this section, we demonstrate how effective InfoBERT improves the robustness of language models over multiple NLP tasks such as NLI and QA.
We evaluate InfoBERT against both strong adversarial datasets and state-of-the-art adversarial attacks.
4. E XPERIMENTAL S ETUP
Adversarial Datasets
The following adversarial datasets and adversarial attacks are used to evaluate the robustness of InfoBERT and baselines.
(I) Adversarial NLI (ANLI)
(Nie et al., 2020) is a large-scale NLI benchmark, collected via an iterative, adversarial, human-and-model-in-theloop procedure to attack BERT and RoBERTa.
ANLI dataset is a strong adversarial dataset which can easily reduce the accuracy of BERT Large to 0% .
(II) Adversarial SQuAD (Jia & Liang, 2017)
dataset is an adversarial QA benchmark dataset generated by a set of handcrafted rules and reﬁned by crowdsourcing.
Since adversarial training data is not provided, we ﬁne-tune RoBERTa Large on benign SQuAD training data (Rajpurkar et al., 2016) only, and test the models on both benign and adversarial test sets.
(III) TextFooler (Jin et al., 2020) is the state-of-the-art word-level adversarial attack method to generate adversarial examples.
To create an adversarial evaluation dataset, we sampled 1 , 000 examples from the test sets of SNLI and MNLI respectively, and run TextFooler against
BERT Large and RoBERTa Large to obtain the adversarial text examples.
Baselines Since IBP-based methods (Huang et al., 2019; Jia et al., 2019) cannot be applied to largescale language models yet, and the randomized-smoothing-based method (Ye et al., 2020) achieves limited certiﬁed robustness, we compare InfoBERT against three competitive baselines based on adversarial training: (I) FreeLB (Zhu et al., 2020a) applies adversarial training to language models during ﬁne-tuning stage to improve generalization.
In § 4.2, we observe that FreeLB can boost the robustness of language models by a large margin.
(II) SMART (Jiang et al., 2020) uses adversarial training as smoothness-inducing regularization and Bregman proximal point optimization during ﬁne-tuning, to improve the generalization and robustness of language models.
(III) ALUM (Liu et al., 2020) performs adversarial training in both pre-training and ﬁne-tuning stages, which achieves substantial performance gain on a wide range of NLP tasks.
Due to the high computational cost of adversarial training, we compare InfoBERT to ALUM and SMART with the best results reported in the original papers.
Evaluation Metrics We use robust accuracy or robust F1 score to measure how robust the baseline models and InfoBERT are when facing adversarial data.
Speciﬁcally, robust accuracy is calculated by:
Acc =
[Equation] [Equation]
max q
[Equation]
)) ≡ y ] , where D adv is the adversarial dataset, y is the ground-truth label, arg max selects the class with the highest logits and 1 ( · ) is the indicator function.
Similarly, robust F1 score is calculated by: F1 =
[Equation]
where v ( · , · ) is the F1 score between the true answer a
and the predicted answer arg max q ψ ( f θ ( x (cid:48) )) , and arg max selects the answer with the highest probability (see Rajpurkar et al.
(2016) for details).
Implementation Details To demonstrate InfoBERT is effective for different language models, we apply InfoBERT to both pretrained RoBERTa Large and BERT Large .
Since InfoBERT can be applied to both standard training and adversarial training, we here use FreeLB as the adversarial training implementation.
InfoBERT is ﬁne-tuned for 2 epochs for the QA task, and 3 epochs for the NLI task.
More implementation details such as α, β, c h , c l selection can be found in Appendix A.1.
[Table] [Table]
4. E XPERIMENTAL R ESULTS
Evaluation on ANLI As ANLI provides an adversarial training dataset, we evaluate models in two settings: 1) training models on benign data (MNLI (Williams et al., 2018) +
SNLI (Bowman et al., 2015))
only, which is the case when the adversarial threat model is unknown; 2) training models on both benign and adversarial training data (SNLI+MNLI+ANLI+FeverNLI), which assumes the threat model is known in advance.
Results of the ﬁrst setting are summarized in Table 1.
The vanilla RoBERTa and BERT models perform poorly on the adversarial dataset.
In particular, vanilla BERT Large with standard training achieves the lowest robust accuracy of 26 .
5% among all the models.
We also evaluate the robustness improvement by performing adversarial training during ﬁne-tuning, and observe that adversarial training for language models can improve not only generalization but also robustness.
In contrast,
InfoBERT substantially improves robust accuracy in both standard and adversarial training.
The robust accuracy of InfoBERT through standard training is even higher than the adversarial training baseline FreeLB for both RoBERTa and BERT, while the training time of InfoBERT is 1 / 3 ∼ 1 /less than FreeLB.
This is mainly because FreeLB requires multiple steps of PGD attacks to generate adversarial examples, while InfoBERT essentially needs only 1-step PGD attack for anchored feature selection.
Results of the second setting are provided in Table 2, which shows InfoBERT can further improve robust accuracy for both standard and adversarial training.
Speciﬁcally, when combined with adversarial training, InfoBERT achieves the state-of-the-art robust accuracy of 58 .
3% , outperforming all existing baselines.
Note that although ALUM achieves higher accuracy for BERT on the dev set, it tends to overﬁt on the dev set, therefore performing worse than InfoBERT on the test set.
[Table]
[Table] [Table]
[Figure]
[Table]
Evaluation against TextFooler InfoBERT can defend against not only human-crafted adversarial examples ( e.g. , ANLI) but also those generated by adversarial attacks ( e g. , TextFooler).
Results are summarized in Table 3.
We can see that InfoBERT barely affects model performance on the benign test data, and in the case of adversarial training, InfoBERT even boosts the benign test accuracy.
Under the TextFooler attack, the robust accuracy of the vanilla BERT drops to 0 .
0% on both MNLI and
SNLI datasets, while RoBERTa drops from 90% to around 20% .
We observe that both adversarial training and InfoBERT with standard training can improve robust accuracy by a comparable large margin, while InfoBERT with adversarial training achieves the best performance among all models, conﬁrming the hypothesis in Theorem 3.2 that combining adversarial training with IB regularizer can further minimize I ( X (cid:48)
i ; T (cid:48) i ) , leading to better robustness than the vanilla one.
Evaluation on Adversarial SQuAD
Previous experiments show that InfoBERT can improve model robustness for NLI tasks.
Now we demonstrate that InfoBERT can also be adapted to other NLP tasks such as QA in Table 4.
Similar to our observation on NLI dataset, we ﬁnd that InfoBERT barely hurts the performance on the benign test data, and even improves it in some cases.
Moreover,
InfoBERT substantially improves model robustness when presented with adversarial QA test sets (AddSent and AddOneSent).
While adversarial training does help improve robustness, InfoBERT can further boost the robust performance by a larger margin.
In particular, InfoBERT through standard training achieves the state-of-the-art robust F1/EM score as 78 .
9 compared to existing adversarial training baselines, and in the meantime requires only half the training time of adversarialtraining-based methods.
4. A NALYSIS OF L OCAL A NCHORED F EATURES
We conduct an ablation study to further validate that our anchored feature regularizer indeed ﬁlters out nonrobust/unuseful information.
As shown in Table 1 and 2, adding adversarial data in the training set can signiﬁcantly improve model robustness.
To ﬁnd out what helps improve the robustness from the MI perspective, we ﬁrst calculate the MI between anchored features and global features 1 M (cid:80) Mj
=
I ( T k j ; Z ) on the adversarial test data and benign test data, based on the model trained without adversarial training data (denoted by I (cid:48) R and I R ).
We then calculate the MI between nonrobust/unuseful features and global features 1 M (cid:48) (cid:80) M (cid:48)
i =
1 I ( T k i ; Z ) on the adversarial test data and benign data as well (denoted by I (cid:48) N and I N ).
After adding adversarial examples into the training set and re-training the model, we ﬁnd that the MI between the local features and the global features substantially increases on the adversarial test data, which accounts for the robustness improvement.
We also observe that those local anchored features extracted by our anchored feature regularizer, as expected, contribute more to the MI improvement.
As shown in Figure 1, the MI improvement of anchored features on adversarial test data ∆ I (cid:48)
R (red bar on the left) is higher than that of nonrobust/unuseful ∆ I (cid:48) N (red bar on the right), thus conﬁrming that local anchored features discovered by our anchored feature regularizer have a stronger impact on robustness than nonrobust/unuseful ones.
We conduct more ablation studies in Appendix § A.2, including analyzing the individual impact of two regularizers, the difference between global and local features for IB regularizer, hyper-parameter selection strategy and so on.
C ONCLUSION
In this paper, we propose a novel learning framework InfoBERT from an information theoretic perspective.
Supported by theoretical analysis, InfoBERT provides a principled way to improve the robustness of BERT and RoBERTa on NLI and QA tasks.
Comprehensive experiments demonstrate that InfoBERT achieves new state of the art on adversarial datasets, shedding light on a new effective approach towards improving the robustness of representation learning for language models.
A CKNOWLEDGEMENT
We gratefully thank the anonymous reviewers and meta-reviewers for their constructive feedback.
We also thank Julia Hockenmaier, Alexander Schwing, Sanmi Koyejo, Fan Wu, Wei Wang, Pengyu
Cheng, and other colleagues during the internship for spotting the mistakes and providing helpful comments.
This work is partially supported by NSF grant No.1910100, DARPA QED-RML-FP003, and U.S. Department of Energy by Lawrence Livermore National Laboratory under Contract
DE-AC52-07NA27344.
A. I MPLEMENTATION D ETAILS Model Details
BERT is a transformer (Vaswani et al., 2017) based model, which is unsupervised pretrained on large corpora.
We use BERT Large -uncased as the baseline model, which has 24 layers, 1024 hidden units, 16 self-attention heads, and 340 M parameters.
RoBERTa Large shares the same architecture as BERT, but modiﬁes key hyperparameters, removes the next-sentence pretraining objective and trains with much larger mini-batches and learning rates, which results in higher performance than BERT model on GLUE, RACE and SQuAD.
Standard Training Details For both standard and adversarial training, we ﬁne-tune InfoBERT for 2 epochs on the QA task, and for 3 epochs on the NLI task.
The best model is selected based on the performance on the development set.
All ﬁne-tuning experiments are run on Nvidia V100 GPUs.
For NLI task, we set the batch size to 256 , learning rate to 2 × 10 − 5 , max sequence length toand warm-up steps to 1000.
For QA task, we set the batch size to 32 , learning rate to 3 × 10 − 5 and max sequence length to 384 without warm-up steps.
Adversarial Training Details
Adversarial training introduces hyper-parameters including adversarial learning rates, number of PGD steps, and adversarial norm.
When combing adversarial training with InfoBERT, we use FreeLB as the adversarial training implementation, and set adversarial learning rate to 10 − 1 or 4 ∗ 10 − 2 , adversarial steps to 3 , maximal perturbation norm to 3 ∗ 10 −or 2 ∗ 10 − 1 and initial random perturbation norm to 10 − 1 or 0 .
Information Bottleneck Regularizer Details For information bottleneck, there are different ways to model p ( t | x ) :
1. Assume that p ( t | x ) is unknown.
We use a neural net parameterized by q θ ( t | x ) to learn the conditional distribution p ( t | x ) .
We assume the distribution is a Gaussian distribution.
The
transformers
neural net q θ will learn the mean and variance of the Gaussian given input x and representation t .
By reparameterization trick, the neural net can be backpropagated to approximate the distribution given the training samples.
p ( t | x ) is known.
Since t is the representation encoded by BERT, we actually already know the distribution of p .
We also denote it as q θ , where θ is the parameter of the BERT encoder f θ .
If we assume the conditional distribution is a Gaussian N ( t i , σ ) for input x i whose mean is the BERT representation t i and variance is a ﬁxed constant σ , the Eq.6 becomes
[Equation]
where c ( σ )
is a
positive constant
related
to
σ
In practice, the sample t
(cid:48)
i from the conditional
distribution Gaussian
N
( t
i , σ
can be t i with
some Gaussian noise an adversarial
examples
of
t i , or t i itself
assume
σ
=
We use the second way to model p ( t | x ) for InfoBERT ﬁnally, as it gives higher robustness improvement than the ﬁrst way empirically (shown in the following § A.2).
We suspect that the main reason is because the ﬁrst way needs to approximate the distribution p ( t | x ) via another neural net which could present some difﬁculty in model training.
Information Bottleneck Regularizer also introduces another parameter β to tune the trad-off between representation compression
I ( X i ; T i ) and predictive power I
( Y ; T ) .
We search for the optimal β via grid search, and set β = 5 × 10 − 2 for RoBERTa, β = 10 − 3 for BERT on the NLI task.
On the
QA task, we set β = 5 × 10 − 5 , which is substantially lower than β on NLI tasks, thus containing more word-level features.
We think it is mainly because the QA task relies more on the word-level representation to predict the exact answer spans.
More ablation results can be found in the following § A.2.
Anchored Feature Regularizer Details Anchored Feature Regularizer uses α to weigh the balance between predictive power and importance of anchored feature.
We set α = 5 × 10 − 3 for both
NLI and QA tasks.
Anchored Feature Regularizer also introduces upper and lower threshold c l and c h for anchored feature extraction.
We set c h = 0 .
9 and c l = 0 .
5 for the NLI task, and set c h
= 0 .and
c l = 0 .
75 for the QA task.
The neural MI estimator used by infoNCE uses two-layer fully connected layer to estimate the MI with the intermediate layer hidden size set to 300 .
A. A DDITIONAL E XPERIMENTAL R ESULTS A.2. A BLATION S TUDY ON I NFORMATION B OTTLENECK R EGULARIZER
Modeling p ( t | x ) As discussed in § A.1, we have two ways to model p ( t | x ) : ( i ) using an auxiliary neural network to approximate the distribution; ( ii ) directly using the BERT encoder f
θ to calculate the p ( t | x ) .
Thus we implemented these two methods and compare the robustness improvement in Table 5.
To eliminate other factors such as Anchored Feature Regularizer and adversarial training, we set α = 0 , β
= 5 × 10 − 2 and conduct the following ablation experiments via standard training on standard datasets.
We observe that although both modeling methods can improve the model robustness, modeling as BERT encoder gives a larger margin than the Auxiliary
Net.
Moreover, the second way barely sacriﬁces the performance on benign data, while the ﬁrst way can hurt the benign accuracy a little bit.
Therefore, we use the BERT Encoder f θ to model the p ( t | x ) in our main paper.
Local Features v.s. Global Features Information Bottlenck Regularizer improves model robustness by reducing I ( X ; T ) .
In the main paper, we use T as word-level local features.
Here we consider T as sentence-level global features, and compare the robustness improvement with T as local features.
To eliminate other factors such as Anchored Feature Regularizer and adversarial training, we set α = 0 , β
= 5 × 10 − 2 and conduct the following ablation experiments via standard training.
[Table]
The experimental results are summarized in Table 6.
We can see that while both features can boost the model robustness, using local features yield higher robust accuracy improvement than global features, especially when adversarial training dataset is added.
Hyper-parameter Search
We perform grid search to ﬁnd out the optimal β so that the optimal trade-off between representation compression (“minimality”) and predictive power (“sufﬁciency”) is achieved.
An example to search for the optimal β on QA dataset is shown in Fingure 3, which illustrates how β affects the F1 score on benign and adversarial datasets.
We can see that from a very small β , both the robust and benign F1 scores increase, demonstrating InfoBERT can improve both robustness and generalization to some extent.
When we set β = 5 × 10 − 5 ( log( β ) = − 9 . 9 ),
InfoBERT achieves the best benign and adversarial accuracy.
When we set a larger β to further minimize I ( X i ; T i ) , we observe that the benign F1 score starts to drop, indicating the increasingly compressed representation could start to hurt its predictive capability.
A.2. A BLATION S TUDY ON A NCHORED F EATURE R EGULARIZER
Visualization of Anchored Words To explore which local anchored features are extracted, we conduct another ablation study to visualize the local anchored words.
We follow the best hyperparameters of Anchored Feature Regularizer introduced in § A.1, use the best BERT model trained on benign datasets (MNLI + SNLI) only and test on the ANLI dev set.
We visualize the local anchored words in Table 7 as follows.
In the ﬁrst example, we ﬁnd that Anchored Features mainly focus on the important features such as quantity number “Two”, the verb “playing” and objects “card”/“poker” to make a robust prediction.
In the second example, the matching robust features between hypothesis and premise, such as “people”, “roller” v
[Table]
s. “park”, “ﬂipped upside” v
[Table]
s. “ride”, are aligned to infer the relationship of hypothesis and premise.
These anchored feature examples conﬁrm that Anchored Feature Regularizer is able to ﬁnd out useful and stable features to improve the robustness of global representation
[Table]
− − − − − − − −5 log β 91.
B e n i g n F
A d v e r a r i a l
F 1 ( A dd S e n t )
Benign/Robust
SQuAD
Benign F1 Adv F1 (AddSent)
[Figure]
[Table]
A.2. A BLATION S TUDY ON D ISENTANGLING T WO R EGULARIZERS
To understand how two regularizers contribute to the improvement of robustness separetely, we apply two regularizers individually to both the standard training and adversarial training.
We refer
InfoBERT trained with IB regularizer only as “InfoBERT (IBR only)” and InfoBERT trained with
Anchored Feature Regularizer only as “InfoBERT (AFR only)”.
“InfoBERT (Both)” is the standard setting for InfoBERT, where we incorporate both regularizers during training.
For “InfoBERT (IBR only)”, we set α = 0 and perform grid search to ﬁnd the optimal β = 5 × 10 − 2 .
Similarly for “InfoBERT (AFR only)”, we set β =
and ﬁnd
the optimal parameters as α = 5 × 10 − 3 , c h = 0 .and
c l = 0 . 5 .
The results are shown in Table 8.
We can see that both regularizers improve the robust accuracy on top of vanilla and FreeLB to a similar margin.
Applying one of the regularizer can achieve similar performance of FreeLB, but the training time of InfoBERT is only 1 / 3˜1 / 2 less than FreeLB.
Moreover, after combining both regularizers, we observe that InfoBERT achieves the best robust accuracy.
A.2. E XAMPLES OF A DVERSARIAL D ATASETS GENERATED BY T EXT F OOLER
We show some adversarial examples generated by TextFooler in Table 9.
We can see most adversarial examples are of high quality and look valid to human while attacking the NLP models, thus conﬁrming our adversarial dastasets created by TextFooler is a strong benchmark dataset to evaluate model robustness.
However, as also noted in Jin et al.
(2020), we observe that some adversarial examples look invalid to human For example, in the last example of Table 9, TextFooler replaces “stand” with “position”, losing the critical information that “girls are standing instead of kneeling” and fooling both human and NLP models.
Therefore, we expect that InfoBERT should achieve better robustness when we eliminate such invalid adversarial examples during evaluation.
[Table] [Table]
[Table] [Table]
black
[Table]
dog
[Table]
playing
[Table]
white dog .
Original
[Table]
play .
[Table]
→
[Table]
share in the looking
[Table]
something
[Table]
stand
[Table]
the side
[Table]
sleeping
[Table]
are dreaming.
[Table]
Contradiction
[Table]
with
[Table]
in front
[Table]
a carousel.
[Table]
Families have some dogs in front of a carousel
[Table]
Hypothesis: Families have some doggie in front of a carousel.
[Table]
→ Entailment
[Table]
A. P ROOFS A.3. P ROOF OF T HEOREM 3.
We ﬁrst state two lemmas.
Lemma A.1.
Given a sequence of random variables X 1 , X 2 , ..., X n and a deterministic function f , then ∀ i, j = 1 , 2 , ..., n, we have
[Equation] [Equation]
Proof.
By the deﬁnition,
[Equation] [Equation]
Since f is a deterministic function,
[Equation] [Equation]
Therefore,
[Equation]
Lemma A.2.
Let X =
[ X 1 ; X 2 ; ... ; X n ] be a sequence of random variables, and T =
[ T 1 ; T 2 ; ... ; T n ] =
[ f ( X 1 ); f ( X 2 ); ... ; f ( X n )] be a sequence of random variables generated by a deterministic function f .
Then we have
I (
[Equation]
Proof.
Since X =
[ X 1 ; X 2 ; ... ; X n ] and T =
[ T 1 ; T 2 ; ... ; T n ] are language tokens with its corresponding local representations, we have
I ( X
[Equation]
, T
[Equation] [Equation]
) = n (cid:88) i =
[Equation] [Equation]
| T
[Equation] [Equation]
where the ﬁrst inequality follows because conditioning reduces entropy, and the last inequality is because I ( X i ; T i ) ≥
I ( X j ; T i ) based on Lemma A.1.
Then we directly plug Lemma A.2 into Theorem 3.1, we have the lower bound of L IB as
[Equation]
[Equation]
A.3. P ROOF OF T HEOREM 3.
We ﬁrst state an easily proven lemma,
Lemma A.3.
For any a, b ∈ [0 , 1] ,
[Equation]
where φ ( · ) : R + → R + is deﬁned as
[Equation]
It is easy to verify that φ ( x ) is a continuous, monotonically increasing, concave and subadditive function.
Now, we can proceed with the proof of Theorem 3.2.
Proof.
We use the fact that
[Equation] [Equation]
and bound each of the summands on the right separately.
We can bound the ﬁrst summand as follows:
[Equation]
t φ ( | (cid:88) x p (
[Equation]
[ p ( x
[Equation]
− q ( x
[Equation]
y
[Equation]
] | ) , (30) where p
[Equation]
=
[Equation] [Equation]
(cid:80)
[Equation] [Equation]
Since (cid:80) x ∈X∪X (cid:48) p ( x | y ) − q ( x | y ) = 0 for any y ∈ Y , we have that for any scalar a , | (cid:88) x p ( t | x )[ p ( x | y ) − q ( x | y )]) | (33) = | (cid:88)
x ( p ( t | x ) − a )( p ( x | y ) − q ( x | y )) | (34) ≤ (cid:115)(cid:88) x
( p ( t | x ) − a ) 2 (cid:115)(cid:88) x
( p ( x | y ) − q ( x | y )) 2 .
Setting a = 1 |X−X (cid:48) | (cid:80) x ∈X∪X (cid:48) p ( t | x ) we get | H ( T | Y ) − H ( T (cid:48) | Y ) ≤ (cid:88)
y p ( y ) (cid:88)
t φ (cid:0)(cid:112) V ( p ( t | x ∈ X ∪ X (cid:48) ) · || p ( x | y ) − q ( x | y ) || 2 (cid:1) , (36) where for any real-value vector a = ( a 1 , ..., a n ) , V ( a ) is deﬁned to be proportional to the variance of elements of a :
[Equation]
p ( t | x ∈ X ∪ X (cid:48) ) stands for the vector in which entries are p ( t | x ) with different values of x ∈ X ∪ X (cid:48) for a ﬁxed t , and p ( x | y ) and q ( x | y ) are the vectors in which entries are p ( x | y ) and q ( x | y ) , respectively, with different values of x ∈ X ∪ X (cid:48) for a ﬁxed y .
Since
[Equation]
38) it follows that
[Equation]
Moreover, we have
[Equation] [Equation]
where the ﬁrst inequality is because sample mean is the minimizer of the sum of the squared distances to each sample and the second inequality is due to the subadditivity of the square root function.
Using the fact that φ ( · ) is monotonically increasing and subadditive, we get
[Equation]
Now we explicate the process for establishing the bound for (cid:80) y p
( y )
(cid:80) t φ (cid:0) 2 (cid:112) V ( p ( t | x ∈ X )) (cid:1) and the one for (cid:80) y p ( y ) (cid:80) t φ (cid:0) 2 (cid:112) V ( p ( t | x ∈ X (cid:48) ))
(cid:1) can be similarly derived.
By deﬁnition of V ( · ) and using Bayes’ theorem p ( t | x ) = p ( t ) p ( x | t ) p ( x ) for x ∈ X , we have that
[Equation]
Denoting
=
(1 , ..., 1) , we have by the triangle inequality
that
[Equation]
From an inequality linking KL-divergence and the l 1 norm, we have that
[Equation]
Plugging Eq.
(52) into Eq.
(51) and using Eq.
(43), we have the following bound:
[Equation]
53) where B =√ 2log(2)
min x ∈X p ( x ) and d t = D KL [ p ( x | t ) || p ( x )] .
We will ﬁrst proceed the proof under the assumption that Bp ( t ) √ d t ≤ 1 e for any t .
We will later see that this condition can be discarded.
If Bp ( t ) √ d t ≤ 1 e , then
[Equation]
57) where the last inequality is due to an easily proven fact that for any x > 0 , x log( 1 x ) ≤ √ x .
We p ( t ) and d ( t ) are vectors comprising p ( t ) and d t with different values of t , respectively.
Using the following two inequalities:
[Equation]
58) and
[Equation] [Equation]
we have
[Equation] [Equation]
Using the equality
[Equation]
[Equation]
we reach the following bound
[Equation]
Plug Lemma A.2 into the equation above
[Equation]
we have
[Equation]
We now show the bound is trivial if the assumption that Bp ( t ) √ d t ≤ 1 e does not hold.
If the assumption does not hold, then there exists a t such that Bp ( t ) √ d t > 1 e .
Since
[Equation] [Equation]
for any t, we get that (cid:112) I
( X ; T ) ≥ 1 eB .
Since |T | ≥ 1 and C ≥ 0 , we get that our bound in Eq.
(63) is at least
[Equation] [Equation]
Let f ( c )
= log(1 /c )
e + c 1 / 2 |T | 1 / 4 e 1 /.
It can be verifed that f (cid:48) ( c ) > 0 if c > 0 .
Since B > 4 (cid:112) 2 log(2) by the deﬁnition of B , we have f ( B ) > f (4 (cid:112) 2 log(2)) > 0 .
Therefore, we have
[Equation] [Equation]
Therefore, if indeed Bp ( t ) √ d t > 1 e for some t , then the bound in Eq.
(63) is trivially true, since H ( T | Y ) is within [0 , log( |T | )] .
Similarly, we can establish a bound for (cid:80) t φ (cid:0) 2 (cid:112) V ( p ( t | x ∈ X (cid:48) ))
(cid:1) as follows:
[Equation]
where B (cid:48)
=
[Equation]
Plugging Eq.
(73) and Eq.
(65) into Eq.
(42), we get
[Equation]
−
[Equation]
Now we turn to the third summand in Eq.
(25), we have to bound | H ( T ) − H ( T (cid:48) ) | .
Recall the deﬁnition of (cid:15) -bounded adversarial example.
We denote the set of the benign data representation t that are within the (cid:15) -ball of t (cid:48) by Q ( t (cid:48) ) .
Then for any t ∈ Q ( t (cid:48) ) , we have |
[Equation]
i
[Equation]
|| ≤ (cid:15)
[Equation]
(75) for i = 1 , 2 , ..., n .
We also denote the number of the (cid:15) -bounded adversarial examples around the benign representation t by c ( t ) .
Then we have the distribution of adversarial representation t (cid:48) as follows:
[Equation]
where the inequality is by log sum inequality.
If we denote the C = max t c ( t ) which is the maximum number of (cid:15) -bounded textual adversarial examples given a benign representation t of a word sequence x , we have
[Equation]
[Equation]
Note that given a word sequence x of n with representation t , the number of (cid:15) -bounded textual adversarial examples c ( t ) is ﬁnite given a ﬁnite vocabulary size.
Therefore, if each word has at most k candidate word perturbations, then log C ≤ n log k can be viewed as some constants depending only on n and (cid:15) .
Now, combining Eq.
(25), Eq.
(74) and Eq.
(85), we prove the bound in Theorem 3.2.