Search

Search papers and lessons

Axiomatic Attribution for Deep Networks

Mukund Sundararajan, Ankur Taly, Qiqi Yan · 2017

Sundararajan, Taly and Yan (2017) set two axioms every attribution method should meet, showed most methods fail one, and built Integrated Gradients, which meets both.

On this page

  • Colour = topic mix
  • Calculus
  • Discrete math
  • Neural network basics
  • Linear algebra
  • Probability
  • Safety & alignment
  • ReadReady to readNot yet

TL;DR

A deep network turns an input, such as a photo or a sentence, into a score. Attribution asks which input features made that score go up or down, and by how much. Sundararajan, Taly and Yan (2017) argue that any attribution method should satisfy two axioms, Sensitivity and Implementation Invariance. They show that most earlier methods break at least one of them. They then design Integrated Gradients, which satisfies both, needs no change to the network, and needs only a few calls to the ordinary gradient.

Builds on: Gradient, Rectified Linear Unit (ReLU) · Leads to: Integrated Gradients

Why it mattered

Before this paper, most attribution methods were judged by eye, or by removing pixels or words and watching the score drop. The authors show why that is not enough. A drop can come from the perturbed input itself, a misbehaving model, or a misbehaving attribution method. The authors found that every empirical test they tried could not tell these apart. The paper's answer is to reason from axioms: write down properties any sensible method must have, then check which methods have them.

The method that came out of this, Integrated Gradients, now has its own lesson. This paper is where its justification lives. The applications in the paper are concrete: pixel attributions for GoogleNet trained on ImageNet, a diabetic retinopathy network, a question classifier over semi-structured tables, Google's LSTM-based neural machine translation system, and a molecular graph model for predicting activity against a target. Each one shows the method pointing at something a human can check.

The problem

The paper defines the task first. Take a function F:Rn→[0,1]F:\mathsf{R}^{n}\rightarrow[0,1] that represents the network, an input xx with nn features, and a baseline input x′x'. An attribution is a vector (a1,…,an)(a_1, \ldots, a_n) where aia_i is the contribution of feature xix_i to the prediction F(x)F(x), measured relative to the baseline.

The baseline matters. A person saying "the cause of this is A" implicitly compares with a world where A is absent. For an image network the absence of objects is the black image, so the black image serves as baseline.

The obvious first attempt is the gradient. For a linear model, practitioners multiply each coefficient by the feature value to see its effect. The gradient of the output with respect to the input is the closest analog for a deep network. The paper shows that this fails. Take f(x)=1−ReLU(1−x)f(x) = 1 - \mathsf{ReLU}(1-x), baseline x′=0x' = 0, input x=2x = 2. The output goes from f(0)=0f(0) = 0 to f(2)=1f(2) = 1, a change of 1. But for x>1x \gt 1 the ReLU term is zero, so the function is flat at x=2x = 2 and the gradient there is 0. A gradient-based attribution gives xx the score 0, even though the output changed. The paper calls this a failure of Sensitivity: if the input and baseline differ in one feature and the prediction differs, that feature must get a nonzero attribution.

Other methods fix the flat-region problem by using large discrete steps instead of gradients, but then they break the second axiom. Implementation Invariance says that two networks with identical outputs for every input must get identical attributions, because attribution should depend on what the network computes, not on how it is built. The chain rule holds for gradients, but it does not hold for discrete steps in general. So methods that chain discrete steps backward through the layers can give different answers for two networks that compute the same function. The paper gives a concrete pair of such networks in its appendix.

The paper traces the earlier methods it discusses: gradient methods from Baehrens and colleagues (2010) and Simonyan and colleagues (2013); backward-pass methods such as deconvolutional networks and guided backpropagation (Zeiler and Fergus, 2014; Springenberg and colleagues, 2014); and DeepLift (Shrikumar and colleagues, 2016) and layer-wise relevance propagation (Binder and colleagues, 2016). The authors' axiomatic test is borrowed from cost sharing in economics. Integrated gradients is the Aumann-Shapley cost-sharing rule (Aumann and Shapley, 1974), and Friedman (2004) is cited for the uniqueness result in the next sections.

