G ENERATING N ATURAL A DVERSARIAL E XAMPLES
A BSTRACT
Due to their complex nature, it is hard to characterize the ways in which machine learning models can misbehave or be exploited when deployed.
Recent work on adversarial examples, i.e. inputs with minor perturbations that result in substantially different model predictions, is helpful in evaluating the robustness of these models by exposing the adversarial scenarios where they fail.
However, these malicious perturbations are often unnatural, not semantically meaningful, and not applicable to complicated domains such as language.
In this paper, we propose a framework to generate natural and legible adversarial examples that lie on the data manifold, by searching in semantic space of dense and continuous data representation, utilizing the recent advances in generative adversarial networks.
We present generated adversaries to demonstrate the potential of the proposed approach for black-box classiﬁers for a wide range of applications such as image classiﬁcation, textual entailment, and machine translation.
We include experiments to show that the generated adversaries are natural, legible to humans, and useful in evaluating and analyzing black-box classiﬁers.
I NTRODUCTION
With the impressive success and extensive use of machine learning models in various securitysensitive applications, it has become crucial to study vulnerabilities in these systems.
Dalvi et al.
(2004) show that adversarial manipulations of input data often result in incorrect predictions from classiﬁers.
This raises serious concerns regarding the security and integrity of existing machine learning algorithms, especially when even state-of-the-art models including deep neural networks have been shown to be highly vulnerable to adversarial attacks with intentionally worst-case perturbations to the input (Szegedy et al., 2014; Goodfellow et al., 2015; Kurakin et al., 2016; Papernot et al., 2016b; Kurakin et al., 2017).
These adversaries are generated effectively with access to the gradients of target models, resulting in much higher successful attack rates than data perturbed by random noise of even larger magnitude.
Further, training models by including such adversaries can provide machine learning models with additional regularization beneﬁts (Goodfellow et al., 2015).
Although these adversarial examples expose “blind spots” in machine learning models, they are unnatural , i.e. these worst-case perturbed instances are not ones the classiﬁer is likely to face when deployed.
Due to this, it is difﬁcult to gain helpful insights into the fundamental decision behavior inside the black-box classiﬁer: why is the decision different for the adversary, what can we change in order to prevent this behavior, and is the classiﬁer robust to natural variations in the data when not in an adversarial scenario?
Moreover, there is often a mismatch between the input space and the semantic space that we can understand.
Changes to the input we may not think meaningful, like slight rotation or translation in images, often lead to substantial differences in the input instance.
For example, Pei et al.
(2017) show that minimal changes in the lighting conditions can fool automated-driving systems, a behavior adversarial examples are unable to discover.
Due to the unnatural perturbations, these approaches cannot be applied to complex domains such as language, in which enforcing grammar and semantic similarity is difﬁcult when perturbing instances.
Therefore, existing approaches that ﬁnd adversarial examples for text often result in ungrammatical sentences, as in the examples generated by Li et al.
(2016), or require manual intervention, as in Jia & Liang (2017).
In this paper, we introduce a framework to generate natural adversarial examples, i.e. instances that are meaningfully similar, valid/legible, and helpful for interpretation.
The primary intuition
[Figure]
behind our proposed approach is to perform the search for adversaries in a dense and continuous representation of the data instead of searching in the input data space directly.
We use generative adversarial networks (GANs) (Goodfellow et al., 2014) to learn a projection to map normally distributed ﬁxed-length vectors to data instances.
Given an input instance, we search for adversaries in the neighborhood of its corresponding representation in latent space by sampling within a range that is recursively tightened.
Figure 1 provides an example of adversaries for digit recognition.
Given a multi-layer perceptron (MLP) for MNIST and an image from test data (Figure 1a), our approach generates a natural adversarial example (Figure 1e) which is classiﬁed incorrectly as “2” by the classiﬁer.
Compared to the adversary generated by the existing Fast Gradient Sign
Method (FGSM) (Goodfellow et al., 2015) that adds gradient-based noise (Figures 1c and 1b), our adversary (Figure 1e) looks like a hand-written digit similar to the original input.
Further, the difference (Figure 1d) provides some insight into the classiﬁer’s behavior, such as the fact that slightly thickening (blue) the bottom stroke and thinning (red) the one above it, fools the classiﬁer.
We apply our approach to both image and text domains, and generate adversaries that are more natural and grammatical, semantically close to the input, and helpful to interpret the local behavior of black-box models.
We present examples of natural adversaries for image classiﬁcation, textual entailment, and machine translation.
Experiments and human evaluation also demonstrate that our approach can help evaluate the robustness of black-box classiﬁers, even without labeled training data.
F RAMEWORK FOR G ENERATING N ATURAL A DVERSARIES
In this section, we describe the problem setup and details of our framework for generating natural adversarial examples of both continuous images and discrete text data.
Given a black-box classiﬁer f and a corpus of unlabeled data X , the goal here is to generate adversarial example x ∗ for a given data instance x that results in a different prediction, i.e. f ( x ∗ ) (cid:54) =
f
( x ) .
In general, the instance x may not be in X , but comes from the same underlying distribution P x , which is the distribution we want to generate x ∗ from as well.
We want x ∗ to be the nearest such instance to x in terms of the manifold that deﬁnes the data distribution P x , instead of in the original data representation.
Unlike other existing approaches that search directly in the input space for adversaries, we propose to search in a corresponding dense representation of z space.
In other words, instead of ﬁnding the adversarial x ∗ directly, we ﬁnd the adversarial z ∗ in an underlying dense vector space which deﬁnes the distribution P x , and then map it back to x ∗ with the help of a generative model.
By searching for samples in the latent low-dimensional z space and mapping them to x space to identify the adversaries, we encourage these adversaries to be valid (legible for images, and grammatical for sentences) and semantically close to the original input.
Background: Generative Adversarial Networks To tackle the problem described above, we need powerful generative models to learn a mapping from the latent low-dimensional representation to the distribution P x , which we estimate using samples in X .
GANs are a class of such generative models that can be trained via procedures of minimax game between two competing networks (Goodfellow et al., 2014): given a large amount of unlabeled instances X as training data, the generator G θ learns to map some noise with distribution
p z
( z ) where z ∈ IR d to synthetic data that is as close to the training data as possible; on the other hand, the critic C ω is trained to discriminate the output of the
[Figure]
generator from real data samples from X .
The original objective function of GANs has been found to be hard to optimize in practice, for reasons theoretically investigated in Arjovsky & Bottou (2017).
Arjovsky et al.
(2017) reﬁne the objective with Wasserstein-1 distance as:
[Equation]
Wasserstein GAN achieves improvement in the stability of learning and provides useful learning curves.
A number of further improvements to the GAN framework have been introduced (Salimans et al., 2016; Arjovsky & Bottou, 2017; Gulrajani et al., 2017; Rosca et al., 2017) that we discuss in Section 6.
We incorporate the structure of WGAN and relevant improvements as a part of our framework for generating natural examples close to the training data distribution, as we describe next.
Natural Adversaries
In order to represent natural instances of the domain, we ﬁrst train a WGAN on corpus X , which provides a generator G θ that maps random dense vectors z ∈ IR
d to samples x from the domain of X .
We separately train a matching inverter I γ to map data instances to corresponding dense representations.
As in Figure 2, we minimize the reconstruction error of x , and the divergence between sampled z and I γ ( G θ ( z )) to encourage the latent space to be normally distributed:
[Equation]
Using these learned functions, we deﬁne the natural adversarial example x ∗ as the following:
[Equation]
Instead of x , we perturb its dense representation z (cid:48)
=
I γ ( x ) , and use the generator to test whether a perturbation ˜
z fools the classiﬁer by querying f with ˜ x
= G θ (˜ z ) .
Figure 3 shows our generation process.
A synthetic example is included for further intuition in Appendix A.
As for the divergence
L , we use L 2 distance with λ = .
1 for images and Jensen-Shannon distance with λ = 1 for text data.
Search Algorithms We propose two approaches to identify the adversary (pseudocode in Appendix B), both of which utilize the inverter to obtain the latent vector z (cid:48)
=
I γ ( x ) of x , and feed perturbations ˜ z in the neighborhood of z (cid:48) to the generator to generate natural samples ˜ x
= G θ (˜ z ) .
In iterative stochastic search (Algorithm 1), we incrementally increase the search range (by ∆ r ) within which the perturbations ˜
z are randomly sampled ( N samples for each iteration), until we have generated samples ˇ x that change the prediction.
Among these samples ˇ x , we choose the one which has the closest z ∗ to the original z (cid:48) as an adversarial example x ∗ .
To improve the efﬁciency beyond this naive search, we propose a coarse-to-ﬁne strategy we call hybrid shrinking search (Algorithm 2).
We ﬁrst search for adversaries in a wide search range, and recursively tighten the upper bound of the search range with denser sampling in bisections.
Extra iterative search steps are taken to further generator G θ
[Equation]
noise ˜
z latent z (cid:48) naturaladversary x ∗ perturbations f
[Table]
tighten the upper bound of the optimal ∆ z .
With the hybrid shrinking search in Algorithm 2, we observe a 4 × speedup while achieving similar results as Algorithm 1.
Both these search algorithms are sample-based and applicable to black-box classiﬁers with no need of access to their gradients.
Further, they are guaranteed to ﬁnd an adversary, i.e. one that upper bounds the optimal adversary.
I LLUSTRATIVE E XAMPLES
We demonstrate the potential of our approach (Algorithm 1) in generating informative, legible, and natural adversaries by applying it to a number of classiﬁers for both visual and textual domains.
3. G ENERATING I MAGE A DVERSARIES
Image classiﬁcation has been a focus for adversarial example generation due to the recent successes in computer vision.
We apply our approach to two standard datasets, MNIST and LSUN, and present generated natural adversaries.
We use ∆ r = 0 .
01 and N = 5000 with model details in Appendix C.
Handwritten Digits Scans of human-written text provide an intuitive deﬁnition of what is natural , i.e. do the generated images look like something a person would write?
In other words, how would a human change a digit in order to fool a classiﬁer?
We train a WGAN with z ∈ IR 64 on 60,000 MNIST images following similar procedures as in Gulrajani et al.
(2017), with the generator consisting of transposed convolutional layers and the critic consisting of convolutional layers.
We include the inverter with fully connected layers on top of the critic’s last hidden layer.
We train two target classiﬁers to generate adversaries against: Random Forests (RF) with 5 trees (test accuracy 90.45%), and LeNet, as trained in LeCun et al.
(1998) (test accuracy 98.71%).
We treat both these classiﬁers as black-boxes, and present the generated adversaries in Table 1 with examples of each digit (from test instances that the GAN or classiﬁers never observed).
Adversaries generated by FGSM look like the original digits eroded by uninterpretable noise (these may not be representative of the approach, as changing (cid:15) for the method results in substantially different results).
Our natural adversaries against both classiﬁers are quite similar to the original inputs in overall style and shape, yet provide informative insights into classiﬁers’ decision behavior around the input.
Take the digit “5” as an example: dimming the vertical stroke can fool LeNet into predicting “3”.
Further we observe that adversaries against RF often look closer to the original images in overall shape than those against
LeNet.
Although generating as impressive natural adversaries against more accurate LeNet is difﬁcult, it implies that compared to RF, LeNet requires more substantial changes to the inputs to be fooled; in other words, RF is less robust than LeNet in classiﬁcation.
We will return to this observation later.
Church vs Tower We apply our approach to outdoor, color images of higher resolution.
We choose the category of “Church Outdoor” in LSUN dataset (Yu et al., 2015), randomly sample the same amount of 126,227 images from the category of “Tower”, and resize them to resolution of 64 × 64.
[Table] [Table]
The training procedure is similar to MNIST, except that the generator and critic in WGAN are deep residual networks (He et al., 2016) and z ∈ IR 128 .
We train an MLP classiﬁer on these two classes with test accuracy of 71.3%.
Table 2 presents original images for both classes and corresponding adversarial examples.
From looking at these pairs, we can observe that the generated adversaries make changes that are natural for this domain.
For example, to change the classiﬁer’s prediction from “Church” to “Tower”, the adversaries sharpen the roof, narrow the buildings
[Table]
or change a tree into a tower.
We can observe similar behavior in the other direction: the image with the Eiffel Tower is changed to a “church” by converting a woman into a building, and narrowing the tower.
3. G ENERATING T EXT A DVERSARIES
Generating grammatical and linguistically coherent adversarial sentences is a challenging task due to the discrete nature of text: adding imperceptible noise is impossible
[Table]
and most actual changes to x may not result in grammatical text.
Prior approaches on generating textual adversaries (Li et al., 2016;
Alvarez-Melis & Jaakkola, 2017; Jia & Liang, 2017) perform word erasures and replacements directly on text input space x , using domain-speciﬁc rule based or heuristic based approaches, or require manual intervention.
Our approach, on the other hand, performs perturbations in the continuous space z , that has been trained to produce semantically and syntactically coherent sentences automatically.
We use the adversarially regularized autoencoder (ARAE)
(Zhao et al., 2017) for encoding discrete text into continuous codes.
ARAE model encodes a sentence with an LSTM encoder into continuous code and then performs adversarial training on these codes to capture the data distribution.
We introduce an inverter that maps these continuous codes into the Gaussian space of z ∈ IR 100 .
We use a 4-layer strided CNN for the encoder as it yields more coherent sentences than LSTMs from the
ARAE model, however LSTM works well as the decoder.
We train two MLP models for the generator and the inverter, to learn mappings between noise and continuous codes.
We train our framework on the Stanford Natural Language Inference (SNLI) (Bowman et al., 2015) data of 570k labeled human-written English sentence pairs with the same preprocessing as Zhao et al.
(2017), using ∆ r = 0.01 and N = 100.
We present details of the architecture and sample perturbations in Appendix D.
Textual Entailment Textual Entailment (TE) is a task designed to evaluate common-sense reasoning for language, requiring both natural language understanding and logical inferences for text snippets.
In this task, we classify a pair of sentences, a premise and a hypothesis , into three categories depending on whether the hypothesis is entailed by the premise, contradicts the premise, or is neutral to it.
For
[Table] [Table]
instance, the sentence “There are children present” is entailed by the sentence “Children smiling and waving at camera”, while the sentence “The kids are frowning” contradicts it.
We use our approach to generate adversaries by perturbing the hypothesis to deceive classiﬁers, keeping the premise unchanged.
We train three classiﬁers of varying complexity, namely, an embedding classiﬁer that is a single layer on top of the average word embeddings, an LSTM based model consisting of a single layer on top of the sentence representations
[Table]
and TreeLSTM (Chen et al., 2017) that uses a hierarchical LSTM on the parses and is a top-performing classiﬁer for this task.
A few examples comparing the three classiﬁers are shown in Table 3 (more examples in Appendix D.1).
Although all classiﬁers correctly predict the label, as the classiﬁers get more accurate (from embedding to LSTM to TreeLSTM ), they require much more substantial changes to the sentences to be fooled.
Machine translation We consider machine translation not only because it is one of the most successful applications of neural approaches to NLP, but also since most practical translation systems lie behind black-box access APIs.
The notion of adversary , however, is not so clear here as the output of a translation system is not a class.
Instead, we deﬁne adversary for machine translation relative to a probing function that tests the translation for certain properties, ones that may lead to linguistic insights into the languages, or detect potential vulnerabilities.
We use the same generator and inverter as in entailment, and ﬁnd such “adversaries” via API access to the currently deployed
Google Translate model (as of October 15, 2017 ) from English to German.
First, let us consider the scenario in which we want to generate adversarial English sentences such that a speciﬁc German word is introduced into the German translation.
The probing function here would test the translation for the presence of that word, and we would have found an adversary (an
English sentence) if the probing function passes for a translation.
We provide an example of such a probing function that introduces the word “stehen” (“stand” in English) to the translation in Table(more examples in Appendix D.2).
Since the translation system is quite strong, such adversaries are not surfacing the vulnerabilities of the model, but instead can be used as a tool to understand or learn different languages (in this example, help a German speaker learn English).
We can design more complex probing functions as well, especially ones that target speciﬁc vulnerabilities of the translation system.
Let us consider translations of English sentences that contain two active verbs, e.g. “People sitting in a restaurant eating”, and see that the German translation has the two verbs as well, “essen” and “sitzen”, respectively.
We now deﬁne a probing function that passes only if the perturbed English sentence s (cid:48) contains both the verbs, but the translation only has one of them.
An adversary for such a probing function will be an English sentence ( s (cid:48) ) that is similar to the original sentence ( s ), but for some reason, its translation is missing one of the verbs.
Table 5 presents examples of generated adversaries using such a probing function (with more in Appendix D.2).
For example, one that tests whether “essen” is dropped from the translation when its English counterpart “eating” appears in the source sentence (“People sitting in a living room eating.”).
These adversaries thus suggest a vulnerability in Google’s English to German translation system: a word acting as a gerund in English often gets dropped from the translation.
[Table]
[Figure]
E XPERIMENTS
In this section, we demonstrate that our approach can be utilized to compare and evaluate the robustness of black-box models even without labeled data.
We present experimental results on images and text data with evaluations from both statistical analysis and pilot user studies.
Robustness of Black-box Classiﬁers We apply our framework to various black-box classiﬁers for both images and text, and observe that it is useful for evaluating and interpreting these models via comparisons.
The primary intuition behind this analysis is that more accurate classiﬁers often require more substantial changes to the instance to change their predictions, as noted in the previous section.
In the following experiments, we apply the more efﬁcient hybrid shrinking search (Algorithm 2).
In order to quantify the extent of change for an adversary, the change in the original x representation may not be meaningful, such as RMSE of the pixels or string edit distances, for the same reason we are generating natural adversaries: they do not correspond to the semantic distance underlying the data manifold.
Instead we use the distance of the adversary in the latent space, i.e. ∆ z = (cid:107) z ∗ − z (cid:48) (cid:107) , in order to measure how much each adversary is modiﬁed to change the classiﬁer prediction.
We also consider the set of adversaries generated for each instance against a group of classiﬁers, and count how many times the adversary of each classiﬁer has the highest ∆ z .
We present these statistics in
Table 6 for both MNIST (over 100 test images, 10 per digit) and Textual Entailment (over 1260 test sentences), against the classiﬁers we described in Section 3.
For both the tasks, we observe that more accurate classiﬁers require larger changes to the inputs (by both measures), indicating that generating such adversaries, even for unlabeled data, can evaluate the accuracy of black-box classiﬁers.
[Table] [Table]
We now consider evaluation on a broader set of classiﬁers, and study the effect of changing hyperparameters of models on the results (focusing on MNIST).
We train a set of neural networks with one hidden layer by varying the number of neurons exponentially from 2 to 1024.
In Figure 4a, we observe that the average ∆ z of adversaries against these models has a similar trend as their test accuracy.
The generated adversaries for a single digit “3” in Figure 4d verify this observation: the adversaries become increasingly different from the original input as classiﬁers become more complex.
We provide similar analysis by ﬁxing the model structure but varying the dropout rates from 0.9 to 0.0 in Figure 4b, and observe a similar trend.
To conﬁrm that this correlation holds generally, we train 80 total classiﬁers that differ in the layer sizes, regularization, and amount of training data, and plot their test set accuracy against the average magnitude of change in their adversaries in Figure 4c.
Given this strong correlation, we are conﬁdent that our framework for generating natural adversaries can be useful for automatically evaluating black-box classiﬁers, even in the absence of labeled data.
Human Evaluation We carry out a pilot study with human subjects to evaluate how natural the generated adversaries are, and whether the adversaries they think are similar to the original ones correspond with the less accurate classiﬁers (as in the evaluation above).
For both image classiﬁcation and textual entailment, we select a number of instances randomly, generate adversaries for each against two classiﬁers, and present a questionnaire to the subjects that evaluates: (1) how natural or legible each generated adversary is; (2) which of the two adversaries is closer to the original instance.
For hand-written digits from MNIST, we pick 20 images (2 for each digit), generate adversaries against RF and LeNet (two adversaries for each image), and obtain 13 responses for each of the questions.
In Table 7, we see that the subjects agree that our generated adversaries are quite natural, and also, they ﬁnd RF adversaries to be much closer to the original image than LeNet (i.e. more accurate classiﬁers, as per test accuracy on their provided labels, have more distant adversaries).
We also compare adversaries against LeNet generated by FGSM and our approach, and ﬁnd that 78% of the time the subjects agree that our adversaries make changes to the original images that are more natural (it is worth noting that FGSM is not applicable to RF for comparison).
We carry out a similar pilot study for the textual entailment task to evaluate the quality of the perturbed sentences.
We present a set of 20 pairs of sentences (premise and hypothesis), and adversarial hypotheses against both LSTM and TreeLSTM classiﬁers, and receive 4 responses for each of the questions above.
The results in Table 8 also validate our previous results: the generated sentences are found to be grammatical and legible, and classiﬁers that need more substantial changes to the hypothesis tend to be more accurate.
We leave a more detailed user study for future work.
R ELATED W ORK
The fast gradient sign method (FGSM) has been proposed in Goodfellow et al.
(2015) to generate adversarial examples fast rather than optimally.
Intuitively, the method shifts the input by (cid:15) in the direction of minimizing the cost function.
Kurakin et al.
(2016) propose a simple extension of FGSM by applying it multiple times, which generates adversarial examples with a higher attack rate, but the underlying idea is the same.
Another method known as the Jacobian-based saliency map attack (JSMA) has been introduced by Papernot et al.
(2016b).
Unlike FGSM, JSMA generates adversaries by greedily modifying the input instance feature-wise.
A saliency map is computed with gradients to indicate how important each feature is for the prediction, and the most important one is modiﬁed repeatedly until the instance changes the resulting classiﬁcation.
Moreover, it has been observed in practice that adversarial examples designed against a model are often likely to successfully attack another model for the same task that has not been given access to.
This transferability property of adversarial examples makes it more practical to attack and evaluate deployed machine learning systems in realistic scenarios (Papernot et al., 2016a; 2017).
All these attacks above are based on gradients with access to the parameters of differentiable classiﬁers.
Moosavi-Dezfooli et al.
(2017) try to ﬁnd a single noise vector which can cause imperceptible changes in most of data points, and meanwhile reduce the classiﬁer accuracy signiﬁcantly.
Our method is capable of generating adversaries against black-box classiﬁers, even those without gradients such as Random Forests.
Also, the noise added by these methods is uninterpretable, while the natural adversaries generated by our approach provide informative insights into classiﬁers’ decision behavior.
Due to the discrete domains involved in text, adversaries for text have received less attention.
Jia & Liang (2017) generate adversarial examples for evaluating reading comprehension systems with predeﬁned rules and candidate words for substitution after analyzing and rephrasing the input sentences.
Li et al.
(2016) introduce a framework to understand neural network through different levels of representation erasure.
However, erasure of words or phrases directly often harms text integrity, resulting in semantically or grammatically incorrect sentences.
Ribeiro et al.
(2018) replace tokens by random words of the same POS tag with probability proportional to embedding similarity.
Belinkov & Bisk (2018) explore approaches to increase the robustness of character-based machine translation models on text corrupted with character-level noise.
With the help of expressive generative models, our approach instead perturbs the latent coding of sentences, resulting in legible generated sentences that are grammatical and semantically similar to the original input.
These merits make our framework suitable for text applications such as sentiment analysis, textual entailment, and machine translation.
D ISCUSSION AND F UTURE W ORK
Our framework builds upon GANs as the generative models, and thus the capabilities of GANs directly effects the quality of generated examples.
In visual domains, although there have been lots of appealing results produced by GANs, the training is well known to be brittle.
Many recent approaches address how to improve the training stability and the objective function of GANs (Salimans et al., 2016; Arjovsky et al., 2017).
Gulrajani et al.
(2017) further improve the training of WGAN with regularization of gradient penalty instead of weight clipping.
In our practice, we observe that we need to carefully balance the capacities of the generator, the critic, and the inverter that we introduced, to avoid situations such as model collapse.
For natural languages, because of the discrete nature and non-differentiability, applications related to text generation have been relatively less studied.
Zhao et al.
(2017) propose to incorporate a discrete structure autoencoder with continuous code space regularized by WGAN for text generation.
Given that there are some concerns about whether GANs actually learn the distribution (Arora & Zhang, 2017), it is worth noting that we can also incorporate other generative models such as Variational Auto-Encoders (VAEs) (Kingma & Welling, 2014) into our framework, as used in Hu et al.
(2017) to generate text with controllable attributes, which we will explore in the future.
We focus on GANs because adversarial training often results in higher quality images, while VAEs tend to produce blurrier ones (Goodfellow, 2016).
We also plan to apply the fusion and variant of VAEs and GANs such as α -GAN in Rosca et al.
(2017) and Wasserstein
Auto-Encoders in Tolstikhin et al.
Note that as more advanced GANs are introduced to address these issues, they can be directly incorporated into our framework.
Our iterative stochastic search algorithm for identifying adversaries is computationally expensive since it is based on naive sampling and local-search.
Search based on gradients such as FGSM are not applicable to our setup because of black-box classiﬁers and discrete domain applications.
We improve the efﬁciency with hybrid shrinking search by using a coarse-to-ﬁne strategy that ﬁnds the upper-bounds by using fewer samples, and then performs ﬁner search in the restricted range.
We observe around 4 × speedup with this search while achieving similar results as the iterative search.
The accuracy of our inverter mapping the input to its corresponding dense vector in latent space is also important for searching adversaries in the right neighborhood.
In our experiments, we ﬁnd that ﬁne-tuning the latent vector produced by the inverter with a ﬁxed GAN can further reﬁne the generated adversarial examples, and we will investigate other such extensions of the search in future.
There is an implicit assumption in this work that the generated samples are within the same class if the added perturbations are small enough, and the generated samples look as if they belong to different classes when the perturbations are large.
However, note that it is also the case for FGSM and other such approaches: when their (cid:15) is small, the noise is imperceptible; but with a large (cid:15) , one often ﬁnds noisy instances that might be in a different class (see Table 1, digit 8 for an example).
While we do observe this behavior in some cases, the corresponding classiﬁers require much more substantial changes to the input, which is why we can utilize our approach to evaluate black-box classiﬁers.
C ONCLUSIONS
In this paper, we propose a framework for generating natural adversaries against black-box classiﬁers, and apply the same approach to both visual and textual domains.
We obtain adversaries that are legible, grammatical, and meaningfully similar to the input.
We show that these natural adversaries can help in interpreting the decision behavior and evaluating the accuracy of black-box classiﬁers even in absence of labeled training data.
We use our approach, built upon recent work in GANs, to generate adversaries for a wide range of applications including image classiﬁcation, textual entailment and machine translation (via the Google Translate API).
Code used to generate such natural adversaries is available at https://github.com/zhengliz/natural-adversary .
A CKNOWLEDGMENTS
We would like to thank Ananya, Casey Graff, Eric Nalisnick, Pouya Pezeshkpour, Robert Logan and the anonymous reviewers for the discussions and feedback on earlier versions.
We would also like to thank Ishaan Gulrajani and Junbo Jake Zhao for making their code available.
This work is supported in part by Adobe Research and in part by FICO.
The views expressed are those of the authors and do not reﬂect the ofﬁcial policy or position of the funding agencies
A PPENDIX A I LLUSTRATION WITH S YNTHETIC D ATA
As shown in Figure 5 with a toy example of synthetic data, we can effectively map data instance x to its corresponding latent dense vector z (cid:48) with the help of the inverter via I γ ( x ) , and then reconstruct x with the help of the generator via G θ ( I γ ( x )) .
For a naive classiﬁer with the horizontal line as decision boundary, adversarial examples should be points above the line given input data x in Figure 5c.
By searching in corresponding latent space, our approach ﬁnds x ∗ on the left as a natural adversary because it is the closest one in semantic space (along the curve trace) and it exists within the data manifold.
However, the gradient-based approaches may ﬁnd the x ∗ right above x as adversarial in input space regardless of the actual data distribution.
B A LGORITHMS
Algorithm 1 shows the pseudocode of the iterative search of our framework.
Starting from the corresponding z of the input instance x , we iteratively move the search range outward in latent space until we have generated samples that change the prediction of the classiﬁer f .
We improve the efﬁciency with Algorithm 2 by using a coarse-to-ﬁne strategy and combining recursive and iterative search.
We ﬁrst search for adversaries in a wide search range, and recursively tighten the upper bound of the search range with denser sampling in bisections.
Extra iterative search steps are taken to further tighten the upper bound of the optimal ∆ z .
This hybrid shrinking search approach, shown in detail in
Algorithm 2, is four times faster to achieve similar adversaries as the iterative search.
C A RCHITECTURE FOR C ONTINUOUS I MAGES
Figure 3 shows the architecture of our framework for continuous images.
We adopt WGAN (Arjovsky et al., 2017) with the objective function in Equation 1, and apply gradient penalty as proposed in
Gulrajani et al.
On top of the generator obtained from WGAN, we train an inverter by optimizing Equation 2.
For handwritten digits from MNIST dataset, we train a WGAN of latent z ∈ IR 64 , with a generator consisting of 3 transposed convolutional layers and ReLU activation, and a critic consisting of 3 convolutional layers with ﬁlter sizes (64, 128, 256) and strides (2, 2, 2).
We include an inverter with 2 fully connected layers of dimensions (4096, 1024) on top of the critic’s last hidden layer.
For “Church Outdoor” and “Tower” images from LSUN dataset, we follow similar procedures as in Gulrajani et al.
(2017) training a WGAN of latent z ∈ IR 128 .
The generator and critic are both residual networks.
We use pre-activation residual blocks with two 3 × 3 convolutional layers each and ReLU activation.
The critic of 4 residual blocks performs downsampling using mean pooling after the second convolution, while the generator contains 4 residual blocks performing nearest-neighbor upsampling before the second convolution.
We include an inverter with 3 fully connected layers of dimensions (8192, 2048, 512) on top of the critic’s last hidden layer.
[Figure]
Require: a target black-box classiﬁer f , an input instance x , and a corpus of relevant data X 1: Hyper-parameters: N : number of samples in each iteration, ∆ r : increment of search range 2: Train a generator G θ and an inverter I γ on X 3:
y ← f ( x ) , z (cid:48) ← I γ ( x ) , radius r ←4: loop (cid:46) loop till we ﬁnd an adversary 5:
S ← ∅ 6: for sample N random noise vectors (cid:15) of norms within ( r, r + ∆ r ] do 7: ˜
z ← z (cid:48) + (cid:15) , ˜ x ← G θ (˜ z ) , ˜ y ← f (˜ x ) (cid:46) perturbation, sample generation, prediction 8: if ˜ y (cid:54) =
y then 9:
S ← S ∪ (cid:104) ˜
x, ˜ y,
˜ z
(cid:105) 10: if S = ∅ then (cid:46) no adversary generated 11: r ← r + ∆ r (cid:46) move search range outward 12: else (cid:46) certain adversary generated 13: return (cid:104) x ∗ , y ∗ , z ∗ (cid:105) =
argmin (cid:104) ˇ x, ˇ y, ˇ z (cid:105)∈ S (cid:107)
ˇ z − z (cid:48) (cid:107) (cid:46) return the closest sample
Require: a target black-box classiﬁer f , an input instance x , and a corpus of relevant data X 1: Hyper-parameters: N : number of samples in each iteration, ∆ r : increment of search range, B : limit of iterations, r : upper limit of search range 2: Train a generator G θ and an inverter I γ on X 3:
y ← f ( x ) , z (cid:48) ← I γ ( x ) , l ← 0 , i ←4:
First, recursive search: 5: while r − l ≥ ∆ r do 6:
S ← ∅ 7: for sample N random noise vectors (cid:15) of magnitude within ( l, r ] do 8: ˜
z ← z (cid:48) + (cid:15) , ˜ x ← G θ (˜ z ) , ˜ y ← f (˜ x ) 9: if ˜ y (cid:54) =
y then 10:
S ← S ∪ (cid:104) ˜
x, ˜ y,
˜ z
(cid:105) 11:
if S = ∅ then (cid:46) no adversary generated 12: l ← ( l + r ) /(cid:46)
shrink search range by half 13: else (cid:46) certain adversary generated 14: (cid:104) x ∗ , y ∗ , z ∗ (cid:105) =
argmin (cid:104) ˇ x, ˇ y, ˇ z (cid:105)∈ S (cid:107)
ˇ z − z (cid:48) (cid:107) (cid:46) store the closest sample 15: l ← 0 , r ← (cid:107) z ∗ − z (cid:48) (cid:107) (cid:46) update upper bound of ∆ z 16: Then, iterative search: 17: while i < B and r > 0 do 18:
S ← ∅ , l ← max(0 , r − ∆ r ) 19: for sample N random noise vectors (cid:15) of norms within ( l, r ] do 20: ˜
z ← z (cid:48) + (cid:15) , ˜ x ← G θ (˜ z ) , ˜ y ← f (˜ x ) 21: if ˜ y (cid:54) =
y then 22:
S ← S ∪ (cid:104) ˜
x, ˜ y,
˜ z
(cid:105) 23: if S = ∅ then 24: i ← i + 1 , r ← r − ∆ r (cid:46) increase counter, continue searching 25: else 26: (cid:104) x ∗ , y ∗ , z ∗ (cid:105)
= argmin (cid:104)
ˇ x, ˇ y, ˇ z (cid:105)∈ S (cid:107) ˇ z − z (cid:48) (cid:107) (cid:46) store the closest sample 27:
i ← 0 , r ← (cid:107) z ∗ − z (cid:48) (cid:107) (cid:46) reset counter, update upper bound of ∆ z 28: return (cid:104) x ∗ , y ∗ , z ∗ (cid:105)
D A RCHITECTURE FOR D ISCRETE T EXT
We use the adversarially regularized autoencoder (ARAE)
(Zhao et al., 2017) for encoding discrete text into continuous codes as shown in Figure 6.
ARAE model encodes a sentence with an LSTM encoder into continuous code and performs adversarial training on the codes generated from noise and data to approximate the data distribution.
We introduce an inverter that maps these continuous codes
[Figure]
into the Gaussian space of z ∈ IR 100 .
We use 4 layers of CNN with varying ﬁlter sizes (300, 500, 700, and 1000), strides (2, 2, 2) and context windows (5, 5, 3) for encoding text x , into continuous space c ∈ IR 300 .
For the decoder, we use a single-layer LSTM with hidden dimension of 300.
We also train two MLPs, one each for the generator and the inverter, to learn mappings from noise to continuous codes and continuous codes to noise respectively.
The loss functions for different components of the
ARAE model, which are autoencoder reconstruction loss and WGAN loss functions for generator and critic, are described in Equations (4), (5), (6) respectively.
We ﬁrst train the ARAE components of encoder, decoder and generator using WGAN strategy, followed by the inverter on top of these with loss function in (7), by minimizing the Jensen-Shannon divergence between the inverted continuous codes and noise samples.
[Equation] [Equation]
[Equation] [Equation]
We train our framework on the sentences up to length 10 from Stanford Natural Language Inference (SNLI) (Bowman et al., 2015) dataset, with hyper-parameters of ∆ r = 0.01 and N = 100.
Table 9 shows some examples of the perturbations generated automatically by our approach
[Table]
which are grammatical and semantically close to the original sentences.
D. T EXTUAL E NTAILMENT E XAMPLES
We provide additional examples of generated adversarial hypotheses for sentences from the SNLI corpus in Table 10, which corresponds to the examples in the main text in Table 3.
D. M ACHINE T RANSLATION E XAMPLES
We provide additional examples of the two probing functions in Table 11 and Table 12, corresponding to Table 4 and Table 5 in the main text, respectively.
[Table] [Table]
[Table] [Table]
Sie
[Table]