Basic API

All methods in ExplainableAI.jl work by calling analyze on an input and an analyzer:

XAIBase.analyzeFunction
analyze(input, method)
analyze(input, method, output_selection)

Apply the analyzer method for the given input, returning an Explanation. If output_selection is specified, the explanation will be calculated for that output. Otherwise, the output with the highest activation is automatically chosen.

See also Explanation.

source
XAIBase.ExplanationType
Explanation(val, output, output_selection, analyzer, heatmap, extras)

Return type of analyzers when calling analyze.

Fields

  • val: numerical output of the analyzer, e.g. an attribution or gradient
  • output: model output for the given analyzer input
  • output_selection: index of the output used for the explanation
  • analyzer: symbol corresponding the used analyzer, e.g. :Gradient or :LRP
  • heatmap: symbol indicating a preset heatmapping style, e.g. :attribution, :sensitivity or :cam
  • extras: optional named tuple that can be used by analyzers to return additional information.
source

For heatmapping functionality, take a look at either VisionHeatmaps.jl or TextHeatmaps.jl. Both provide heatmap methods for visualizing explanations, either for images or text, respectively.

Analyzers

ExplainableAI.GradientType
Gradient(model)

Analyze model by calculating the gradient of a neuron activation with respect to the input.

source
ExplainableAI.InputTimesGradientType
InputTimesGradient(model)

Analyze model by calculating the gradient of a neuron activation with respect to the input. This gradient is then multiplied element-wise with the input.

source
ExplainableAI.SmoothGradFunction
SmoothGrad(analyzer, [n=50, std=0.1, rng=GLOBAL_RNG])
SmoothGrad(analyzer, [n=50, distribution=Normal(0, σ²=0.01), rng=GLOBAL_RNG])

Analyze model by calculating a smoothed sensitivity map. This is done by averaging sensitivity maps of a Gradient analyzer over random samples in a neighborhood of the input, typically by adding Gaussian noise with mean 0.

References

  • Smilkov et al., SmoothGrad: removing noise by adding noise
source
ExplainableAI.IntegratedGradientsFunction
IntegratedGradients(analyzer, [n=50])
IntegratedGradients(analyzer, [n=50])

Analyze model by using the Integrated Gradients method.

References

  • Sundararajan et al., Axiomatic Attribution for Deep Networks
source
ExplainableAI.GradCAMType
GradCAM(feature_layers, adaptation_layers)

Calculates the Gradient-weighted Class Activation Map (GradCAM). GradCAM provides a visual explanation of the regions with significant neuron importance for the model's classification decision.

Parameters

  • feature_layers: The layers of a convolutional neural network (CNN) responsible for extracting feature maps.
  • adaptation_layers: The layers of the CNN used for adaptation and classification.

Note

Flux is not required for GradCAM. GradCAM is compatible with a wide variety of CNN model-families.

References

  • Selvaraju et al., Grad-CAM: Visual Explanations from Deep Networks via Gradient-based Localization
source

Input augmentations

SmoothGrad and IntegratedGradients are special cases of the input augmentations NoiseAugmentation and InterpolationAugmentation, which can be applied as a wrapper to any analyzer:

ExplainableAI.NoiseAugmentationType
NoiseAugmentation(analyzer, n, [std=1, rng=GLOBAL_RNG])
NoiseAugmentation(analyzer, n, distribution, [rng=GLOBAL_RNG])

A wrapper around analyzers that augments the input with n samples of additive noise sampled from distribution. This input augmentation is then averaged to return an Explanation.

source
ExplainableAI.InterpolationAugmentationType
InterpolationAugmentation(model, [n=50])

A wrapper around analyzers that augments the input with n steps of linear interpolation between the input and a reference input (typically zero(input)). The gradients w.r.t. this augmented input are then averaged and multiplied with the difference between the input and the reference input.

source

Index