Symmetry-Preserving Paths in Integrated Gradients
Abstract.
We provide rigorous proofs that the Integrated Gradients (IG) attribution method for deep networks satisfies completeness and symmetry-preserving properties. We also study the uniqueness of IG as a path method preserving symmetry.
1. Introduction
1.1. Integrated Gradients
The Integrated Gradients (IG) attribution method for deep networks is introduced in [5]. A neural network can be interpreted as a function that maps its inputs to an output . As an example, assume that the input represents an image, and the are the intensities of its pixels. Assume we want to determine whether the image contains some element, say a dog, or a cat. There are deep networks that have been training with millions of images and can provide an answer by assigning a score (given by the value of ) to the presence or absence of the chosen element (see e.g. [4]). If the element is present in the image then the score is high, if not it is low. Each possible element has an associated score function, say , , etc. A problem that IG is designed to solve is to determine the contribution of each of its inputs to the output. In the example where the input is an image, and the network provides scores for the presence of an element (dog, cat,…), the inputs (pixels) that contribute most to the output are expected to be the ones in the area of the image where that element appears. This provides a way to locate that element within the image, e.g. where exactly the dog or the cat appears in the image.
IG was designed requiring it to satisfy a number of desirable properties, particularly sensitivity and implementation invariance. To define sensitivity we will need to establish a baseline input where the element or feature is absent (in image recognition a black image may serve the purpose). Then, the definitions of sensitivity and implementation invariance are as follows.
-
•
An attribution method satisfies Sensitivity if for every input and baseline that differ in one feature but have different predictions then the differing feature should be given a non-zero attribution.
-
•
An attribution method satisfies Implementation Invariance if the attributions are always identical for two functionally equivalent networks (two networks are functionally equivalent if their outputs are equal for all inputs).
The solution proposed in [5] is as follows. Given a baseline and an input , then the attribution assigned to the -th coordinate of the input is:
(1) |
where .
In the next section we will justify this formula, and discuss two additional properties of IG:
-
•
Completeness. The attributions add up to the difference between the output of at the input and the baseline .
-
•
Symmetry Preserving. Two input variables are symmetric w.r.t. a function if swapping them does not change the function. An attribution method is symmetry preserving, if for all inputs that have identical values for symmetric variables and baselines that have identical values for symmetric variables, the symmetric variables receive identical attributions.
1.2. IG Completeness and Symmetry Preserving
1.2.1. Completeness
The solution proposed by the authors can be understood as an application of the Gradient Theorem for line integrals. Under appropriate assumptions on function we have:
(2) |
where is a smooth (continuously differentiable) path, and is the nabla operator, i.e., . The attribution to the -th variable of the score increase with respect to baseline is the -th term of the final sum, i.e., .
Note that the result is highly dependent on the path chosen. The authors of IG claim that the best (in fact canonical) choice of path is a straight line from baseline to input, i.e., . With this choice we get , and equation (1) follows.
If (2) holds, then it is easy to see that IG also satisfies the completeness property:
This is Proposition 1 in their paper. However this result depends on the Gradient Theorem for line integrals, which requires the function to be continuously differentiable everywhere. This cannot be the case for deep networks, which involve functions such as ReLU and max pooling that are not everywhere differentiable. As a fix the authors restate the Gradient Theorem assuming only that is continuous everywhere and differentiable almost everywhere. However this cannot work, the particular case of the Gradient Theorem in 1-dimension is the (second) Fundamental Theorem of Calculus, which does not hold in general under those premises—Cantor’s staircase function provides a well known counterexample. There are also issues concerning allowable paths, e.g. for the function the partial derivatives and don’t even exist at the points of the line .
Our Proposition 1 in the next section states a version of the Gradient Theorem that can be applied to deep networks.
1.2.2. Symmetry Preserving
Theorem 1 of [5] states that IG, with paths that are a straight line from baseline to input, is the unique path method that is symmetry-preserving. However this theorem is not stated in the paper with full mathematical rigor, and the proof provided contains some inconsistencies.111Look for instance at the value of function in the region where and . Here we will present a completely rigorous formulation of a theorem that we believe captures the original authors’ intention, and provide its full proof.
2. Main Results
Here we state an appropriate generalization of the Gradient Theorem that can be applied to deep networks, and study the symmetry-preserving property of IG with straight-line paths.
First, we need to extend the class of functions to which we want to apply the theorem so that it includes functions implemented by common deep networks. We will do so by introducing Lipschitz continuous functions.
Definition 1.
A function is Lipschitz continuous if there is a constant such that for every , where represents Euclidean distance.
For univariate functions, continuity and almost everywhere differentiability is a necessary condition to make sense of the integral of a derivative. The following result ensures that such condition is satisfied for multivariate Lipschitz continuous functions.
Rademacher’s theorem.
If is an open subset of and is Lipschitz continuous, then f is differentiable almost everywhere in .
Rademacher’s theorem ensures that the function in our proposition 1, that we state next, is differentiable almost everywhere. However that does not mean that such function is differentiable almost everywhere on a given path—e.g. the function is everywhere continuous, and almost everywhere differentiable on , but is not differentiable at any point of the line . So differentiability on the path needs to be included as an additional premise.
Proposition 1 (Gradient Theorem for Lipschitz Continuous Functions).
Let be an open subset of . If is Lipschitz continuous, and is a smooth path such that is differentiable at for almost every , then
Proof.
The path is continuously differentiable on a compact set (the interval ), hence it is Lipschitz continuous (because its derivative is continuous and so bounded on ). The composition of two Lipschitz continuous functions is Lipschitz continuous, hence is Lipschitz continuous, which implies absolutely continuous. By the Fundamental Theorem of Calculus for absolutely continuous functions222See [3] sec. 33.2, theorem 6. we have
By the multivariate chain rule we have
wherever is differentiable (for almost every by hypothesis). Hence
and the result follows.
∎
Next, we will look at results intended to capture the symmetry-preserving properties of IG.
Definition 2.
A multivariate function with variables is symmetric in variables and , , if .
Definition 3.
The smooth path is said to be IG-symmetry preserving for variables and if and implies for every function verifying the hypotheses of proposition 1 that is symmetric in its variables and .
Definition 4.
A path is monotonic if for each we have or , where represents the -th coordinate of .333In other words, each is either increasing, or decreasing. Note that could be increasing in some coordinates and decreasing in other The path is strictly monotonic if the inequalities hold replacing them with strict inequalities, i.e., or .
Next theorem is intended to capture the symmetry-preserving properties of IG. The proof follows closely the one given in [5].
Theorem 1.
Given , , real numbers , and a strictly monotonic smooth path such that and , then the following statements are equivalent:
-
(1)
For every , .
-
(2)
For every function symmetric in and and verifying the premises of proposition 1 with we have (i.e., is IG-symmetry preserving for variables and ).
Proof.
Proof of (1) (2). Since for every , and is symmetric with respect to variables and , we have for almost every . Hence they have the same integral.
Proof of (2) (1). Without loss of generality we will assume that and are increasing, so that . Next, assume that (1) is not true. Then, for some we have . Assume wlog . Let be the maximum interval containing such that for every . Since is maximum, and , are increasing, then for , and for .
Define as follows:
and . Then is symmetric in and , and verifies the premises of proposition 1. For we have that is constant, hence . For we have
By hypothesis , hence , which is a contradiction.
This completes the proof. ∎
Corollary 1.
Let and be two points in the open set , such that and . Then, the (straight line) path is IG-symmetry preserving for variables , for every function that is symmetric in and and verifies the hypotheses of proposition 1. Furthermore, if and , and is IG-symmetric preserving for (each pair of) variables in the sense of definition 3, then is a straight line in .
Next, we will look at a simple example illustrating the result stated in theorem 1.
Example 1.
Figure (1) illustrates the failure to preserve symmetry when the path is not a straight line between baseline and input. The function used is , which is symmetric, and the path is a curve joining and . The attributions from IG are

