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:
- A feature-attribution method has to be a subtype of
AbstractXAIMethod - A feature-attribution method has to implement a
call_analyzermethod:
import XAIBase: call_analyzer
call_analyzer(input, method::MyMethod, output_selector::AbstractOutputSelector; kwargs...)call_analyzerhas to return anAttribution- 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 thevalfield. AbstractOutputSelectors are predefined callable structs that select scalar values from a model's output, e.g. the maximally activated outputs of a classifier usingMaxActivationSelectoror a specific output indices usingIndexSelector.
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)
endRefer to the example implementations for more information.