trw.train.integrated_gradients

Module Contents

Classes

IntegratedGradients

Implementation of Integrated gradients, a method of attributing the prediction of a deep network

Functions

is_feature_metadata(name: str, value: Any) → bool

Return True is a feature name/value should be considered as metadata

Attributes

logger

trw.train.integrated_gradients.logger
trw.train.integrated_gradients.is_feature_metadata(name: str, value: Any) bool

Return True is a feature name/value should be considered as metadata

class trw.train.integrated_gradients.IntegratedGradients(model: torch.nn.Module, steps: int = 100, baseline_inputs: Any = None, use_output_as_target: bool = False, post_process_output: Callable[[Any], torch.Tensor] = guided_back_propagation.post_process_output_id)
Implementation of Integrated gradients, a method of attributing the prediction of a deep network

to its input features.

This is implementing the paper Axiomatic Attribution for Deep Networks, Mukund Sundararajan, Ankur Taly, Qiqi Yan as described in https://arxiv.org/abs/1703.01365

__call__(self, inputs: Any, target_class_name: str, target_class: Optional[int] = None) Optional[Tuple[str, Mapping]]

Generate the guided back-propagation gradient

Parameters
  • inputs – a tensor or dictionary of tensors. Must have require_grads for the inputs to be explained

  • target_class – the index of the class to explain the decision. If None, the class output will be used

  • target_class_name

    the output node to be used. If None: * if model output is a single tensor then use this as target output

    • else it will use the first OutputClassification output

Returns

a tuple (output_name, dictionary (input, integrated gradient))