XAIBase.jl

Core package defining the Julia-XAI interface.
Author Julia-XAI
Popularity
1 Star
Updated Last
2 Months Ago
Started In
October 2023

XAIBase.jl

Stable Dev Build Status Coverage Aqua JET

XAIBase is a light-weight dependency that defines the interface of XAI methods in the Julia-XAI ecosystem, which focusses on post-hoc, local input space explanations of black-box models. In simpler terms, methods that try to answer the question "Which part of the input is responsible for the model's output?"

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. It also allows you to use input-augmentations from ExplainableAI.jl.

Interface description

XAIBase only requires you to fulfill the following two requirements:

  1. An XAI algorithm has to be a subtype of AbstractXAIMethod
  2. 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 an Explanation
  • 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 the val field.
  • AbstractOutputSelector are predefined callable structs that select scalar values from a model's output, e.g. the maximally activated output of a classifier using MaxActivationSelector.

Refer to the Explanation documentation for a description of the expected fields. For more information, take a look at the documentation.

Example implementation

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

Tip

For full implementation examples, refer to the examples in the XAIBase documentation.

Acknowledgements

Adrian Hill acknowledges support by the Federal Ministry of Education and Research (BMBF) for the Berlin Institute for the Foundations of Learning and Data (BIFOLD) (01IS18037A).

Required Packages

No packages found.