Model Reconstruction from Model Explanations
Smitha Milli, Ludwig Schmidt, Anca D. Dragan, Moritz Hardt
Introduction
Commercial machine learning models increasingly support consequential decisions in numerous domains including medical diagnosis, employment, and criminal justice. In such applications, there is now growing demand for methods that explain a model’s decision. The secrecy of a model strongly fuels this demand.
At the same time, there are a number of valid reasons a company might wish to keep its machine learning models secret. The competitive value of the product is one consideration. Revealed models may also be easier to game, resulting in diminished predictive power . Yet another reason is that the model might leak sensitive information about the data it was trained on .
In this work, we point out a tension between keeping a model secret and explaining its decisions. We show that a popular class of existing methods to explain a model’s decision quickly reveals the model itself in what is typically an undesired side effect.
Numerous explanation methods have been proposed in an ongoing line of research. Among these methods, saliency maps are a widespread technique to highlight characteristics of an input deemed relevant for the prediction of a model. The most basic saliency map is to compute the gradient of the model with respect to a chosen input and numerous variants add different transformations to the raw gradients leading to some disagreement over which of these heuristics is preferable in what context . Abstracting away from these implementation details, we focus on reconstructing models given the basic underlying primitive, which is gradients of the model with respect to its inputs.
Our contributions are twofold, spanning both a theoretical and experimental component.
Learning from input gradients. On the theoretical side, we introduce a model of learning from input gradient queries. In this model, a learning algorithm can observe gradients of an unknown model at chosen query inputs. This model turns out to be rich in its mathematical structure and connections to standard learning models, such as learning from membership queries, in which the learner can request the model’s prediction at a given input.
Assuming the rows of the weight matrix are linearly independent, our algorithm recovers a functionally equivalent model from input gradient queries and function evaluations with high probability.
The queries our theorem requires is optimal to within a logarithmic factor, since it takes parameters to specify the model, and each query reveals only numbers. Furthermore, compared to membership queries, gradient queries reduce the number of queries needed by approximately a factor of , since it takes membership queries to specify the model.
Although our algorithm enjoys an intuitive geometric interpretation, the proof requires a delicate argument, as well as an anti-concentration bound that may be useful independently.
Practical reconstruction methods. In a second step, we explore practically effective heuristics to reconstruct a model from input gradient queries. Our experiments show that reconstructing models from explanations is not just a theoretical concern. If a company were to provide an explanation API with standard saliency maps, it would effectively give up the underlying model, which it may not be willing to do for reasons mentioned above. This situation parallels an ongoing investigation on stealing models from prediction APIs . However, as our results show, with explanation APIs we need far fewer queries, thus greatly exacerbating the threat of model leakage.
Our experiments focus on a heuristic for learning from input query gradients. While our theoretical method is specific to two-layer networks, our heuristic is agnostic to the shape of the target model. At the outset, our heuristic simply queries a number of input gradients and fits a model against the observed gradients in much the same way we would fit a model against labels. We find that this heuristic reduces the number of queries needed to learn models on MNIST and CIFAR10 by orders of magnitude, even in cases where the model class is unknown or the data distribution is unknown.
Conclusion. Our work demonstrates that establishing usable explanation methods for machine learning models faces another hurdle in commercial applications. Whatever criteria of explanation quality we choose must be weighed against the risk of model leakage resulting from the method at hand. We see our work as only a first step in this new direction that raises many intriguing questions.
Problem statement: reconstructing a two-layer ReLU network
We consider the problem of finding a classifier identical to an unknown classifier when given access to membership and gradient queries. That is, we assume access to an oracle that given a query input returns the evaluation of at and the gradient of with respect to
The rows are unit vectors.
No two rows and with are collinear, i.e., for some .
The rows are linearly independent.
The first two assumptions are without loss of generality, as they follow from simple reparameterizations of the network that involve scaling or or reducing the hidden dimension.
Our main result is the following theorem, which shows that our sample complexity for learning the function with gradient queries has no dependence on the input dimension .
Suppose, the unknown function satisfies our assumptions. Then, with probability , Algorithm 1 succeeds to find a function such that in queries. If the Algorithm fails, then it notifies of the failure.
Section 3 contains our algorithm and proof of correctness. In Appendix C we show that our algorithm can also be converted to one which learns the function in membership queries by using membership queries to approximate gradients of .
Algorithm
Before we formally introduce our algorithm, we briefly provide some high-level intuition. First, note that we can express our two-layer ReLU networks as
Our algorithm can be separated into two steps. First, we find the separating hyperplanes of . In particular, we recover unsigned, weighted normal vectors or for . The second step then recovers the sign information for these normal vectors. More precisely, the two steps are the following:
Recover a vector such that . (Algorithm 3)
Together, the matrix and vector identify the function . We analyze the first step in Section 3.1 and the second step in Section 3.2.
Algorithm 2 finds the separating hyperplanes by exploiting the structure of the gradient of :
In this way, Algorithm 2 isolates changes in the gradient of to recover up to a sign for every . Figure 1 provides an illustrated explanation of the algorithm, which we briefly sketch below:
Repeat Step (2) times to recover all rows up to their sign, which become the rows of the matrix .
The proof of correctness relies on showing that with high probability, the following two events hold: (i) The points at which the gradient of changes are spaced sufficiently far apart. (ii) The same gradient change points are within some line segment of and that is not too big. The change points can then be found with a binary search that is bounded within a range that is not too large and uses step sizes that are not too small. In the next lemma, we prove correctness of the binary search given that the change points are spaced appropriately.
Let be the indices such that . To prove the lemma we will show that on the -th call to binarySearch, either or is added as a row to matrix .
First, we make the following assumption, which we will later prove: assume that where is the value of the variable at the start of the -th call to binarySearch. Given this assumption, the -th call to binarySearch adds or to the matrix . To see this, note that on each iteration of the while loop in binarySearch either the variable increases or the variable decreases, and thus binarySearch always terminates. However, dose not increase past and does not decrease past . So, when the condition for termination of the while loop is met we have , , and . Since for all , the row returned by binarySearch is equal to either or .
Now we revisit the assumption that . We prove the assumption by induction. The base case is clearly true: because and . On the -th call to binarySearch the variable is set to the value of when the -th call to binarySearch terminated. When the -th call to binarySearch finishes, the value of the variable is above , but less than . Thus, .
Therefore, the returned matrix is such that or where the permutation of is defined by where . ∎
The next two lemmas (proved in Appendix A) establish the necessary anti-concentration and concentration bounds for showing that the change points are spaced sufficiently far apart (Lemma 2), but still within some line segment of and that is not too big (Lemma 3).
Finally, the proof of our main theorem for Algorithm 2 follows by combining the probabilistic guarantees of Lemmas 2 and 3 with the deterministic proof of correctness in Lemma 1.
By Lemma 1, if and for all and , then Algorithm 2 succeeds. The probability of this event can be lower-bounded as the following.
Let . Set . Then, solving for yields . So, Algorithm 2 succeeds with probability and uses less than queries, which is upper bounded as the following.
2 Step two: recovering the signs of the normal vectors
Algorithm 2 recovers unsigned, weighted normal vectors: or for . But to identify the function , we still need the sign of these vectors. In Algorithm 3, we recover a vector that encodes this sign information. Precisely, Algorithm 3 returns a vector such that
It is clear that if Algorithm 3 returns the vector , then the function is identified. Algorithm 3 solves linear equations to determine the vector . To prove correctness of Algorithm 3, we show that the query points picked in the algorithm lead to a determined set of linear equations.
The determinant of the matrix is . Thus, is a full-rank matrix. ∎
In Appendix B we describe a simple linear program that can be used to pick a matrix that satisfies the conditions of the above Lemma 4. Since Algorithm 3 picks such a matrix , Lemma 4 immediately implies our main theorem proving correctness of Algorithm 3.
Together, Theorem 2 proving correctness of Algorithm 2 and Theorem 3 proving correctness of 3 imply our main Theorem 1 that proves correctness of Algorithm 1.
Suppose the unknown function satisfies the assumptions in Section 2. Then, with probability , Algorithm 1 succeeds to find a function such that in queries. If the Algorithm fails, then it notifies of the failure.
By Theorem 2, with probability , Algorithm 2 returns a matrix that satisfies the conditions of Theorem 3 in queries. By Theorem 3, Algorithm 3 then returns a vector such that in queries. Thus, overall Algorithm 1 succeeds with probability in queries. ∎
Experimental design
While our theoretical analysis provides insight into the power of gradient queries over membership queries, it is specific to a two-layer ReLU network. To complement our theory, we also experimentally investigate the impact of gradients on reconstructing models used in practice.
Manipulated factors. We manipulate three independent variables. First, we manipulate the type of query. We test membership only queries as well as membership and gradients. Further, because in practice explanations often provide a processed version of the gradients, instead of the raw gradients, we also test membership and gradients processed with SmoothGrad, a saliency map denoising technique . Instead of returning the raw gradient , SmoothGrad returns an average of gradients around the input : where .
Second, we manipulate the complexity of the task to test whether gradients help more or less on more complex tasks. We experiment on both MNIST and CIFAR10. Finally, we manipulate the complexity of the model class to test whether gradients help more when the model is simpler. We train three models on each of the two tasks that are chosen to display a range of complexity.
Dependent measure. We measure the accuracy of our reconstructed classifier on a test set of 10,000 images from the task (MNIST or CIFAR10).
Experimental procedure. We split our datasets into three parts:
A training set of images and ground-truth labels for the true classifier . The training set for MNIST has 50,000 examples and for CIFAR10 has 40,000 examples.
A training set of 10,000 images for the reconstructed classifier . Note that does not have access to ground-truth labels, so it must query for labels.
A test set of 10,000 images and ground-truth labels for and .
We first train models to serve as the true classifier . We train three types of models on MNIST: a 1-layer network (multinomial logistic regression), a 2-layer neural network with ReLu activations, and a network with two convolutional layers (each followed by a max-pool layer) followed by two dense layers. We also train three types of models on CIFAR10: the same convolutional network used for MNIST (with the input dimension changed appropriately), a VGG11 network , and a ResNet-18 network .
Next, we train a new classifier from the same model class as the true classifier . The inputs given to are randomly sampled from the training set for . After training, we compute the accuracy of our reconstructed classifier on the test set.
Follow-up experiments: unknown model class and data distribution An adversary trying to reconstruct the classifier may not know the model class of or the data distribution. So, in follow-up experiments we (1) reconstruct the classifier with a classifier from a different model class and (2) reconstruct the classifier using Gaussian generated queries. In these follow-up experiments we analyze the same factors, but with a subset of conditions.
Experimental results and discussion
Figure 2 shows the results of our main experiments, described in Section 4.
Type of query. Across all experiments, training with gradient queries leads to orders of magnitude fewer queries required to learn the model. For example, for the MNIST convolutional model we get to 95% accuracy in 10 gradient queries, compared to 1000 membership queries. We find practically no difference between gradient queries and SmoothGrad queries, despite picking the hyperparameters for SmoothGrad that produced the best saliency maps (See Appendix D).
Complexity of model class. We find that the gap in performance between gradient queries and membership queries is larger for models of lower complexity.
On MNIST with the 2-layer or convolutional network we find a 100x decrease in the number of queries needed to reconstruct the model. On CIFAR10 we find that the convolutional network (which is the same as the convolutional network used for MNIST) also has at least a 100x decrease in the number of queries needed. On the other hand, VGG11 and Resnet-18 show only a 10x decrease in the number of queries needed to reach 75% accuracy.
Complexity of task. We find that the relative reduction in queries needed seems to depend on the complexity of the model class, rather than the complexity of the task. But, not surprisingly, the absolute number of queries needed increases with the complexity of the task.
On both MNIST and CIFAR10 gradient queries lead to a 100x decrease for reconstructing the convolutional network, suggesting that for the relative decrease in query complexity depends more on the complexity of the model class than the complexity of the task. However, as might be expected, for both gradient and membership queries the absolute number of queries needed increases as the complexity of the task increases. On MNIST the convolutional model is reconstructed in 10 gradient queries, compared to 1000 membership queries. On CIFAR10 the convolutional model is reconstructed in 100 gradient queries, compared to 10,000 membership queries.
2 Unknown model class
In the scenario where we do not know the true model class beforehand, we experiment with:
MNIST: Reconstructing the 1-layer model with the 2-layer network (and vice versa).
MNIST: Reconstructing the 2-layer model with the convolutional network (and vice versa).
CIFAR10: Reconstructing the VGG11 model with the ResNet-18 network (and vice versa).
We refer the reader to Section 4 for details on the models. Figure 3 displays our results.
We find that gradient queries seem to help more when the the model class of is more complex than the true classifier . For example, we see a 100x decrease in the number of queries needed to reconstruct MNIST 1-layer with a 2-layer network. But, we only get an initial 10x decrease in the number of queries needed to reconstruct MNIST 2-layer with a 1-layer network. Similarly reconstructing the 2-layer network with the convolutional network works much better than reconstructing the convolutional network with the 2-layer network.
We have been fairly loose when referring to the relative complexities of different models, and it is unclear to us how to compare VGG11 and ResNet-18 in terms of complexity. Interestingly however, we find that although gradient queries still lead to a 10x decrease when reconstructing ResNet-18 with VGG11, they help very little when reconstructing a VGG11 model with a ResNet-18 network.
3 Unknown data distribution
We now analyze the setting where we do not know the data distribution. Instead we query using randomly generated Gaussian queries, i.e . Figure 4 displays our results.
On MNIST we find that Gaussian queries lead to a greater gap in performance between gradient and membership queries, compared to when using images from the data distribution.On the 1-layer network we see the same relative decrease because it is identifiable with a single gradient + membership query or 784 membership queries, independent of the distribution the queries are generated from. On the MNIST 2-layer network, we see at least a 1000x decrease, compared to the 100x decrease we saw in Section 4 when using queries from the data distribution. On the MNIST convolutional network, we see that in 10 gradient queries we get to 84% accuracy. On the other hand, it takes 10,000 membership queries to learn at all, and even then we get to only 71%. Thus, we seem to get at least a 1000x decrease, compared to the 100x reduction we saw when using queries from the data distribution.
On CIFAR10 it is harder to interpret the results because the performance degrades so much for both gradient and membership queries. However, at least in the convolutional network, the gap between gradient and membership queries also seems to increase. The reconstructed model gets to 50% accuracy in 10 gradient queries, but only to 11% accuracy in 10,000 membership queries.
Related work
Tramèr et al. show how models can be reconstructed in practice through prediction APIs . Our work addresses the complementary threat of model leakage through a hypothetical explanation API. While differential privacy can help guard against attacks from prediction APIs , it is not clear if this is a viable approach for preventing reconstruction from explanations.
Learning a model via a prediction API instantiates the framework of learning with membership queries, in which the learner gets to actively query an oracle for labels to inputs of its choosing . In our work, we propose a complementary learning framework: learning from input gradient queries. Similar to membership queries and prediction APIs, we believe that learning from gradients is likely to be the theoretical framework underpinning reconstruction from explanation APIs.
We give a near-optimal algorithm for learning a two-layer network with ReLU activations through gradient queries. The geometric intuition for our algorithm is similar to the work of Baum for learning two-layer linear threshold networks with membership queries .
References
Appendix A Omitted proofs for Algorithm 2
First, we prove the following two lemmas that will be useful in proving the anti-concentration and concentration bounds in Lemma 2 and Lemma 3.
(Anti-concentration of difference of variables) Let . Then, for .
Recall that the cumulative distribution function of a random variable is
where is the lower incomplete gamma function and is the gamma function. When , simplifies to . Thus,
(Distribution of product of independent Gaussians) Let . Then can be written as
where are independent.
Since , we know and are independent random variables from a distribution. Thus, we can express and as and where are independent random variables. Thus, . ∎
Solving for the scalars and yields
Using this expression for the vector we can rewrite as
where are independent random variables. To bound we can bound the numerator and denominator of (A) separately. For all , the following inequality holds.
Applying a union bound to the complementary event yields,
Applying Lemma 6 to the independent products and simplifies the numerator to
where are independent Chi-squared random variables. Then by Lemma 5,
To upper bound the tail probability of the denominator (the second term in Equation 5) note that
Minimizing the right-hand side with respect to yields
follows a standard Cauchy distribution. The cumulative distribution function of a standard Cauchy random variable is . Thus,
Appendix B Picking query points in Algorithm 3
For completeness, we show that we can easily find a matrix which satisfy the requirements of Lemma 4 through the following steps:
Construct a set of linearly independent vectors as follows.
Appendix C Reconstruction from membership queries
We now consider how to reconstruct the two-layer ReLU neural network described in Section 2 with membership queries alone, rather than membership and gradient queries. We show that we can convert our algorithm into one that learns with membership queries by estimating the gradients of with membership queries.
We define the membership query version of Algorithm 1, referred to as Algorithm 1-MQ, by replacing any use of the gradient with an estimate of the gradient, , computed with membership queries. We estimate the gradient by estimating each component separately through a finite difference approximation:
Our main result shows that we can recover the function in membership queries:
C.2 Proofs
The proof of Theorem 4 relies on showing that we can pick an small enough so that with high probability all estimates of the gradient are equal to the exact gradient. We show this by proving that if all points used in estimating a gradient lie in the same cell defined by the separating hyperplanes of , then the estimate of the gradient is equal to the gradient . If is small enough, then all points evaluated for a gradient estimate will lie in the same cell, and thus the exact gradient will be recovered. By choosing small enough, we can ensure that all gradients estimated by Algorithm 1-MQ are equal to the exact gradient with high probability.
First, we show that if all points sampled in estimating the gradient lie in the same cell, then the estimate of the gradient is equal to the gradient :
Suppose for all , lies in the same cell as , i.e,
Then, .
Recall that the function can be expressed as
Thus, the -th component of the gradient of is
where is the -th column of . Our estimate of the gradient is
Therefore, . ∎
The next lemma shows that if is small enough, then all points evaluated used to estimate a gradient lie in the same cell, and thus the exact gradient is recovered.
Next, given a particular value of , we bound the probability that all gradients we estimate with our algorithm are exactly equal to the true gradient.
First we will establish a bound for one row of the weight matrix .
A union bound on all rows of the weight matrix then shows that
Finally, we show that by picking small enough so that all gradients estimate are exact with high probability, the sample complexity of Algorithm 1-MQ becomes membership queries.
Algorithm 1 only uses gradients of in Algorithm 2 and Algorithm 1 succeeds if and only if Algorithm 2 succeeds. Thus, we can bound the success of Algorithm 1-MQ by bounding the probability that all gradients used in Algorithm 2 are estimated exactly.
In gradient queries we can guarantee that Algorithm 2 succeeds with probability . The probability Algorithm 1-MQ succeeds then becomes the following.
Since, it takes membership queries to compute each gradient that Algorithm 2 requires, the sample complexity becomes membership queries.
Appendix D SmoothGrad
Instead of returning the raw gradient , SmoothGrad returns an average of gradients around the input :
where and . SmoothGrad has two hyperparameters: (1) the standard deviation of the Gaussian noise and (2) the number of samples to pick.
As shown in Figure 5, we found that the best value of for MNIST was 1000 times , the standard deviation of the images in the dataset. On CIFAR10 using either the VGG-11 or ResNet-18 network, no value of seems to produce a sharp map (Figures 6 and 7). So for our CIFAR10 experiments, we set equal to the standard deviation of the dataset . In the original SmoothGrad paper, Smilkov et al. find that the best value of for MNIST is about 70% the spread of the dataset, while on ImageNet it is only 10-20%. So the difference between the value of we use on MNIST and the value of we use on CIFAR10 seems to qualitatively match the difference in the value of Smilkov et al. use on MNIST and ImageNet.
We expect that SmoothGrad may eventually degrade the performance of the reconstructed model as increases. But at least for the values of we test, which are already quite large relative to the standard deviation of the dataset, and seem to match values that may be used in practice, we see no degradation in performance when using gradients preprocessed by SmoothGrad.
Regarding the number of samples, , Smilkov et al. state that the estimated gradient becomes smoother as increases, but that they find diminishing returns for . For computational reasons we set in our experiments, however, this should only make it harder to learn, since the outputs of SmoothGrad become noisier.