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:
- Run a forward pass and select the scalar output to explain, for example the logit of the predicted class.
- Run a backward pass to obtain the gradient of that output with respect to every input feature.
- 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.
| Property | Holds | Practical meaning |
|---|---|---|
| Implementation invariance | Yes | Functionally identical networks get identical maps |
| Completeness | Only for linear models | Scores need not sum to the output |
| Sensitivity | No | A relevant feature can receive zero score |
| Linearity | Yes | Attributions of summed models add up |
| Baseline dependence | Implicit zero baseline | Results change if inputs are shifted |
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.
Comparison with related attribution methods
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.
| Method | Core idea | Cost per explanation | Main advantage |
|---|---|---|---|
| Vanilla gradient (saliency) | Absolute gradient only | One backward pass | Shows sensitivity |
| Gradient × input | Gradient scaled by input | One backward pass | Signed, input-aware scores |
| Integrated gradients | Average gradient along path from baseline | 20 to 300 backward passes | Satisfies completeness |
| SmoothGrad | Average gradients over noisy copies | About 50 backward passes | Reduces visual noise |
| DeepLIFT | Differences from reference via modified rules | One modified backward pass | Handles saturation better |
| Layer-wise relevance propagation | Redistributes relevance layer by layer | One modified backward pass | Conserves relevance |
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.
| Situation | Recommendation | Reason |
|---|---|---|
| Quick debugging of a vision or text model | Use gradient × input | Cheap and immediate |
| Regulatory or audit explanation | Prefer integrated gradients or SHAP | Completeness and stated baseline |
| Features where zero is meaningful | Use a method with explicit baseline | Zero inputs get no credit |
| Non-differentiable model such as gradient boosted trees | Use TreeSHAP or permutation methods | No gradients available |
| Token-level attribution in transformers | Apply to embeddings, then sum per token | Tokens are discrete indices |
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.