KernelShap
KernelShap
Bases: Explainer
KernelSHAP 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. |
required |
n_samples |
int
|
Number of samples |
25
|
baseline_fn |
Union[BaselineMethodOrFunction, Tuple[BaselineMethodOrFunction]]
|
The baseline function, accepting the attribution input, and returning the baseline accordingly. |
'zeros'
|
feature_mask_fn |
Union[FeatureMaskMethodOrFunction, Tuple[FeatureMaskMethodOrFunction]
|
The feature mask function, accepting the attribution input, and returning the feature mask accordingly. |
'felzenszwalb'
|
mask_token_id |
Optional[int]
|
The token id of the mask, used for modalities, utilizing tokenization |
None
|
forward_arg_extractor |
Optional[ForwardArgumentExtractor]
|
A function that extracts forward arguments from the input batch(s) where the attribution scores are assigned. |
None
|
additional_forward_arg_extractor |
Optional[ForwardArgumentExtractor]
|
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
Scott M. Lundberg, Su-In Lee. A Unified Approach to Interpreting Model Predictions.
Source code in pnpxai/explainers/kernel_shap.py
15 16 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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
attribute(inputs, targets=None)
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. |
None
|
Returns:
Type | Description |
---|---|
Union[Tensor, Tuple[Tensor]]
|
Union[torch.Tensor, Tuple[torch.Tensor]]: The result of the explanation. |
Source code in pnpxai/explainers/kernel_shap.py
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 |
|
get_tunables()
Provides Tunable parameters for the optimizer
Tunable parameters
n_samples
(int): Value can be selected in the range of range(10, 50, 10)
baseline_fn
(callable): BaselineFunction selects suitable values in accordance with the modality
feature_mask_fn
(callable): FeatureMaskFunction selects suitable values in accordance with the modality
Source code in pnpxai/explainers/kernel_shap.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|