Gradient × input

Also known as: gradient times input · input × gradient · InputXGradient

On this page 7

Gradient × input is a gradient-based feature attribution method that scores each input feature by multiplying its value by the partial derivative of the model output with respect to that feature. The result is a signed relevance map with the same shape as the input, which indicates how strongly, and in which direction, each feature pushed a specific prediction. In Explainable AI, it is one of the simplest local explanation techniques for differentiable models such as neural networks.

The method is also known as gradient times input or InputXGradient, the name used in the Captum library. It costs one forward and one backward pass, which makes it fast enough for interactive debugging, and it serves as a baseline against which more elaborate attribution methods in artificial intelligence are compared.

How gradient × input computes attributions

For a model output f(x) and input features x_i, the attribution of feature i is x_i multiplied by the partial derivative of f with respect to x_i. The gradient measures local sensitivity, meaning how much the output would change for a tiny change in that feature, while the input value scales that sensitivity by how much of the feature is actually present.

The output f is usually the logit or pre-softmax score of the target class rather than the probability, because the softmax saturates and flattens gradients. The computation proceeds in three steps:

  1. Run a forward pass and select the scalar output to explain, for example the logit of the predicted class.
  2. Run a backward pass to obtain the gradient of that output with respect to every input feature.
  3. Multiply the gradient element-wise by the input and, for images, optionally sum across color channels.

The multiplication has a useful interpretation. For a purely linear model, gradient × input returns exactly each feature’s term w_i x_i in the prediction, so the attributions sum to the output minus the bias. This exact decomposition holds only for linear functions; for nonlinear networks it is a first-order approximation around the current input.

Properties and theoretical behavior

Attribution methods are judged by formal properties called axioms, and gradient × input satisfies some of them but not others. Knowing which properties hold explains when its maps can be trusted.

PropertyHoldsPractical meaning
Implementation invarianceYesFunctionally identical networks get identical maps
CompletenessOnly for linear modelsScores need not sum to the output
SensitivityNoA relevant feature can receive zero score
LinearityYesAttributions of summed models add up
Baseline dependenceImplicit zero baselineResults change if inputs are shifted
Axiomatic properties of gradient × input

The implicit zero baseline is the most consequential property. Multiplying by x means that a feature with value zero always receives zero attribution, regardless of its importance. For normalized images, zero is a mid-gray pixel; for tabular data it may be a meaningful category, so input encoding directly shapes the explanation.

Gradient × input sits in a family of gradient-based methods that trade speed for faithfulness in different ways. Several of them reduce to gradient × input under specific conditions, which makes it a useful reference point.

MethodCore ideaCost per explanationMain advantage
Vanilla gradient (saliency)Absolute gradient onlyOne backward passShows sensitivity
Gradient × inputGradient scaled by inputOne backward passSigned, input-aware scores
Integrated gradientsAverage gradient along path from baseline20 to 300 backward passesSatisfies completeness
SmoothGradAverage gradients over noisy copiesAbout 50 backward passesReduces visual noise
DeepLIFTDifferences from reference via modified rulesOne modified backward passHandles saturation better
Layer-wise relevance propagationRedistributes relevance layer by layerOne modified backward passConserves relevance
Gradient × input and neighboring methods

Research has shown that epsilon-LRP and DeepLIFT with a zero reference reduce to gradient × input in networks with only ReLU activations, under certain conditions. Integrated gradients with a zero baseline also approaches gradient × input when the model is close to linear along the path. These links explain why the maps often look similar in practice.

Using gradient × input in practice

The method is most useful as a fast first diagnostic when a team needs explanations for many predictions or wants to inspect a model during training. Libraries such as Captum implement it in a few lines, and it scales to large models because it needs no sampling and no surrogate model.

SituationRecommendationReason
Quick debugging of a vision or text modelUse gradient × inputCheap and immediate
Regulatory or audit explanationPrefer integrated gradients or SHAPCompleteness and stated baseline
Features where zero is meaningfulUse a method with explicit baselineZero inputs get no credit
Non-differentiable model such as gradient boosted treesUse TreeSHAP or permutation methodsNo gradients available
Token-level attribution in transformersApply to embeddings, then sum per tokenTokens are discrete indices
When to choose gradient × input

For text and language models, the gradient is taken with respect to the token embeddings, and the per-dimension products are summed or reduced by an L2 norm to obtain one score per token. The choice between summing and taking a norm changes whether the sign of the contribution is preserved.

Limitations and failure modes

The method inherits the weaknesses of local gradients. When a neuron saturates, its gradient becomes close to zero even though the feature strongly influenced the output, so the explanation underestimates important features. Gradients of ReLU networks are also piecewise constant and can be noisy, producing speckled maps for images.

  • Saturation blindness: features that pushed a unit into a flat region receive little credit.
  • Input-scale artifacts: bright pixels or large raw values dominate the map regardless of relevance.
  • Gradient shattering in deep networks makes maps look like edge detectors.
  • Vulnerability to manipulation: small input perturbations can change the map without changing the prediction.
  • Failure of sanity checks in some studies, where maps stayed similar after model weights were randomized.

Because of these issues, gradient × input should be validated for explanation faithfulness, for example with deletion or insertion curves that remove top-ranked features and measure the drop in the output. A map that looks plausible is not evidence that it is faithful.

Explained without jargon

Imagine a recipe where the final taste depends on many ingredients. Gradient × input asks two questions for each ingredient. How much would the taste change if a little more were added? And how much of it is already in the dish? Multiplying the two answers gives a rough share of credit for each ingredient.

The method is quick, so it can check thousands of decisions. Its weakness is simple. An ingredient that is absent always gets zero credit, and an ingredient whose effect has already peaked looks unimportant. The result is a fast first look, not the final word.

A typical use case

A hospital imaging team trains a convolutional network to flag pneumonia on chest X-rays. Before a clinical pilot, engineers run gradient × input on 2,000 validation images, which takes only a few minutes on a single GPU because each image needs one backward pass.

The maps reveal that on many positive cases the highest attributions fall on a text marker in the image corner rather than on the lungs. The marker came from one scanner used mostly in the intensive care unit, where pneumonia is more common. The team crops the markers, retrains the model and confirms with integrated gradients that attributions now concentrate on lung fields. The cheap first-pass explanation exposed a shortcut that accuracy metrics had hidden.