LayerAttributionExplainer<T>

Models & Types · AiDotNet.Interpretability.Explainers

Layer-level attribution explainer for computing attributions at intermediate layers. Supports LayerIntegratedGradients, LayerDeepLIFT, LayerGradientXActivation, and LayerConductance.

Implements: IGPUAcceleratedExplainer<T>

For Beginners

While input attribution tells you which input features matter, layer attribution tells you which NEURONS IN A HIDDEN LAYER matter for the output.

Why layer attribution?

  • Higher-level features: Later layers encode abstract concepts, not raw pixels
  • Model understanding: See what the model “thinks” at each stage
  • Debugging: Find where information is lost or distorted
  • Transfer learning: Understand which learned representations are being used

Comparison of methods:

  • LayerGradient: Simple ∂output/∂layer, fast but noisy
  • LayerIntegratedGradients: Path-integrated gradients, theoretically grounded
  • LayerDeepLIFT: Difference from reference, handles saturation well
  • LayerConductance: Layer activation × gradient, captures both magnitude and sensitivity

Example: For an image classifier, layer attribution on the last conv layer might show that specific feature maps (detecting eyes, fur, etc.) are important for the “cat” prediction.

Constructors

Constructor Summary
LayerAttributionExplainer(Func<Vector<T>, Vector<T>> predictFunction, Func<Vector<T>, Vector<T>> layerActivationFunction, Func<Vector<T>, int, Vector<T>> layerGradientFunction, int layerSize, int inputSize, LayerAttributionMethod method, int integrationSteps) Initializes a layer attribution explainer.

Properties

Property Summary
bool IsGPUAccelerated { get; }
bool SupportsGlobalExplanations { get; } Gets whether this explainer supports global explanations.
bool SupportsLocalExplanations { get; } Gets whether this explainer supports local explanations.
string MethodName { get; } Gets the method name.

Methods

Method Summary
LayerAttributionResult<T> ComputeLayerAttribution(Vector<T> instance, int? targetClass) Computes layer attribution for the specified layer.
void SetGPUHelper(GPUExplainerHelper<T> helper)