We have area under the path , and area above the path. Their sum is , the whole area of the square with vertices and , which equals , and the Gradient Theorem holds. However . If we used instead the straight line path joining and , then the IG attributions would be equal.
Note that the uniqueness of IG (using straight line paths) is not fully captured by our results, and in general does not hold (under the definition of “symmetry-preserving” as worded in the IG paper, which we tried to formally capture in definition 3). All we can tell is that if and then for every , but if the premises fail (i.e., or ) then nothing forces the path to be a straight line. To illustrate this point we give next a counterexample showing a way to select paths that are not straight lines in general, and still verify the definition of IG-symmetry preserving.
Counterexample 1.
Consider the following path between points and in :
We multiply the last term of each expression by the sign function444The sign function is defined if , and . to make sure that the paths are monotonic (this shows that requiring the paths to be monotonic does not affect the result.) Also note that the assignment of path , where is defined as above, is symmetric in the sense that swapping the indexes and in the expression produces another expression that is equivalent to the original, so the assignment of path is symmetric with respect to the coordinates and . Also, we have that if and then , which, according to theorem 1, is IG-symmetry preserving for variables , for every function that is symmetric in and and verifies the hypotheses of proposition 1. However, if or , the quadratic terms in make a curve that is not a straight line in general, and hence it differs from the path used in the IG attribution method. The symmetry preserving property is not violated because in the cases where the path is not a straight line the premises of the definition don’t apply, so theorem 1 still holds.
Admittedly this counterexample is an artificial modification of a straight-line. IG (with straight line paths) is a simple path-based symmetry-preserving attribution method, and we see no reason to replace it with a different method using non straight-line paths without justification.
3. Conclusions
We have rigorously stated and proved that Integrated Gradients has completeness and symmetry preserving properties. The premises used to prove the result makes it suitable for functions implemented by common deep networks.
On the other hand we have shown that IG with straight line paths is not the unique path method that is symmetry-preserving, in fact there are path methods that verify the definition of symmetry-preserving but don’t necessarily use straight line paths for all combinations of baseline and input. Note that this should not be taken as an argument against using straight line paths in IG, in fact straight lines are still the simplest paths that provide the desired results.
References
- [1] Federer, Herbert (1969). Geometric measure theory, Die Grundlehren der mathematischen Wissenschaften, 153, Berlin–Heidelberg–New York: Springer-Verlag, pp. xiv+676, ISBN 978-3-540-60656-7, MR 0257325, Zbl 0176.00801.
- [2] Heinonen, Juha (2004). Lectures on Lipschitz Analysis. URL: http://www.math.jyu.fi/research/reports/rep100.pdf
- [3] A. N. Kolmogorov, S. V. Fomin (1970). Introductory Real Analysis. Dover Books on Mathematics.
- [4] Karen Simonyan, Andrew Zisserman (2015). Very Deep Convolutional Networks for Large-Scale Image Recognition. arXiv preprint arXiv:1409.1556 [cs.CV]
- [5] Mukund Sundararajan, Ankur Taly, and Qiqi Yan (2017). Axiomatic attribution for deep networks. arXiv preprint arXiv:1703.01365 [cs.LG]