Certified Robustness for Top-k Predictions against Adversarial Perturbations via Randomized Smoothing
Jinyuan Jia, Xiaoyu Cao, Binghui Wang, Neil Zhenqiang Gong
Introduction
Classifiers are vulnerable to adversarial perturbations (Szegedy et al., 2014; Goodfellow et al., 2015; Carlini & Wagner, 2017b; Jia & Gong, 2018). Specifically, given an example and a classifier , an attacker can carefully craft a perturbation such that makes predictions for as the attacker desires. Various empirical defenses (e.g., Goodfellow et al. (2015); Svoboda et al. (2019); Buckman et al. (2018); Ma et al. (2018); Guo et al. (2018); Dhillon et al. (2018); Xie et al. (2018); Song et al. (2018)) have been proposed to defend against adversarial perturbations. However, these empirical defenses were often soon broken by adaptive adversaries (Carlini & Wagner, 2017a; Athalye et al., 2018). As a response, certified robustness (e.g., Wong & Kolter (2018); Raghunathan et al. (2018a); Liu et al. (2018); Lecuyer et al. (2019); Cohen et al. (2019)) against adversarial perturbations has been developed. In particular, a robust classifier verifiably predicts the same top-1 label for data points in a certain region around any example .
In many applications such as recommender systems, web search, and image classification cloud service (Clarifai, ; Google Cloud Vision, ), top- predictions are more relevant. In particular, given an example, a set of most likely labels are predicted for the example. However, existing certified robustness results are limited to top-1 predictions, leaving top- robustness unexplored. To bridge this gap, we study certified robustness for top- predictions in this work. Our certified top- robustness leverages randomized smoothing (Cao & Gong, 2017; Cohen et al., 2019), which turns any base classifier to be a robust classifier via adding random noise to an example. For instance, Cao & Gong (2017) is the first to propose randomized smoothing with uniform noise as an empirical defense. We consider random Gaussian noise because of its certified robustness guarantee (Cohen et al., 2019). Specifically, we denote by the probability that the base classifier predicts label for the Gaussian random variable . The smoothed classifier predicts the labels with the largest probabilities ’s for the example . We adopt randomized smoothing because it is scalable to large-scale neural networks and applicable to any base classifier.
Our contributions are summarized as follows:
Theory. We derive the first certified radius for top- predictions. Moreover, we prove our certified radius is tight for randomized smoothing with Gaussian noise.
Algorithm. We develop algorithms to estimate our certified radius in practice.
Evaluation. We empirically evaluate our method on CIFAR10 and ImageNet.
Certified Radius for Top-k𝑘k Predictions
Suppose we are given an example , an arbitrary base classifier , , a smoothed classifier , an arbitrary label , and that satisfy the following conditions:
where and indicate lower and upper bounds of , respectively. Let be the largest ones among , where ties are broken uniformly at random. Moreover, we denote by the set of labels with the smallest probability upper bounds in the largest ones and by the sum of the probability upper bounds, where . Then, we have:
where is the unique solution to the following equation:
where and are the cumulative distribution function and its inverse of the standard Gaussian distribution, respectively.
Assuming we have and . Then, for any perturbation , there exists a base classifier consistent with (1) but we have .
We have several observations about our theorems.
Our certified radius is applicable to any base classifier .
According to Equation 3, our certified radius depends on , , and the largest probability upper bounds excluding . When the lower bound and the upper bounds are tighter, the certified radius is larger. When , the label is not among the top- labels predicted by the smoothed classifier even if no perturbation is added, i.e., .
When , we have , where is an upper bound of the largest label probability excluding . The certified radius derived by Cohen et al. (2019) for top-1 predictions (i.e., their Equation 3) is a special case of our certified radius with , , and .
Prediction and Certification in practice
With probability at least over the randomness in Predict, if Predict returns a set (i.e., does not ABSTAIN), then we have .
2 Certification
Given a base classifier , an example , a label , and the standard deviation of the Gaussian noise, we aim to compute the certified radius . According to our Equation 3, our relies on a lower bound of , i.e., , and the upper bound of , i.e., , which are related to , , and . We first discuss two Monte Carlo methods to estimate and with probabilistic guarantees. However, given and , it is still challenging to exactly solve as the Equation 3 does not have an analytical solution. To address the challenge, we design an algorithm to obtain a lower bound of via solving Equation 3 through binary search. Our lower bound can be tuned to be arbitrarily close to .
Our approach has two steps. The first step is to estimate and for . The second step is to estimate using for .
Estimating and for : The probabilities can be viewed as a multinomial distribution over the labels . If we sample a Gaussian noise uniformly at random, then the label can be viewed as a sample from the multinomial distribution. Therefore, estimating and for is essentially a one-sided simultaneous confidence interval estimation problem. In particular, we aim to estimate these bounds with a confidence level at least . In statistics, Goodman (1965); Sison & Glaz (1995) are well-known methods for simultaneous confidence interval estimations. However, these methods are insufficient for our problem. Specifically, Goodman’s method is based on Chi-square test, which requires the expected count for each label to be no less than 5. We found that this is usually not satisfied, e.g., ImageNet has 1,000 labels, some of which have close-to-zero probabilities and do not have more than 5 counts even if we sample a large number of Gaussian noise. Sison & Glaz’s method guarantees a confidence level of approximately , which means that the confidence level could be (slightly) smaller than . However, we aim to achieve a confidence level of at least . To address these challenges, we discuss two confidence interval estimation methods as follows:
where is the confidence level and is the th quantile of the Beta distribution with shape parameters and . We note that the Clopper-Pearson method was also adopted by Cohen et al. (2019) to estimate label probability for their certified radius of top-1 predictions.
Estimating : One natural method is to estimate . However, this bound may be loose. For example, when using BinoCP to estimate the probability bounds, we have , which may be bigger than . To address the challenge, we derive another bound for from another perspective. Specifically, we have . Therefore, we can use as an upper bound of , i.e., . Finally, we combine the above two estimations by taking the minimal one, i.e., .
It is challenging to compute the certified radius exactly because Equation 3 does not have an analytical solution. To address the challenge, we design a method to estimate a lower bound of that can be tuned to be arbitrarily close to . Specifically, we first approximately solve the following equation for each :
We note that it is still difficult to obtain an analytical solution to Equation 7 when . However, we notice that the left-hand side has the following properties: 1) it decreases as increases; 2) when , it is greater than 0; 3) when , it is smaller than 0. Therefore, there exists a unique solution to Equation 7. Moreover, we leverage binary search to find a lower bound that can be arbitrarily close to the exact solution . In particular, we run the binary search until the left-hand side of Equation 7 is non-negative and the width of the search interval is less than a parameter . Formally, we have:
After obtaining , we let be our lower bound of . Based on and Equation 8, we have the following guarantee:
2.3 Complete Certification Algorithm
Algorithm 2 shows our algorithm to estimate the certified radius for a given example and a label . The function SampleUnderNoise is the same as in Algorithm 1. Functions BinoCP and SimuEM return the estimated probability bound for each label. Function BinarySearch performs binary search to solve the Equation 7 and returns a solution satisfying Equation 8. Formally, our algorithm has the following guarantee:
With probability at least over the randomness in Certify, if Certify returns a radius (i.e., does not ABSTAIN), then we have , .
Experiments
Datasets and models: We conduct experiments on the standard CIFAR10 (Krizhevsky & Hinton, 2009) and ImageNet (Deng et al., 2009) datasets to evaluate our method. We use the publicly available pre-trained models from Cohen et al. (2019). Specifically, the architectures of the base classifiers are ResNet-110 and ResNet-50 for CIFAR10 and ImageNet, respectively.
Parameter setting: We study the impact of , the confidence level , the noise level , the number of samples , and the confidence interval estimation methods on the certified radius. Unless otherwise mentioned, we use the following default parameters: , , , , and . Moreover, we use SimuEM to estimate bounds of label probabilities. When studying the impact of one parameter on the certified radius, we fix the other parameters to their default values.
Approximate certified top- accuracy: For each testing example whose true label is , we compute the certified radius using the Certify algorithm. Then, we compute the certified top- accuracy at a radius as the fraction of testing examples whose certified radius are at least . Note that our computed certified top- accuracy is an approximate certified top- accuracy instead of the true certified top- accuracy. However, we can obtain a lower bound of the true certified top- accuracy based on the approximate certified top- accuracy. Appendix E shows the details. Moreover, the gap between the lower bound of the true certified top- accuracy and the approximate top- accuracy is negligible when is small. For convenience, we simply use the term certified top- accuracy in the paper.
2 Experimental results
Related Work
Numerous defenses have been proposed against adversarial perturbations in the past several years. These defenses either show robustness against existing attacks empirically, or prove the robustness against arbitrary bounded-perturbations (known as certified defenses).
The community has proposed many empirical defenses. The most effective empirical defense is adversarial training (Goodfellow et al., 2015; Kurakin et al., 2017; Tramèr et al., 2018; Madry et al., 2018). However, adversarial training does not have certified robustness guarantees. Other examples of empirical defenses include defensive distillation (Papernot et al., 2016), MagNet (Meng & Chen, 2017), PixelDefend (Song et al., 2017), Feature squeezing (Xu et al., 2018), and many others (Liu et al., 2019; Svoboda et al., 2019; Schott et al., 2019; Buckman et al., 2018; Ma et al., 2018; Guo et al., 2018; Dhillon et al., 2018; Xie et al., 2018; Song et al., 2018; Samangouei et al., 2018; Na et al., 2018; Metzen et al., 2017). However, many of these defenses were soon broken by adaptive attacks (Carlini & Wagner, 2017a; Athalye et al., 2018; Uesato et al., 2018; Athalye & Carlini, 2018).
2 Certified defenses
Randomized smoothing was first proposed as an empirical defense (Cao & Gong, 2017; Liu et al., 2018) without deriving the certified robustness guarantees. For instance, Cao & Gong (2017) proposed randomized smoothing with uniform noise from a hypercube centered at an example. Lecuyer et al. (2019) was the first to prove the certified robustness guarantee of randomized smoothing for top-1 predictions. Their results leverage differential privacy. Subsequently, Li et al. (2018) further leverages information theory to improve the certified radius bound. Cohen et al. (2019) obtains a tight certified radius bound for randomized smoothing with Gaussian noise by leveraging the Neyman-Pearson Lemma. Pinot et al. (2019) theoretically demonstrated the robustness to adversarial attacks of randomized smoothing when adding noise from Exponential family distributions and devised an upper bound on the adversarial generalization gap of randomized neural networks. Lee et al. (2019) generalized randomized smoothing to discrete data. Salman et al. (2019) employed adversarial training to improve the performance of randomized smoothing. Unlike the other certified defenses, randomized smoothing is scalable to large neural networks and applicable to arbitrary classifiers. Our work derives the first certified robustness guarantee of randomized smoothing for top- predictions. Moreover, we show that our robustness guarantee is tight for randomized smoothing with Gaussian noise.
Conclusion
ACKNOWLEDGMENTS We thank the anonymous reviewers for insightful reviews. This work was supported by NSF grant No. 1937786.
References
Appendix A Proof of Theorem 1
Given an example , we define the following two random variables:
where . The random variables and represent random samples obtained by adding isotropic Gaussian noise to the example and its perturbed version , respectively. Cohen et al. (2019) applied the standard Neyman-Pearson Lemma (Neyman & Pearson, 1933) to the above two random variables, and obtained the following lemma:
Moreover, we have the following lemma from Cohen et al. (2019).
Given an example , a number , and regions and defined as follows:
Based on Lemma 1 and 2, we derive the following lemma:
Suppose we have an arbitrary base classifier , an example , a set of labels which are denoted as , two probabilities and that satisfy , and regions and defined as follows:
which is the first inequality in (21). The second inequality in (21) can be obtained similarly. ∎
Next, we restate Theorem 1 and show our proof.
Roughly speaking, our idea is to make the probability that the base classifier predicts when taking as input larger than the smallest one among the probabilities that predicts for a set of arbitrary labels selected from all labels except . For simplicity, we let , i.e., all labels except . We denote by a set of labels in . We aim to find a certified radius such that we have , which guarantees . We first upper bound the minimal probability for a given , and then we upper bound the maximum value of the minimal probability among all possible . Finally, we obtain the certified radius via letting the upper bound of the maximum value smaller than .
Bounding for a given : We use to denote a non-empty subset of and use to denote its size. We define , which is the sum of the upper bounds of the probabilities for the labels in . Moreover, we define the following region associated with the set :
We have by applying Lemma 3 to the set . In addition, we have . Therefore, we have:
where we have the first inequality because is a subset of and we have the second inequality because the smallest value in a set is no larger than the average value of the set. Equation 27 holds for any . Therefore, by taking all possible sets into consideration, we have the following:
where is the set of labels in whose probability upper bounds are the smallest, where ties are broken uniformly at random. We have Equation 30 from Equation 29 because decreases as decreases.
Bounding : Since increases as increases, Equation 30 reaches its maximum value when , i.e., when is the set of labels in with the largest probability upper bounds. Formally, we have:
where .
Obtaining : According to Lemma 3, we have the following for :
Recall that our goal is to make . It suffices to let:
According to Lemma 2, we have and . Therefore, we have the following constraint on :
Since the left-hand side of the above inequality 1) decreases as increases, 2) is larger than 0 when , and 3) is smaller than 0 when , we have the constraint , where is the unique solution to the following equation:
Appendix B Proof of Theorem 2
Following the terminology we used in proving Theorem 1, we define a region as follows:
According to Lemma 2, we have . We first show the following lemma, which is the key to prove our Theorem 2.
where the random variables and are defined in Equation 10 and 11, respectively; and and are defined in Theorem 1.
Our proof is based on mathematical induction and the intermediate value theorem. For convenience, we defer the proof to Appendix B.1. ∎
Next, we restate Theorem 2 and show our proof. See 2
Based on the definition of , we have the following:
Therefore, satisfies the conditions in (1). Next, we show that is not among the top- labels predicted by the smoothed classifier for any perturbed example when . Specifically, we have:
where . Since we have found labels whose probabilities are larger than the probability of the label , we have when . ∎
We first define some key notations and lemmas that will be used in our proof.
Given two values and that satisfy , we define the following region:
where the Gaussian random variable is defined in Equation 10. Moreover, assuming we have pairs of , , where , . We define the following region:
is the remaining region of excluding . Given two values and that satisfy , we also define the following two functions:
where the random variables and are defined in Equation 10 and 11, respectively.
Next, we show a key property of our defined functions and .
If and (or , then we have .
Scenario I: . We denote and as the probability densities for the random variables and , respectively. Then, we have and . Therefore, the ratio of the probability density of and the probability density of at a given point is as follows:
Next, we compare the ratio for the points in different regions and have the following:
The Equation 57 from 56 is based on Equation 55 and the fact that for any point in the region from Definition 1. Similarly, we can obtain Equation 59 from 58. We note that the Equation 58 from 57 is because . Based on Equation 57 and 58, we know that there exists a real number such that:
Combining the Equation 56, 57, and 60, we have the following:
Taking an integral on both sides of the Equation 61 in the region and recalling the definition of and , we have the following:
Based on Equation 62, 63, and the condition that , we have the following:
Scenario II: . We have:
Therefore, we have the following equation:
Similar to Scenario I, we know that there exists such that:
Similar to Scenario I, we have the following based on Equation 66:
Scenario III: . As , we have . Therefore, we have . ∎
Next, we list the well-known Intermediate Value Theorem and show several other properties of our defined functions and .
If a function is continuous at every point in the interval and , then there exists such that .
Roughly speaking, the Intermediate Value Theorem tells us that if a continuous function has values no larger and no smaller (or no smaller and no larger) than at the two end points of an interval, respectively, then the function takes value at some point in the interval.
Given two probabilities , if we have:
Then, there exists such that:
then there exists such that:
We define function . Then, we have since and based on Equation 70. Therefore, according to Lemma 6, there exists such that:
Similarly, we can prove that there exists such that .
For any , we define . Then, we know since . Moreover, we have . Therefore, we have . According to Lemma 6,we know there exists such that for arbitrary . We define where , and are a value such that for a given . When , we can let since , and when , we can let since . Based on Equation 73 and Lemma 6, we know that there exists such that . Therefore, there exists and such that:
Assuming we have , . If , then we have the following:
If , then we have since no region is excluded. Therefore, we have based on Equation 51. We note that when and . Therefore, we can obtain Equation 80 based on the definition of from Definition 1. ∎
If we have , then we have the following:
We further generalize Lemma 5 to two regions. Specifically, we have the following lemma:
Assuming we have a region and we have . If , and , then we have:
We let . As and , we can obtain the conclusion by applying Lemma 5 on . ∎
Next, we restate Lemma 4 and show our proof. See 4
Our proof leverages Mathematical Induction, which contains two steps. In the first step, we show that the statement holds initially. In the second step, we show that if the statement is true for the th iteration, then it also holds for the th iteration. Without loss of generality, we assume . Therefore, we have the following:
Recall the definition of and we have the following:
where . We can split into two parts: and . We will show that , we can find disjoint whose union is such that:
For the other part, we will show that , we can find disjoint whose union is such that:
We first show that , we can find that satisfy Equation 85 and 86. Since our proof leverages Mathematical Induction, we iteratively construct each . Specifically, we first show that we can find that satisfies the requirements. Then, assuming we can find , we show that we can find . We will leverage Lemma 7 to prove the existence for each . Next, we show the two steps.
Step I: We show that we can find that satisfies Equation 85 and 86. We let and , and we define the following region:
which can be directly obtained as . As we have , there exist such that:
The equality in the middle is from Lemma 8, the left inequality is because , and the right inequality is from Equation 83. Furthermore, we have the following:
We obtain Equation 100 from Equation 99 based on Lemma 8, and Equation 101 from Equation 100 based on Equation 83. Therefore, we have the following:
Thus, there exists such that based on Lemma 7. Then, we have the following based on the definition of :
Finally, we let , which meets our goal.
Step II: Assuming we can find () where such that , we have:
We denote . We show we can find such that we have:
We let and denote
The Equation 116 from 115 is based on the Equation 108, and the Equation 117 from 116 is based the Equation 51 and 106. Furthermore, we have the following:
The Equation 123 from 122 is because and the Equation 107. We have . Therefore, based on Lemma 7, there exist such that:
Equation 128 from 127 is based on Lemma 9, Equation 129 from 128 is based on Equation 90 and 125, and Equation 130 from 129 is obtained from Equation 91 and the fact that . Next, we show:
In particular, we consider two scenarios.
Scenario 1). . We denote . We let . As and , we have the following based on Lemma 10:
Scenario 2). . We have the following:
Moreover, we have from Lemma 8. The above two should be equal. Thus, we have since . we have:
We obtain Equation 140 from Equation 139 based on Lemma 8.
Therefore, we have the following in both scenarios:
Based on Lemma 7, there exist such that . Then, we have the following based on the definition of :
We let . From the definition of , we have . Thus, we have since .
Therefore, we reach our goal by Mathematical Induction, i.e., for , we have:
We can also verify that .
Next, we show our proof based on Mathematical Induction for the other part, i.e., . Our construction process is similar to the above first part but has subtle differences.
Step I: Let and . We define:
The Equation 150 is based on the fact that and Definition 1, and we obtain Equation 154 from 155 based on Equation 83. We have . Therefore, based on Lemma 7, we know that there exists such that:
Scenario 1). In this scenario, we consider . We let , i.e., we have . Then, we have:
Scenario 2). In this scenario, we consider . We have the following:
We obtain Equation 167 from 166 via Lemma 9, and we obtain Equation 168 from 167 based on Equation 150 to 156 and the fact . We have . Therefore, from Lemma 7, we know that there exist such that:
Similarly, we let .
Based on the conditions of our constructions in the two scenarios, we know that if , then we have .
Step II: We show that if we can find where and such that:
Then, we can find such that:
For simplicity, we denote , we let and , and we define:
We have . Therefore, based on Lemma 7, we know that there exists such that:
Scenario 1). In this scenario, we consider that the following holds:
We let , i.e., . Then, we have:
We note that we have in this scenario. Otherwise, Equation 186 will not hold based on Lemma 10. We give a short proof.
Assuming . We denote . We let . Note that in this case, we have because and cannot hold at the same time as long as . Thus, we have because if , we have . As we have and . We have the following based on Lemma 10:
Since Equation 186 and Equation 189 cannot hold at the same time, the assumption must be wrong. Therefore, we have .
Based on , we have the following:
Therefore, we have from Definition 1. Moreover, we have the following:
The above two should be equal. Therefore, we have . Recall that we let . Thus, we have:
Scenario 2). In this scenario, we consider that the following holds:
We obtain Equation 203 from 202 via Lemma 9, and we obtain Equation 204 from 203 based on Equation 183 and the fact . We have . Based on Lemma 7, we can find such that we have:
We let . We also have the following:
Similar to Step I, we still hold the conclusion that if , we have . Then, we can apply Mathematical Induction to reach the conclusion. Also, we can verify . ∎
Appendix C Proof of Proposition 1
Proposition 1: With probability at least over the randomness in Predict, if Predict returns a set (i.e., does not ABSTAIN), then we have .
We aim to compute the probability that Predict returns a set which not equals to , which happens if and only if and Predict doesn’t abstain. Specifically, we have:
Theorem 1 in Hung et al. (2019) shows the above conditional probability is as follows:
Appendix D Proof of Proposition 2
Proposition 2: With probability at least over the randomness in Certify, if Certify returns a radius (i.e., does not ABSTAIN), then we have .
From the definition of BinoCP and SimuEM, we know the probability that the following inequalities simultaneously hold is at least over the sampling of counts:
Then, with the returned bounds, we can invoke Theorem 1 to obtain the robustness guarantee if the calculated radius is larger than 0. Note that otherwise Certify abstains. ∎
Appendix E Certified top-k𝑘k accuracy
We show how to derive a lower bound of the certified top- accuracy based on the approximate certified top- accuracy. The process is similar to that Cohen et al. (2019) used to derive a lower bound of the certified top- accuracy based on the approximate certified top- accuracy. Specifically, we have the following lemma from Cohen et al. (2019).
Let be a binary variable and be a Bernoulli random variable. Suppose if , then . Then, for any , with probability at least , we have the following:
Assuming we have a test dataset as well as a radius . We define the following indicate value:
Then, the certified top- accuracy of the smoothed classifier at radius can be computed as . For each sample , we run the Certify function with confidence level and we use a random variable to denote that the function Certify returns a radius bigger than . From Proposition 2, we know:
The approximate certified top- accuracy of the smoothed classifier at radius is . Then, we can use Lemma 11 to obtain a lower bound of . Specifically, for any , with probability at least over the randomness of Certify, we have:
We can see that the difference between the certified top- accuracy and the approximate certified top- accuracy is negligible when is small.