Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Relax type annotations to allow for non-array inputs #18

Closed
adrhill opened this issue Jul 22, 2024 · 0 comments · Fixed by #20
Closed

Relax type annotations to allow for non-array inputs #18

adrhill opened this issue Jul 22, 2024 · 0 comments · Fixed by #20

Comments

@adrhill
Copy link
Member

adrhill commented Jul 22, 2024

The XAIBase interface currently requires inputs to be AbstractArray{<:Real}:

function analyze(
input::AbstractArray{<:Real},

This is too strict for explanations on e.g. named tuples (required by Transformers.jl, see Julia-XAI/ExplainableAI.jl#164) or tabular data. Ideally, input should be left untyped.

Example

julia> using ExplainableAI

julia> x = (foo=fill(1, 2, 2), bar=fill(2, 3, 3))
(foo = [1 1; 1 1], bar = [2 2 2; 2 2 2; 2 2 2])

julia> mymodel(x) = x.foo
mymodel (generic function with 1 method)

julia> mymodel(x)
2×2 Matrix{Int64}:
 1  1
 1  1

julia> analyzer = Gradient(mymodel)
Gradient{typeof(mymodel)}(mymodel)

julia> expl = analyzer(x)
ERROR: MethodError: no method matching (::Gradient{typeof(mymodel)})(::@NamedTuple{foo::Matrix{Int64}, bar::Matrix{Int64}})

Closest candidates are:
  (::Gradient)(::Any, ::AbstractOutputSelector)
   @ ExplainableAI ~/.julia/packages/ExplainableAI/rEdqm/src/gradient.jl:22
  (::AbstractXAIMethod)(::AbstractArray{<:Real}, ::Union{Integer, Tuple{Integer}}; kwargs...)
   @ XAIBase ~/.julia/packages/XAIBase/7QtIN/src/analyze.jl:33
  (::AbstractXAIMethod)(::AbstractArray{<:Real}; kwargs...)
   @ XAIBase ~/.julia/packages/XAIBase/7QtIN/src/analyze.jl:40

Stacktrace:
 [1] top-level scope
   @ REPL[11]:1
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant