Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Update XAIBase dependency to v4, drop support for Julia <1.10 #19

Merged
merged 5 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "RelevancePropagation"
uuid = "0be6dd02-ae9e-43eb-b318-c6e81d6890d8"
authors = ["Adrian Hill <gh@adrianhill.de>"]
version = "2.0.3-DEV"
version = "3.0.0-DEV"

[deps]
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
Expand All @@ -14,12 +14,12 @@ XAIBase = "9b48221d-a747-4c1b-9860-46a1d8ba24a7"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

[compat]
Flux = "0.13, 0.14"
Flux = "0.14"
MacroTools = "0.5"
Markdown = "1"
Random = "1"
Reexport = "1"
Statistics = "1"
XAIBase = "3"
XAIBase = "4"
Zygote = "0.6"
julia = "1.6"
julia = "1.10"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This package is part of the [Julia-XAI ecosystem](https://github.com/Julia-XAI)
[ExplainableAI.jl](https://github.com/Julia-XAI/ExplainableAI.jl).

## Installation
This package supports Julia ≥1.6. To install it, open the Julia REPL and run
This package supports Julia ≥1.10. To install it, open the Julia REPL and run
```julia-repl
julia> ]add RelevancePropagation
```
Expand Down
2 changes: 1 addition & 1 deletion src/RelevancePropagation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module RelevancePropagation

using Reexport
@reexport using XAIBase
import XAIBase: call_analyzer

using XAIBase: AbstractFeatureSelector, number_of_features
using Base.Iterators
Expand All @@ -12,7 +13,6 @@ using Zygote
using Markdown
using Statistics: mean, std

include("compat.jl")
include("bibliography.jl")
include("layer_types.jl")
include("layer_utils.jl")
Expand Down
6 changes: 0 additions & 6 deletions src/compat.jl

This file was deleted.

6 changes: 4 additions & 2 deletions src/crp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ end
# Call to CRP analyzer #
#======================#

function (crp::CRP)(input::AbstractArray{T,N}, ns::AbstractOutputSelector) where {T,N}
function call_analyzer(
input::AbstractArray{T,N}, crp::CRP, ns::AbstractOutputSelector
) where {T,N}
rules = crp.lrp.rules
layers = crp.lrp.model.layers
modified_layers = crp.lrp.modified_layers
Expand Down Expand Up @@ -88,5 +90,5 @@ function (crp::CRP)(input::AbstractArray{T,N}, ns::AbstractOutputSelector) where
end
end
end
return Explanation(R_return, last(as), ns(last(as)), :CRP, :attribution, nothing)
return Explanation(R_return, input, last(as), ns(last(as)), :CRP, :attribution, nothing)
end
6 changes: 3 additions & 3 deletions src/lrp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ LRP(model::Chain, c::Composite; kwargs...) = LRP(model, lrp_rules(model, c); kwa
# Call to the LRP analyzer #
#==========================#

function (lrp::LRP)(
input::AbstractArray, ns::AbstractOutputSelector; layerwise_relevances=false
function call_analyzer(
input::AbstractArray, lrp::LRP, ns::AbstractOutputSelector; layerwise_relevances=false
)
as = get_activations(lrp.model, input) # compute activations aᵏ for all layers k
Rs = similar.(as) # allocate relevances Rᵏ for all layers k
mask_output_neuron!(Rs[end], as[end], ns) # compute relevance Rᴺ of output layer N

lrp_backward_pass!(Rs, as, lrp.rules, lrp.model, lrp.modified_layers)
extras = layerwise_relevances ? (layerwise_relevances=Rs,) : nothing
return Explanation(first(Rs), last(as), ns(last(as)), :LRP, :attribution, extras)
return Explanation(first(Rs), input, last(as), ns(last(as)), :LRP, :attribution, extras)
end

get_activations(model, input) = (input, Flux.activations(model, input)...)
Expand Down
10 changes: 1 addition & 9 deletions test/test_batches.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,12 @@ ANALYZERS = Dict(

for (name, method) in ANALYZERS
@testset "$name" begin
# Using `add_batch_dim=true` should result in same explanation
# as input reshaped to have a batch dimension
analyzer = method(model)
expl1_no_bd = analyzer(input1_no_bd; add_batch_dim=true)
analyzer = method(model)
expl1_bd = analyzer(input1_bd)
@test expl1_bd.val ≈ expl1_no_bd.val

# Analyzing a batch should have the same result
# as analyzing inputs in batch individually
analyzer = method(model)
expl2_bd = analyzer(input2_bd)
analyzer = method(model)
expl_batch = analyzer(input_batch)
@test expl1_bd.val ≈ expl_batch.val[:, 1]
@test expl2_bd.val ≈ expl_batch.val[:, 2]
end
end
Loading