Skip to content

Integrated gradients

Attribute a model’s output change to input features by integrating gradients from a baseline, while checking path choices, interaction allocation and numerical convergence.

Integrated gradients (IG) assigns each input feature a contribution to a scalar model output’s change from a chosen baseline, by accumulating input gradients along the straight line between baseline and observation. For a quant model, it can help investigate why a predicted risk score differs from a reference market state. Its answer depends on that reference and on the output being explained.
A gradient saliency map measures sensitivity at or near the observation. IG instead follows the journey from reference to observation, including regions where the model’s response was stronger before flattening. This is the distinction behind the method introduced by Sundararajan, Taly and Yan.

Name the comparison before computing it

Let ff be the scalar output, xx the observed feature vector and bb the baseline. Standard IG is

IG⁡i(x;b)=(xi−bi)∫01∂f(b+α(x−b))∂xi dα.\operatorname{IG}_i(x;b)=(x_i-b_i)\int_0^1 \frac{\partial f(b+\alpha(x-b))}{\partial x_i}\,d\alpha.

The multiplier xi−bix_i-b_i matters: an average derivative alone has different units. IG has the units of the chosen output. A positive attribution adds to the output difference; a negative one offsets it. Neither sign establishes whether a feature is economically desirable.

For a credit model, explaining a default probability differs from explaining its pre-sigmoid logit. A nonlinear output transformation changes the gradients along the path; one cannot transform individual logit attributions into probability attributions afterward. Specify the target output or class, feature preprocessing and model evaluation settings before comparing explanations.

A zero baseline is a numerical convenience, not an automatic definition of “no information.” Zero in a standardised variable may represent a historical mean; zero in a raw price variable may be implausible. A reference market observation answers a different question from an all-zero vector. Sturmfels, Lundberg and Lee’s baseline study shows why such choices belong to the explanation itself.

One interaction, three allocations

Consider a synthetic score with dimensionless inputs,

f(x1,x2)=x1x2,b=(0,0),x=(2,3).f(x_1,x_2)=x_1x_2,\qquad b=(0,0),\qquad x=(2,3).

The score rises from 00 to 66. On the straight path (2α,3α)(2\alpha,3\alpha), the partial derivatives are 3α3\alpha and 2α2\alpha. Therefore

IG⁡1=2∫013α dα=3,IG⁡2=3∫012α dα=3.\operatorname{IG}_1=2\int_0^1 3\alpha\,d\alpha=3, \qquad \operatorname{IG}_2=3\int_0^1 2\alpha\,d\alpha=3.

At the endpoint, the raw gradient is (3,2)(3,2); multiplying it by the displacement gives (6,6)(6,6), which sums to 1212. That endpoint shortcut counts the product interaction twice. IG allocates the interaction across the journey.

Synthetic bilinear score from baseline (0,0) to target (2,3). Straight-line integrated gradients allocate 3 to each feature. Changing feature 1 first allocates 0 to feature 1 and 6 to feature 2; reversing the order allocates 6 and 0. Every path sums to 6.
Synthetic bilinear score from baseline (0,0) to target (2,3). Straight-line integrated gradients allocate 3 to each feature. Changing feature 1 first allocates 0 to feature 1 and 6 to feature 2; reversing the order allocates 6 and 0. Every path sums to 6.

Original synthetic example. The product interaction is split equally by the straight path; coordinate-by-coordinate paths allocate it to whichever feature changes second. Completeness holds for all three allocations.

The two bent paths in the figure are alternative path attribution methods, rather than standard IG. Change x1x_1 from 00 to 22 while x2=0x_2=0, and the score stays zero. Changing x2x_2 next creates the entire rise of 66: the allocation is (0,6)(0,6). Reverse the order and it becomes (6,0)(6,0). These are exact allocations of the same model change, so adding up correctly cannot select the economically appropriate path.

Even retaining the straight path, changing the baseline to (1,1)(1,1) changes IG to (2,3)(2,3). The total is now 55, because the reference score is 11. This is a different comparison, not a failed completeness check.

What completeness promises

Under conditions that justify the chain rule along the path and the fundamental theorem of calculus,

∑iIG⁡i(x;b)=f(x)−f(b).\sum_i\operatorname{IG}_i(x;b)=f(x)-f(b).

For example, these conditions hold when ff is continuously differentiable around the path. A more general sufficient formulation requires the output along the path to be absolutely continuous and its derivative to equal the gradient dotted with the path velocity almost everywhere. Ordinary continuous piecewise-smooth networks can meet this condition despite isolated activation kinks. Differentiability almost everywhere in the surrounding input space alone is insufficient to justify every exceptional path: inspect paths that run along nondifferentiable boundaries and the derivative conventions used there. Discrete decisions, hard thresholds and tree splits do not automatically inherit the smooth-path argument.

Completeness is an accounting identity for the fitted function. It does not establish that a feature caused a realised market outcome, that the baseline is neutral, or that the interpolated feature combinations are realistic. Correlated market inputs may travel through states absent from training data. In this example, the equal split is a path-based allocation of a pure interaction; it is not evidence that two real economic mechanisms contributed equally.

Check the integral, then the interpretation

Numerical IG replaces the integral with weighted gradient evaluations. Define the signed completeness residual as

r=∑iIG⁡^i−(f(x)−f(b)).r=\sum_i\widehat{\operatorname{IG}}_i-\bigl(f(x)-f(b)\bigr).

For the bilinear example, equally spaced right-endpoint sums give:

Integration rulePointsEstimated contributionsResidual rr
Right endpoints20(3.15,3.15)(3.15,3.15)0.300.30
Right endpoints100(3.03,3.03)(3.03,3.03)0.060.06
Midpoints20(3,3)(3,3)00
The midpoint rule is exact here because the path integrands are linear; that result does not extend to arbitrary networks. Captum’s API offers Riemann rules and Gauss–Legendre quadrature, a step-count setting, and a convergence delta. The standard formula here includes the displacement multiplier, corresponding to its multiply_by_inputs=True setting.

Use a finer grid or another integration rule to check individual attribution stability as well as the total. A small residual can conceal cancelling component errors; it cannot validate a baseline or supply causal evidence. Report the baseline, output scale, integration method and residual with the explanation, and examine whether conclusions survive defensible alternative baselines.

IG repeatedly evaluates ordinary gradients. DeepLIFT instead propagates contributions based on activation differences from a reference, as described by Shrikumar, Greenside and Kundaje. A shared reference-based interpretation does not make the methods interchangeable.
For the derivative machinery, Backpropagation as the Chain Rule explains how the backward pass reuses local computations. Its public preview is open; the full lesson requires membership. Attribution differentiates a selected output with respect to inputs, whereas training typically differentiates a loss with respect to parameters.

Sources

Last updated
  • explainable ai
  • feature attribution
  • deep learning
← Back to the glossaryBack to top ↑