Integrated Gradients ReLU Path
Integrate gradients along a baseline path and verify the exact completeness identity.
By Riano · Published · Updated · Report a correction
Integrated Gradients ReLU Path
Integrated Gradients (IG) is a technique for attributing the prediction of a neural network to its input features. This module demonstrates the integration path along a single ReLU activation function and verifies the exact completeness identity.
Worked Example
Consider a scalar function F(x) = ReLU(w·x + b), where w = [1, 2], b = -1. Let baseline a = [0, 0] and input x = [1, 1].
- First, calculate the function values at the baseline and input:
F(a) = max(0, 1(0) + 2(0) - 1) = max(0, -1) = 0
F(x) = max(0, 1(1) + 2(1) - 1) = max(0, 2) = 2 - The straight path is parameterized by α ∈ [0, 1]:
p(α) = a + α(x - a) = [α, α] - The pre-activation along this path is:
w·p(α) + b = 1(α) + 2(α) - 1 = 3α - 1 - We find where the pre-activation is positive:
3α - 1 > 0 ⇒ α > 1/3. - The gradient of the ReLU is 1 when positive (for α ∈ (1/3, 1]) and 0 when negative. The fraction of the active path in α ∈ [0, 1] is 1 - 1/3 = 2/3.
- The attribution for feature i is IG_i = (x_i - a_i) × w_i × (active path fraction).
IG_1 = (1 - 0) × 1 × (2/3) = 2/3 ≈ 0.6666666666666666
IG_2 = (1 - 0) × 2 × (2/3) = 4/3 ≈ 1.3333333333333333 - Check the completeness identity: IG_1 + IG_2 = 2/3 + 4/3 = 2 = F(x) - F(a). The completeness residual is exactly 0.0.
Experiment
Open the Interactive Module to explore how the baseline and input affect the attributions.
- Set Weights to Positive, Bias to -1, Baseline to Origin, and Input to Positive. Verify the attributions match the worked example above: 0.6666666666666666 and 1.3333333333333333.
- Change Weights to Mixed. The pre-activation 2(1) - 1(1) - 1 = 0 means the function never becomes strictly positive. The active path fraction is 0, yielding attributions of 0 and output difference of 0.
- Switch Weights back to Positive, and change Baseline to Left. Observe how the integration path changes, activating at a different point and altering the individual attributions to 1.0 and 1.0, though they still sum to the total difference of 2.
Limitations
This visualization simplifies Integrated Gradients by applying it to a single ReLU node. In deep neural networks with multiple layers and non-linearities, the integration path becomes highly non-linear with respect to the final output, and calculating the exact integral is often intractable, requiring discrete approximations (such as Riemann sums). The choice of baseline is also subjective and heavily influences the resulting attributions.
References
Integrated Gradients is formally established by Sundararajan et al. The following source covers axiomatic attribution in deep networks:
- Sundararajan, M., Taly, A., and Yan, Q. (2017). Axiomatic Attribution for Deep Networks. In Proceedings of the 34th International Conference on Machine Learning, PMLR 70:3319-3328. This paper introduces Integrated Gradients and establishes the completeness axiom.
Experience it interactively
Adjust parameters, observe in real time, and build deep intuition with Riano’s interactive Integrated Gradients ReLU Path module.
Try Integrated Gradients ReLU Path on Riano →