Loading skill
Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Explains PyTorch predictions via feature attribution (Integrated Gradients, DeepLIFT, SmoothGrad, Occlusion) for vision and text models.
73% 82%+9 ptsof test cases passed
Passed 18 of 22 test cases with the skill, and 16 of 22 without it.
3 of 3 safety checks passed
Not used yet
Captum (Comprehension in PyTorch) provides model interpretability for PyTorch models. Implements Integrated Gradients, Gradient SHAP, DeepLIFT, Occlusion, Feature Ablation, and Layer Conductance. Supports computer vision, NLP, and tabular models.
uv pip install captum
import torch
import torch.nn as nn
from captum.attr import IntegratedGradients
model = nn.Linear(10, 2)
input = torch.randn(1, 10)
baseline = torch.zeros(1, 10)
ig = IntegratedGradients(model)
attrs = ig.attribute(input, baseline, target=0)
print(f"Feature attributions: {attrs}")
from captum.attr import Occlusion
occ = Occlusion(model)
attrs = occ.attribute(input, target=0, sliding_window_shapes=(1,)) # 1D
print(attrs)
from captum.attr import visualization as viz
Next to this one in the catalogue, plus more from the same author.