Skip to content

Commit 52c6d1a

Browse files
committed
Improve documentation of analyze and heatmap
1 parent 438ee97 commit 52c6d1a

File tree

5 files changed

+18
-14
lines changed

5 files changed

+18
-14
lines changed

docs/literate/example.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ input = reshape(x, 28, 28, 1, :);
5050

5151
# ## Calling the analyzer
5252
# We can now select an analyzer of our choice
53-
# and call [`analyze`](@ref) to get an `Explanation`:
53+
# and call [`analyze`](@ref) to get an [`Explanation`](@ref):
5454
analyzer = LRP(model)
5555
expl = analyze(input, analyzer);
5656

57-
# This `Explanation` bundles the following data:
57+
# This [`Explanation`](@ref) bundles the following data:
5858
# * `expl.attribution`: the analyzer's attribution
5959
# * `expl.output`: the model output
60-
# * `expl.neuron_selection`: the neuron index of used for the attribution
60+
# * `expl.neuron_selection`: the neuron index used for the attribution
6161
# * `expl.analyzer`: a symbol corresponding the used analyzer, e.g. `:LRP`
6262

6363
# Finally, we can visualize the `Explanation` through [`heatmap`](@ref):

docs/src/api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
All methods in ExplainableAI.jl work by calling `analyze` on an input and an analyzer:
33
```@docs
44
analyze
5+
Explanation
56
heatmap
67
```
78

src/ExplainableAI.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ include("preprocessing.jl")
3636
export analyze
3737

3838
# Analyzers
39-
export AbstractXAIMethod
39+
export AbstractXAIMethod, Explanation
4040
export Gradient, InputTimesGradient
4141
export NoiseAugmentation, SmoothGrad
4242
export InterpolationAugmentation, IntegratedGradients

src/analyze_api.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const BATCHDIM_MISSING = ArgumentError(
1111
analyze(input, method)
1212
analyze(input, method, neuron_selection)
1313
14-
Return raw classifier output and explanation.
14+
Return an [`Explanation`](@ref) containing the attribution and the raw classifier output.
1515
If `neuron_selection` is specified, the explanation will be calculated for that neuron.
1616
Otherwise, the output neuron with the highest activation is automatically chosen.
1717
@@ -57,10 +57,15 @@ function _analyze(
5757
return method(input, sel; kwargs...)
5858
end
5959

60-
# for convenience, the anaylyzer can be called directly
60+
"""
61+
Return type of analyzers when calling `analyze`.
6162
62-
# Explanations and outputs are returned in a wrapper.
63-
# Metadata such as the analyzer allows dispatching on functions like `heatmap`.
63+
Contains:
64+
* `attribution`: the analyzer's attribution
65+
* `output`: the model output
66+
* `neuron_selection`: the neuron index used for the attribution
67+
* `analyzer`: a symbol corresponding the used analyzer, e.g. `:LRP`
68+
"""
6469
struct Explanation{A,O,I,L}
6570
attribution::A
6671
output::O

src/heatmap.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ const HEATMAPPING_PRESETS = Dict{Symbol,Tuple{ColorScheme,Symbol,Symbol}}(
88
)
99

1010
"""
11-
heatmap(expl::Explanation; kwargs...)
12-
heatmap(attr::AbstractArray; kwargs...)
13-
14-
heatmap(input, analyzer::AbstractXAIMethod)
15-
heatmap(input, analyzer::AbstractXAIMethod, neuron_selection::Int)
11+
heatmap(explanation)
12+
heatmap(input, analyzer)
13+
heatmap(input, analyzer, neuron_selection)
1614
1715
Visualize explanation.
1816
Assumes Flux's WHCN convention (width, height, color channels, batch size).
@@ -37,7 +35,7 @@ Assumes Flux's WHCN convention (width, height, color channels, batch size).
3735
- `unpack_singleton::Bool`: When heatmapping a batch with a single sample, setting `unpack_singleton=true`
3836
will return an image instead of an Vector containing a single image.
3937
40-
**Note:** these keyword arguments can't be used when calling `heatmap` with an analyzer.
38+
**Note:** keyword arguments can't be used when calling `heatmap` with an analyzer.
4139
"""
4240
function heatmap(
4341
attr::AbstractArray{T,N};

0 commit comments

Comments
 (0)