Part XXI — Explainable AI & Model Interpretability · Chapter 4

Integrated gradients

Hook

Saliency maps score a feature's importance by its gradient at the input — but a sigmoid deep in saturation has a gradient near zero everywhere close to the input, even when that feature clearly moved the output a lot on the way there. What does the gradient look like along the whole path, not just at the destination?

Intuition

Instead of one gradient at one point, walk from a baseline to the input in small steps and average the gradient along the way. More steps means a finer walk along the exact same path, not a different destination — and the result converges to something a single gradient could never see.

Formalize

Integrated gradients attribute a prediction to an input by integrating the gradient along the straight-line path from a baseline to the actual input:

IG(x)=(xxbaseline)01fx(xbaseline+α(xxbaseline))dα\text{IG}(x) = (x - x_{\text{baseline}}) \int_0^1 \frac{\partial f}{\partial x}\Big(x_{\text{baseline}} + \alpha(x - x_{\text{baseline}})\Big)\, d\alpha
  • IG(x)\text{IG}(x) — the integrated gradients attribution for input xx: how much of the output change gets credited to this feature.
  • xx — the actual input value being explained.
  • xbaselinex_{\text{baseline}} — the reference input (often all zeros) that the path starts from, representing "no information" for that feature.
  • α\alpha — the interpolation fraction along the straight-line path from baseline to input, ranging from 00 to 11.
  • ff — the model, as a function of its input.
  1. Approximated by a Riemann sum

    In practice this integral is approximated by a Riemann sum over mm steps along that path.

  2. Completeness axiom

    As mm grows, the attribution converges to exactly f(x)f(xbaseline)f(x) - f(x_{\text{baseline}}), the true change in output — the key guarantee behind this method.

  3. Saliency is the degenerate case, m=1

    Plain saliency is just this method with a single step: the gradient at the input alone, with no path at all.

Play
baseline (x=0) → input (x=2): the path crosses the steep middle, even though the plain gradient AT x=2 is only 0.00023

The model curve is flat near both ends and steep only in the middle. The path from baseline to input crosses that entire steep region — but the gradient at the input alone sits in the flat, saturated tail, where it's almost meaningless.

Worked example

f(x)=σ(5x)f(x) = \sigma(5x), baseline x0=0x_0=0, input x=2x=2:

  1. The true output change is large, the gradient at the input is tiny
    • f(0)=σ(0)=0.5f(0)=\sigma(0)=0.5
    • f(2)=σ(10)=1/(1+e10)0.99995f(2)=\sigma(10)=1/(1+e^{-10})\approx0.99995

    A change of nearly 0.50.5. The derivative f(x)=5σ(5x)(1σ(5x))f'(x)=5\sigma(5x)(1-\sigma(5x)) at x=2x=2: f(2)=5×0.99995×(10.99995)5×0.99995×0.000050.000227f'(2)=5\times0.99995\times(1-0.99995) \approx5\times0.99995\times0.00005\approx0.000227 — the input sits so deep in saturation that its own gradient badly understates how much it mattered.

  2. One step reduces to the same blind spot

    With only 1 integration step, IG evaluates the gradient only at the input itself — identical to plain saliency. The result, 0.00045\approx0.00045, misses over 99.9% of the true 0.4999546\approx0.4999546 output change.

  3. More steps recover the missing attribution
    • At 10 steps: 0.375\approx0.375 (gap 0.125\approx0.125)
    • At 50 steps: 0.475\approx0.475 (gap 0.025\approx0.025)
    • At 500 steps: 0.497\approx0.497 (gap 0.0025\approx0.0025)

    Steadily converging toward the exact true change, because most of that path crosses the steep, high-gradient middle that a single endpoint gradient never sees.

Checkpoint

Find the step count, among the three candidates, where integrated gradients lands within 0.05 of the true output change.

Pick a step count to try it
Summary
IG(x)mf(x)f(xbaseline)(completeness)\text{IG}(x) \xrightarrow[m\to\infty]{} f(x) - f(x_{\text{baseline}}) \qquad\text{(completeness)}

Saliency asks "how steep is the model right here?" Integrated gradients asks the more honest question: "how much did this feature's whole journey from nothing to its actual value change the answer?" Saturating activations — sigmoids, tanh, anything with a flat tail — are exactly where those two questions diverge, and exactly where a plain gradient becomes actively misleading rather than just imprecise. The next chapter looks at feature importance from a completely different angle: not the gradient at all, but how the prediction changes as you sweep one feature across its whole range.