VarGrad
VarGrad
Bases: SmoothGrad
VarGrad explainer.
Supported Modules: Linear
, Convolution
, LSTM
, RNN
, Attention
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
Module
|
The PyTorch model for which attribution is to be computed. noise_level (float): The noise level added during attribution. n_iter (int): The number of iterations, the input is modified. layer (Optional[Union[Union[str, Module], Sequence[Union[str, Module]]]]): The target module to be explained. |
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
Lorenz Richter, Ayman Boustati, Nikolas Nüsken, Francisco J. R. Ruiz, Ömer Deniz Akyildiz. VarGrad: A Low-Variance Gradient Estimator for Variational Inference.
Source code in pnpxai/explainers/var_grad.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
attribute(inputs, targets)
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]]
|
torch.Tensor: The result of the explanation. |
Source code in pnpxai/explainers/var_grad.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|