Quant Memo
Advanced

Saliency Maps and Raw Gradient Attribution

The simplest way to ask a network which inputs matter is to read off the gradient of its output with respect to each input, right where you're standing — a cheap, one-step compass reading, with real blind spots.

Prerequisites: Computational Graphs and Automatic Differentiation, Global vs Local Explanations

The cheapest way to ask "which input features does this network's prediction actually depend on" is to compute the gradient of the output with respect to each input feature, exactly where the input currently sits. That single number per feature — how much the output would move for a tiny nudge in that direction — is a saliency map. It costs one backward pass, reusing exactly the machinery already built for training, but it is only ever a local, single-point reading, and that limitation is easy to forget.

The analogy: a compass reading, valid only where you stand

A compass tells you which direction is "more uphill" from exactly where you are standing — completely accurate at that spot, but it says nothing about the terrain a mile away, and it can mislead you if you happen to be standing on a small flat ledge partway up an otherwise steep mountain: the compass reads "flat, no direction matters here" even though the mountain clearly has a dominant slope overall. A raw gradient is exactly this compass reading taken at the network's actual input — accurate about the local slope of the output with respect to each feature, right at that one point, but blind to whether that point happens to sit on a locally flat plateau of an otherwise steep, important function.

The computation

For a model output f(x)f(x) and input features x1,,xMx_1, \ldots, x_M, the saliency attribution for feature ii is simply:

Si(x)=f(x)xiS_i(x) = \frac{\partial f(x)}{\partial x_i}

computed at the specific input xx being explained, via one ordinary backward pass (automatic differentiation, the same operation used every training step). In words: this number says how fast the model's output would change per unit nudge to feature ii, evaluated only at this exact input — nothing is walked, sampled, or averaged, it is a single read of the local slope. A common variant, gradient × input, multiplies Si(x)S_i(x) by xix_i itself, which better reflects total contribution when features are on very different scales.

Worked example 1: a simple linear-plus-ReLU network

Let f(x)=max(0,2x1x2+3)f(x) = \max(0,\, 2x_1 - x_2 + 3), evaluated at x1=1,x2=0x_1=1, x_2=0, so the pre-activation value is 2(1)0+3=5>02(1)-0+3=5 > 0 — the ReLU is active (in its linear region). The gradient there is simply the linear coefficients: f/x1=2\partial f/\partial x_1 = 2, f/x2=1\partial f/\partial x_2 = -1. Gradient×input gives 2×1=22\times1=2 for feature 1 and 1×0=0-1\times0=0 for feature 2 — feature 2's raw gradient says "moving it would matter (coefficient 1-1)," but its gradient×input attribution says "at this specific value of zero, it isn't currently contributing anything," a genuinely different and equally valid question.

Worked example 2: where raw gradient goes wrong

Now evaluate the same network at x1=5,x2=0x_1=-5, x_2=0: the pre-activation is 2(5)0+3=7<02(-5)-0+3=-7 < 0, so the ReLU is in its flat, inactive region and outputs exactly 00. The gradient there is 00 for both features — raw saliency reports both x1x_1 and x2x_2 as completely unimportant at this point. But x1x_1 clearly matters a great deal to this model overall: moving it from 5-5 to, say, 11 would flip the ReLU active and change the output substantially. The single-point gradient, sitting on this flat region, is technically correct about the local slope and yet completely misses the feature's real importance — exactly the plateau problem the compass analogy describes.

x₁: gradient = 2 x₂: gradient = 0 (flat/saturated here, may still matter elsewhere)
A raw gradient of zero only reports "flat right here" — it cannot distinguish a genuinely irrelevant feature from one sitting on a locally saturated point.

Function explorer
-221.1
x = 1.00f(x) = 0.731

The flat tails of this curve are where raw gradient attribution goes quiet even though the input clearly still matters to the function's overall shape — the same failure mode a saturated ReLU or sigmoid layer produces inside a real network.

A saliency map is the gradient of a model's output with respect to each input feature, evaluated at one specific point — cheap to compute (a single backward pass) but only ever a local reading, which can report near-zero importance for a feature sitting on a locally flat region of an otherwise important function.

What this means in practice

Saliency maps are the fastest, most accessible explanation tool for any differentiable model, and remain useful as a quick first pass — spotting obviously irrelevant input regions in an image classifier, or obviously dead features in a trading signal network — but they should not be the final word on feature importance for any decision with real stakes, precisely because of the plateau blind spot.

The common mistake is treating a near-zero raw gradient as proof a feature doesn't matter to the model. It only proves the model's output is locally flat with respect to that feature at this exact input value — a saturated activation, a currently-inactive ReLU, or a genuinely flat region can all produce this reading for a feature that matters enormously elsewhere in the input space. Methods like integrated gradients exist specifically to fix this by looking at more than one point.

Related concepts

Practice in interviews

Further reading

  • Simonyan, Vedaldi & Zisserman, Deep Inside Convolutional Networks: Visualising Image Classification Models and Saliency Maps (2014)
ShareTwitterLinkedIn