How it works

The method is built so that both axioms hold by design. The walkthrough runs in pipeline order.

  1. Choose an input and a baseline. The input xx is the thing being explained. The baseline x′x' is a neutral input with near-zero score. For images it is the black image. For text it is the all-zero embedding vector.
  2. Draw a straight path from baseline to input. The points are γ(α)=x′+α(x−x′)\gamma(\alpha) = x' + \alpha(x - x') for α\alpha from 0 to 1. Check: γ(0)=x′\gamma(0) = x' and γ(1)=x\gamma(1) = x.
  3. Compute the gradient at many points on the path. At each point the gradient says how fast the output changes in each feature.
  4. Add up those gradients, weighted by the tiny step between points. This is an integral along the path. In practice it is a sum over 20 to 300 points, which the paper reports is enough to get within 5 percent of the total.
  5. Multiply by how far each feature moved. Feature ii moved by xi−xi′x_i - x'_i. Its attribution is that distance times the averaged gradient.
  6. Check completeness. The attributions should add up to F(x)−F(x′)F(x) - F(x'), the change in output. This is a built-in accounting check. If the sum is far off, use more points.
00.511.522.5300.51input xoutput f(x)
  • f(x) = 1 - ReLU(1 - x)
The output rises with slope 1 until x = 1, then goes flat. Points at the baseline 0, the kink at 1, and the input 2.
flowchart LR
  A[input] --> C[straight path from baseline to input]
  B[baseline] --> C
  C --> D[gradients at many points on the path]
  D --> E[weighted sum over the path]
  E --> F[one attribution per feature, summing to the output change]

Traced instance: a flat region at the input

Use f(x)=1−ReLU(1−x)f(x) = 1 - \mathsf{ReLU}(1-x), baseline 00, input 22. The path is γ(α)=2α\gamma(\alpha) = 2\alpha. Along it, the gradient is 1 while 2α<12\alpha \lt 1, that is for α<0.5\alpha \lt 0.5, and 0 after that. Averaging the gradient over the path gives 0.5. Multiply by the distance 2 and get 1. The output change was f(2)−f(0)=1f(2) - f(0) = 1, so the attribution adds up exactly. The plain gradient at the input was 0, but the path went through the region where the function still rises, so the change is recovered.

Traced instance: the minimum of two inputs

The paper's example is f(x1,x2)=min⁡(x1,x2)f(x_1, x_2) = \min(x_1, x_2), baseline (0,0)(0, 0), input (1,3)(1, 3). The output change is min⁡(1,3)−min⁡(0,0)=1\min(1, 3) - \min(0, 0) = 1. The path is γ(α)=(α,3α)\gamma(\alpha) = (\alpha, 3\alpha). For α>0\alpha \gt 0, α<3α\alpha \lt 3\alpha, so the minimum is x1x_1 and the gradient on the path is (1,0)(1, 0). Then IG1=(1−0)×∫011 dα=1\text{IG}_1 = (1 - 0) \times \int_0^1 1\, d\alpha = 1 and IG2=(3−0)×∫010 dα=0\text{IG}_2 = (3 - 0) \times \int_0^1 0\, d\alpha = 0. The two add to 1, the change, so integrated gradients gives all the credit to x1x_1. Averaging the Shapley-Shubik orderings instead gives each input 12\tfrac{1}{2}, which is also complete. The paper says it is subjective which split to prefer.

The math

Definition: Integrated gradients

For a network FF, input xx and baseline x′x', the attribution to feature ii is

IGi(x)=(xi−xi′)∫α=01∂F(x′+α(x−x′))∂xi dα\text{IG}_i(x) = (x_i - x'_i) \int_{\alpha=0}^{1} \frac{\partial F(x' + \alpha (x - x'))}{\partial x_i}\, d\alpha

Here ∂F/∂xi\partial F / \partial x_i is the partial derivative of the output with respect to feature ii, and the integral runs over the straight path that α\alpha traces.

Step 2 in symbols

The path is γ(α)=x′+α(x−x′)\gamma(\alpha) = x' + \alpha(x - x'). It starts at the baseline, γ(0)=x′\gamma(0) = x', and ends at the input, γ(1)=x\gamma(1) = x. Every point in between is a blend of the two, with weight α\alpha on the input.

Step 4 in symbols

The integral is approximated by a Riemann sum with mm steps:

IGiapprox(x)=(xi−xi′)∑k=1m∂F(x′+km(x−x′))∂xi⋅1m\text{IG}_i^{\text{approx}}(x) = (x_i - x'_i) \sum_{k=1}^{m} \frac{\partial F\big(x' + \tfrac{k}{m}(x - x')\big)}{\partial x_i} \cdot \frac{1}{m}

A Riemann sum replaces the area under a curve by a stack of thin rectangles. Each term here is one rectangle, with height the gradient at one point and width 1/m1/m.

Step 6 in symbols: completeness

The paper's Proposition 1 says the attributions sum to the output change. Here is why. Let g(α)=F(γ(α))g(\alpha) = F(\gamma(\alpha)), the output along the path. By the chain rule, g′(α)=∑i∂F∂xi(γ(α))⋅(xi−xi′)g'(\alpha) = \sum_i \frac{\partial F}{\partial x_i}(\gamma(\alpha)) \cdot (x_i - x'_i), since γi′(α)=xi−xi′\gamma_i'(\alpha) = x_i - x'_i. The fundamental theorem of calculus gives

F(x)−F(x′)=g(1)−g(0)=∫01g′(α) dα=∑i=1nIGi(x)F(x) - F(x') = g(1) - g(0) = \int_0^1 g'(\alpha)\, d\alpha = \sum_{i=1}^{n} \text{IG}_i(x)

This needs FF to be continuous and differentiable almost everywhere along the path, which the paper notes holds for networks built from sigmoids, ReLUs and pooling.

Path methods in symbols

Any smooth path γ\gamma from x′x' to xx gives a path method:

PathIGiγ(x)=∫01∂F(γ(α))∂γi(α)⋅∂γi(α)∂α dα\text{PathIG}_i^{\gamma}(x) = \int_0^1 \frac{\partial F(\gamma(\alpha))}{\partial \gamma_i(\alpha)} \cdot \frac{\partial \gamma_i(\alpha)}{\partial \alpha}\, d\alpha

The straight line is the special case γ(α)=x′+α(x−x′)\gamma(\alpha) = x' + \alpha(x - x'), which gives the formula above. Path methods all satisfy Implementation Invariance and Completeness. The paper states that they are the only methods that always satisfy Implementation Invariance, a dummy property (zero attribution to variables the function does not depend on), Linearity and Completeness. That result is credited to Friedman (2004), and the paper leaves the proof there.

Symmetry in words

Two inputs are symmetric for a function if swapping them leaves the function unchanged. Symmetry-preserving methods give symmetric inputs equal attributions when they have equal values in both the input and the baseline. The paper's Theorem 1 says integrated gradients is the unique path method with this property. Its proof is in the appendix.

Results

  • Gradients break Sensitivity. The paper's example f(x)=1−ReLU(1−x)f(x) = 1 - \mathsf{ReLU}(1 - x) shows zero gradient at an input where the output differs from the baseline. The appendix shows that deconvolutional networks and guided backpropagation also give zero attribution to a feature the output depends on.
  • DeepLift and LRP break Implementation Invariance. The appendix gives two functionally equivalent networks, ff and gg, for which they assign different attributions. Integrated gradients gives the same attributions for both.
  • Integrated gradients satisfies both axioms. Completeness implies Sensitivity, and the method uses only gradients, so it is implementation invariant.
  • Uniqueness. Integrated gradients is the unique path method that is symmetry-preserving (Theorem 1). The paper says it is not the unique method with the two axioms, since averaging over paths, such as the Shapley-Shubik method, also satisfies them.
  • Cost. The paper reports that 20 to 300 steps were enough to approximate the integral within 5 percent. Neural machine translation used 100 to 1000 steps, because that network is highly nonlinear. Shapley-Shubik would need n!n! orderings. For a 100 by 100 image, n=10000n = 10000, while integrated gradients uses 20 to 300 calls.
  • Applications. In the object recognition network, integrated gradients highlights distinctive features of the image more than gradient-times-image does. In the diabetic retinopathy network, attributions fall on lesions, negative inside and positive at the boundary. In question classification, "how many" marks numeric questions, "total number" was a new numeric rule the authors found, and "charles" was an undesirable trigger for yes/no questions. In translation, "und" is mostly attributed to "and" and "morgen" to "morning." In the chemistry network, bonded atom pairs contribute 46 percent of the prediction score and all other pairs contribute negative 3 percent. The attributions also exposed identical credit for atoms with different neighbors, which led the authors to a defect in an architecture.
  • Limits. The paper's applications are shown as figures and examples; the text reports no benchmark accuracy for them. The authors say that empirical tests could not separate method errors from model errors, which is why they used axioms. The baseline choice affects the result, and a baseline can be chosen adversarially so that its score is near zero but its features are not neutral. The method does not address feature interactions or the network's logic. Attention weights are not a substitute, since the paper argues attention ignores other channels of influence such as an LSTM's memory cell and recurrent state.

Reading guide

Check yourself

QuestionName the two axioms the paper proposes, and state what each one requires.Show answer

Sensitivity: if the input and baseline differ in one feature and the predictions differ, that feature must get a nonzero attribution. Implementation Invariance: two networks that give the same output for every input must get identical attributions. Integrated gradients also satisfies Completeness, which says the attributions sum to F(x)−F(x′)F(x) - F(x').

QuestionFor f(x)=1−ReLU(1−x)f(x) = 1 - \mathsf{ReLU}(1 - x), baseline 00, input 33, what does integrated gradients give to xx?Show answer

The path is γ(α)=3α\gamma(\alpha) = 3\alpha. The gradient is 1 while 3α<13\alpha \lt 1, that is for α<1/3\alpha \lt 1/3, and 0 after. The integral of the gradient is 1/31/3. Multiply by the distance 3−0=33 - 0 = 3 and get 3×1/3=13 \times 1/3 = 1. The output change is f(3)−f(0)=1−0=1f(3) - f(0) = 1 - 0 = 1, so the answer is 1.

QuestionWhy does the method average gradients along a path rather than using the gradient at the input alone?Show answer

At the input the gradient can be zero even when the output differs from the baseline, as in the flat region of the ReLU example. The path integral includes the points between baseline and input, where the function is still changing. The average keeps that change, and completeness then ensures the attributions account for the whole output difference.

QuestionA classifier scores the input 0.70 and the baseline 0.10. Your integrated gradients attributions sum to 0.52. Using the paper's rough 5 percent check, is the approximation acceptable, and what should you do?Show answer

The target is 0.70−0.10=0.600.70 - 0.10 = 0.60. The gap is 0.60−0.52=0.080.60 - 0.52 = 0.08, and its share is 0.08/0.60≈0.1330.08 / 0.60 \approx 0.133, about 13 percent. That is well above 5 percent, so the approximation is not acceptable. Increase the number of steps and check again.

Sources

Read the full paper

Mukund Sundararajan, Ankur Taly, Qiqi Yan, 2017. arXiv:1703.01365