Interface description

XAIBase.jl is a light-weight dependency that defines the interface of feature-attribution methods in the Julia-XAI ecosystem.

Building on top of XAIBase (or providing an interface via package extensions) makes your package compatible with the Julia-XAI ecosystem, allowing you to automatically compute heatmaps for vision and language models using VisionHeatmaps.jl and TextHeatmaps.jl.

This only requires you to fulfill the following two requirements:

  1. A feature-attribution method has to be a subtype of AbstractXAIMethod
  2. A feature-attribution method has to implement a call_analyzer method:
import XAIBase: call_analyzer

call_analyzer(input, method::MyMethod, output_selector::AbstractOutputSelector; kwargs...)
  • call_analyzer has to return an Attribution
  • The input is expected to have a batch dimensions as its last dimension
  • The output is expected to be a matrix (of e.g. logits) with a batch dimensions as its last dimension
  • When applied to a batch, the method returns a single Attribution, which contains the batched output in the val field.
  • AbstractOutputSelectors are predefined callable structs that select scalar values from a model's output, e.g. the maximally activated outputs of a classifier using MaxActivationSelector or a specific output indices using IndexSelector.

Refer to the Attribution documentation for a description of the expected fields. For more information, take a look at src/XAIBase.jl.

Implementation template

Julia-XAI feature-attribution methods will usually follow the following template:

using XAIBase
import XAIBase: call_analyzer

struct MyMethod{M} <: AbstractXAIMethod
    model::M
end

function call_analyzer(input, method::MyMethod, output_selector::AbstractOutputSelector; kwargs...)
    output = method.model(input)
    output_selection = output_selector(output)

    val = ...              # your method's implementation
    pooling = NormPooling()   # how to reduce `val` over its feature dimension
    return Attribution(val, input, output, output_selection, pooling)
end

Refer to the example implementations for more information.