SaliencyMapExplainer<T>

Models & Types · AiDotNet.Interpretability.Explainers

Saliency Map explainer using gradient-based methods.

Implements: ILocalExplainer<T, SaliencyMapExplanation<T>>

For Beginners

Saliency maps are one of the simplest ways to explain neural networks. They show which input features are most “sensitive” - where small changes would most affect the output.

Types of saliency methods:

  1. Vanilla Gradient: The raw gradient of output w.r.t. input
  2. Gradient × Input: Gradient multiplied by input (more interpretable)
  3. SmoothGrad: Average gradient over noisy versions (reduces noise)
  4. SmoothGrad²: Squared gradients for sharper feature focus

How to interpret:

  • High absolute saliency = changing this feature would change the output a lot
  • For images: bright spots show important pixels
  • For tabular data: high values show important features

Pros:

  • Fast to compute (single backward pass)
  • Easy to understand
  • Works with any differentiable model

Cons:

  • Can be noisy (especially vanilla gradient)
  • Doesn’t show actual contribution, just sensitivity
  • Can miss important features with low gradient

SmoothGrad is recommended for cleaner visualizations.

Constructors

Constructor Summary
SaliencyMapExplainer(Func<Vector<T>, Vector<T>> predictFunction, Func<Vector<T>, int, Vector<T>> gradientFunction, int numFeatures, SaliencyMethod method, int smoothGradSamples, double smoothGradNoise, string[] featureNames, int? randomState) Initializes a new Saliency Map explainer.

Properties

Property Summary
bool SupportsGlobalExplanations { get; }
bool SupportsLocalExplanations { get; }
string MethodName { get; }

Methods

Method Summary
SaliencyMapExplanation<T> Explain(Vector<T> instance) Computes saliency map for an input.
SaliencyMapExplanation<T> Explain(Vector<T> instance, int outputIndex) Computes saliency map for a specific output.
SaliencyMapExplanation<T>[] ExplainBatch(Matrix<T> instances)