Interface description
XAIBase.jl is a light-weight dependency that defines the interface of XAI 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:
- An XAI method has to be a subtype of
AbstractXAIMethod
- An XAI algorithm 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 anExplanation
- The input is expected to have a batch dimensions as its last dimension
- When applied to a batch, the method returns a single
Explanation
, which contains the batched output in theval
field. AbstractOutputSelector
s are predefined callable structs that select a single scalar value from a model's output, e.g. the maximally activated output of a classifier usingMaxActivationSelector
or a specific output usingIndexSelector
.
Refer to the Explanation
documentation for a description of the expected fields. For more information, take a look at src/XAIBase.jl
.
Implementation template
Julia-XAI 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
extras = nothing # optionally add additional information using a named tuple
return Explanation(val, input, output, output_selection, :MyMethod, :attribution, extras)
end
Refer to the example implementations for more information.