Skip to content

Commit bd65d33

Browse files
authored
Remove heatmapping functionality (#16)
Move heatmapping on `Explanation` type to VisionHeatmaps.jl and TextHeatmaps.jl via package extensions on XAIBase. This change is breaking: users are now required to manually load either VisionHeatmaps or TextHeatmaps.
1 parent 63d7f60 commit bd65d33

File tree

14 files changed

+31
-252
lines changed

14 files changed

+31
-252
lines changed

Project.toml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
name = "XAIBase"
22
uuid = "9b48221d-a747-4c1b-9860-46a1d8ba24a7"
33
authors = ["Adrian Hill <gh@adrianhill.de>"]
4-
version = "2.0.0"
5-
6-
[deps]
7-
TextHeatmaps = "2dd6718a-6083-4824-b9f7-90e4a57f72d2"
8-
VisionHeatmaps = "27106da1-f8bc-4ca8-8c66-9b8289f1e035"
4+
version = "3.0.0-DEV"
95

106
[compat]
11-
TextHeatmaps = "1.1"
12-
VisionHeatmaps = "1.1"
137
julia = "1.6"

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ In simpler terms, methods that try to answer the question
1212

1313
Building on top of XAIBase (or providing an interface via [package extensions][docs-extensions])
1414
makes your package compatible with the Julia-XAI ecosystem,
15-
allowing you to automatically compute heatmaps for vision and language models.
15+
allowing you to automatically compute heatmaps for vision and language models
16+
using [VisionHeatmaps.jl](https://julia-xai.github.io/XAIDocs/VisionHeatmaps/stable/)
17+
and [TextHeatmaps.jl](https://julia-xai.github.io/XAIDocs/TextHeatmaps/stable/).
1618
It also allows you to use input-augmentations from [ExplainableAI.jl][url-explainableai].
1719

1820
## Interface description

docs/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ ImageIO = "82e4d734-157c-48bb-816b-45c225c6df19"
77
ImageShow = "4e3cecfd-b093-5904-9786-8bbb286a6a31"
88
MLDatasets = "eb30cadb-4394-5ae3-aed4-317e484a6458"
99
Metalhead = "dbeba491-748d-5e0e-a39e-b530a07fa0cc"
10+
VisionHeatmaps = "27106da1-f8bc-4ca8-8c66-9b8289f1e035"
1011
XAIBase = "9b48221d-a747-4c1b-9860-46a1d8ba24a7"
1112
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

docs/src/api.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ The return type of `analyze` is an `Explanation`:
1414
Explanation
1515
```
1616

17-
## Visualizing explanations
18-
`Explanation`s can be visualized using `heatmap`:
19-
```@docs
20-
heatmap
21-
```
22-
2317
## Feature selection
2418
```@docs
2519
AbstractFeatureSelector

docs/src/examples.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,23 @@ function (method::RandomAnalyzer)(input, output_selector::AbstractOutputSelector
4343
end
4444
```
4545

46-
We can directly use XAIBase's `analyze` and `heatmap` functions
47-
to compute and visualize the random explanation:
46+
We can directly use XAIBase's `analyze` function
47+
to compute the random explanation:
4848

4949
```@example implementations
5050
analyzer = RandomAnalyzer(model)
51-
heatmap(input, analyzer)
51+
expl = analyze(input, analyzer)
52+
```
53+
54+
Using either [VisionHeatmaps.jl](https://julia-xai.github.io/XAIDocs/VisionHeatmaps/stable/)
55+
or [TextHeatmaps.jl](https://julia-xai.github.io/XAIDocs/TextHeatmaps/stable/),
56+
which provide package extensions on XAIBase's `Explanation` type,
57+
we can visualize the explanations:
58+
59+
```@example implementations
60+
using VisionHeatmaps # load heatmapping functionality
61+
62+
heatmap(expl.val)
5263
```
5364

5465
As expected, the explanation is just noise.
@@ -81,15 +92,17 @@ end
8192
that works with batched inputs and only requires a single forward
8293
and backward pass through the model.
8394

84-
Once again, we can directly use XAIBase's `analyze` and `heatmap` functions
95+
Once again, we can directly use XAIBase's `analyze` and VisionHeatmaps' `heatmap` functions
8596
```@example implementations
97+
using VisionHeatmaps
98+
8699
analyzer = MyGradient(model)
87100
expl = analyze(input, analyzer)
88-
heatmap(expl)
101+
heatmap(expl.val)
89102
```
90103

91104
```@example implementations
92-
heatmap(expl, colorscheme=:twilight, reduce=:norm, rangescale=:centered)
105+
heatmap(expl.val, colorscheme=:twilight, reduce=:norm, rangescale=:centered)
93106
```
94107

95108
and make use of all the features provided by the Julia-XAI ecosystem.

docs/src/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ in the [Julia-XAI ecosystem](https://julia-xai.github.io/XAIDocs/).
66
Building on top of XAIBase
77
(or providing an interface via [package extensions](https://pkgdocs.julialang.org/v1/creating-packages/#Conditional-loading-of-code-in-packages-(Extensions)))
88
makes your package compatible with the Julia-XAI ecosystem,
9-
allowing you to automatically compute heatmaps for vision and language models.
9+
allowing you to automatically compute heatmaps for vision and language models
10+
using [VisionHeatmaps.jl](https://julia-xai.github.io/XAIDocs/VisionHeatmaps/stable/)
11+
and [TextHeatmaps.jl](https://julia-xai.github.io/XAIDocs/TextHeatmaps/stable/).
1012

1113
This only requires you to fulfill the following two requirements:
1214

src/XAIBase.jl

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
module XAIBase
22

3-
using TextHeatmaps
4-
using VisionHeatmaps
5-
63
include("compat.jl")
74
include("utils.jl")
85

@@ -15,7 +12,8 @@ It is expected that all XAI methods are callable types that return an `Explanati
1512
(method::AbstractXAIMethod)(input, output_selector::AbstractOutputSelector)
1613
```
1714
18-
If this function is implemented, XAIBase will provide the `analyze` and `heatmap` functionality.
15+
If this function is implemented, XAIBase will provide the `analyze` functionality
16+
and `heatmap` functionality by loading either VisionHeatmaps.jl or TextHeatmaps.jl.
1917
"""
2018
abstract type AbstractXAIMethod end
2119

@@ -31,16 +29,12 @@ include("explanation.jl")
3129
# which in turn calls `(method)(input, output_selector)`.
3230
include("analyze.jl")
3331

34-
# Heatmapping for vision and NLP tasks.
35-
include("heatmaps.jl")
36-
3732
# Utilities for XAI methods that compute Explanations w.r.t. specific features:
3833
include("feature_selection.jl")
3934

4035
export AbstractXAIMethod
4136
export Explanation
4237
export analyze
43-
export heatmap
4438
export AbstractOutputSelector, MaxActivationSelector, IndexSelector
4539
export AbstractFeatureSelector, IndexedFeatures, TopNFeatures
4640
end #module

src/analyze.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Apply the analyzer `method` for the given input, returning an [`Explanation`](@r
1212
If `output_selection` is specified, the explanation will be calculated for that output.
1313
Otherwise, the output with the highest activation is automatically chosen.
1414
15-
See also [`Explanation`](@ref) and [`heatmap`](@ref).
15+
See also [`Explanation`](@ref).
1616
1717
## Keyword arguments
1818
- `add_batch_dim`: add batch dimension to the input without allocating. Default is `false`.

src/heatmaps.jl

Lines changed: 0 additions & 135 deletions
This file was deleted.

test/Project.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,3 @@ JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
44
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
55
ReferenceTests = "324d217c-45ce-50fc-942e-d289b448e8cf"
66
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
7-
TextHeatmaps = "2dd6718a-6083-4824-b9f7-90e4a57f72d2"
8-
VisionHeatmaps = "27106da1-f8bc-4ca8-8c66-9b8289f1e035"
9-
10-
[compat]
11-
Aqua = "0.8"

test/runtests.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,4 @@ using JuliaFormatter
2525
@info "Testing feature selection..."
2626
include("test_feature_selection.jl")
2727
end
28-
@testset "Vision heatmaps" begin
29-
@info "Testing vision heatmaps..."
30-
include("test_heatmap.jl")
31-
end
32-
@testset "Text heatmaps" begin
33-
@info "Testing text heatmaps..."
34-
include("test_textheatmap.jl")
35-
end
3628
end

test/test_api.jl

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Create dummy analyzer to test API and heatmapping
1+
# Create dummy analyzer to test API
22
struct DummyAnalyzer <: AbstractXAIMethod end
33
function (method::DummyAnalyzer)(input, output_selector::AbstractOutputSelector)
44
output = input
@@ -38,24 +38,3 @@ expl = analyzer(input, output_index)
3838
# Ouput selection + add_batch_dim
3939
expl = analyzer(input_vec, output_index; add_batch_dim=true)
4040
@test expl.val == val[:, 1:1]
41-
42-
# Test direct heatmapping
43-
input = rand(5, 5, 3, 1)
44-
45-
h1 = heatmap(analyze(input, analyzer))
46-
h2 = heatmap(input, analyzer)
47-
@test h1 == h2
48-
49-
h1 = heatmap(analyze(input, analyzer, 5))
50-
h2 = heatmap(input, analyzer, 5)
51-
@test h1 == h2
52-
53-
input = rand(5, 5, 3)
54-
55-
h1 = heatmap(analyze(input, analyzer; add_batch_dim=true))
56-
h2 = heatmap(input, analyzer; add_batch_dim=true)
57-
@test h1 == h2
58-
59-
h1 = heatmap(analyze(input, analyzer, 5; add_batch_dim=true))
60-
h2 = heatmap(input, analyzer, 5; add_batch_dim=true)
61-
@test h1 == h2

test/test_heatmap.jl

Lines changed: 0 additions & 30 deletions
This file was deleted.

test/test_textheatmap.jl

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)