IntegratedGradients
pnpxai.explainers.integrated_gradients
IntegratedGradients
Bases: Explainer
IntegratedGradients explainer.
Supported Modules: Linear
, Convolution
, Attention
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
Module
|
The PyTorch model for which attribution is to be computed. |
required |
baseline_fn
|
Union[BaselineMethodOrFunction, Tuple[BaselineMethodOrFunction]]
|
The baseline function, accepting the attribution input, and returning the baseline accordingly. |
'zeros'
|
n_steps
|
int
|
The Number of steps the algorithm makes |
20
|
layer
|
Optional[Union[Union[str, Module], Sequence[Union[str, Module]]]]
|
The target module to be explained |
None
|
n_classes
|
Optional[int]
|
Number of classes |
required |
forward_arg_extractor
|
Optional[Callable[[Tuple[Tensor]], Union[Tensor, Tuple[Tensor]]]]
|
A function that extracts forward arguments from the input batch(s) where the attribution scores are assigned. |
None
|
additional_forward_arg_extractor
|
Optional[Callable[[Tuple[Tensor]], Union[Tensor, Tuple[Tensor]]]]
|
A secondary function that extract additional forward arguments from the input batch(s). |
None
|
**kwargs
|
Keyword arguments that are forwarded to the base implementation of the Explainer |
required |
Reference
Mukund Sundararajan, Ankur Taly, Qiqi Yan. Axiomatic Attribution for Deep Networks.
SUPPORTED_MODULES = [Linear, Convolution, Attention]
class-attribute
instance-attribute
layer = layer
instance-attribute
n_steps = n_steps
instance-attribute
baseline_fn = baseline_fn
instance-attribute
explainer: Union[CaptumIntegratedGradients, CaptumLayerIntegratedGradients]
property
EXPLANATION_TYPE: ExplanationType = 'attribution'
class-attribute
instance-attribute
TUNABLES = {}
class-attribute
instance-attribute
model = model.eval()
instance-attribute
forward_arg_extractor = forward_arg_extractor
instance-attribute
additional_forward_arg_extractor = additional_forward_arg_extractor
instance-attribute
device
property
__init__(model: Module, n_steps: int = 20, baseline_fn: Union[BaselineMethodOrFunction, Tuple[BaselineMethodOrFunction]] = 'zeros', layer: Optional[Callable[[Tuple[Tensor]], Union[Tensor, Tuple[Tensor]]]] = None, forward_arg_extractor: Optional[Callable[[Tuple[Tensor]], Union[Tensor, Tuple[Tensor]]]] = None, additional_forward_arg_extractor: Optional[Callable[[Tuple[Tensor]], Union[Tensor, Tuple[Tensor]]]] = None) -> None
attribute(inputs: Union[Tensor, Tuple[Tensor]], targets: Tensor) -> Union[Tensor, Tuple[Tensor]]
Computes attributions for the given inputs and targets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inputs
|
Tensor
|
The input data. |
required |
targets
|
Tensor
|
The target labels for the inputs. |
required |
Returns:
Type | Description |
---|---|
Union[Tensor, Tuple[Tensor]]
|
Union[torch.Tensor, Tuple[torch.Tensor]]: The result of the explanation. |
get_tunables() -> Dict[str, Tuple[type, dict]]
Provides Tunable parameters for the optimizer
Tunable parameters
noise_level
(float): Value can be selected in the range of range(10, 100, 10)
baseline_fn
(callable): BaselineFunction selects suitable values in accordance with the modality