Skip to content

Commit 32b6ccd

Browse files
authored
Make XAIBase a direct dependency (#5)
1 parent 7b9d6d1 commit 32b6ccd

File tree

6 files changed

+12
-38
lines changed

6 files changed

+12
-38
lines changed

Project.toml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,19 @@
11
name = "TextHeatmaps"
22
uuid = "2dd6718a-6083-4824-b9f7-90e4a57f72d2"
33
authors = ["Adrian Hill <[email protected]>"]
4-
version = "1.2.0"
4+
version = "1.2.1-DEV"
55

66
[deps]
77
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
88
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
99
Crayons = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
1010
FixedPointNumbers = "53c48c17-4a7d-5ca2-90c5-79b7896eea93"
11-
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
1211
XAIBase = "9b48221d-a747-4c1b-9860-46a1d8ba24a7"
1312

14-
[weakdeps]
15-
XAIBase = "9b48221d-a747-4c1b-9860-46a1d8ba24a7"
16-
17-
[extensions]
18-
TextHeatmapsXAIBaseExt = "XAIBase"
19-
2013
[compat]
2114
ColorSchemes = "3"
2215
Colors = "0.12"
2316
Crayons = "4"
2417
FixedPointNumbers = "0.8"
25-
Requires = "1"
2618
XAIBase = "3"
2719
julia = "1.6"

src/TextHeatmaps.jl

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,10 @@ using Crayons: Crayon
44
using FixedPointNumbers: N0f8
55
using Colors: Colorant, RGB, hex
66
using ColorSchemes: ColorScheme, colorschemes, get, seismic
7-
using Requires: @require
7+
using XAIBase: Explanation, AbstractXAIMethod, analyze
88

99
include("heatmap.jl")
10-
11-
if !isdefined(Base, :get_extension)
12-
using Requires
13-
function __init__()
14-
@require XAIBase = "9b48221d-a747-4c1b-9860-46a1d8ba24a7" include(
15-
"../ext/TextHeatmapsXAIBaseExt.jl"
16-
)
17-
end
18-
end
10+
include("xaibase.jl")
1911

2012
export heatmap
2113

src/heatmap.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
const DEFAULT_COLORSCHEME = seismic
1+
const DEFAULT_COLORSCHEME = :seismic
22
const DEFAULT_RANGESCALE = :centered
3+
const DEFAULT_REDUCE = :sum
34

45
"""
5-
heatmap(values, words)
6+
heatmap(values::AbstractArray, words)
67
78
Create a heatmap of words where the background color of each word is determined by its corresponding value.
89
Arguments `values` and `words` (and optionally `colors`) must have the same size.

ext/TextHeatmapsXAIBaseExt.jl renamed to src/xaibase.jl

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
module TextHeatmapsXAIBaseExt
2-
31
using TextHeatmaps, XAIBase
42

53
struct HeatmapConfig
@@ -8,9 +6,6 @@ struct HeatmapConfig
86
rangescale::Symbol
97
end
108

11-
const DEFAULT_COLORSCHEME = :seismic
12-
const DEFAULT_REDUCE = :sum
13-
const DEFAULT_RANGESCALE = :centered
149
const DEFAULT_HEATMAP_PRESET = HeatmapConfig(
1510
DEFAULT_COLORSCHEME, DEFAULT_REDUCE, DEFAULT_RANGESCALE
1611
)
@@ -37,17 +32,13 @@ function get_heatmapping_config(expl::Explanation; kwargs...)
3732
end
3833

3934
"""
40-
heatmap(explanation, text)
35+
heatmap(expl::Explanation, text)
4136
42-
Visualize [`Explanation`](@ref) from XAIBase as text heatmap.
37+
Visualize `Explanation` from XAIBase as text heatmap.
4338
Text should be a vector containing vectors of strings, one for each input in the batched explanation.
4439
45-
## Keyword arguments
46-
- `colorscheme::Union{ColorScheme,Symbol}`: color scheme from ColorSchemes.jl.
47-
Defaults to `:$DEFAULT_COLORSCHEME`.
48-
- `rangescale::Symbol`: selects how the color channel reduced heatmap is normalized
49-
before the color scheme is applied. Can be either `:extrema` or `:centered`.
50-
Defaults to `:$DEFAULT_RANGESCALE` for use with the default color scheme `:$DEFAULT_COLORSCHEME`.
40+
This will use the default heatmapping style for the given type of explanation.
41+
Defaults can be overridden via keyword arguments.
5142
"""
5243
function TextHeatmaps.heatmap(
5344
expl::Explanation, texts::AbstractVector{<:AbstractVector{<:AbstractString}}; kwargs...
@@ -75,5 +66,3 @@ function TextHeatmaps.heatmap(
7566
)
7667
return heatmap(expl, [text]; kwargs...)
7768
end
78-
79-
end # module

test/runtests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ using JuliaFormatter
2121
@info "Testing heatmaps..."
2222
include("test_heatmap.jl")
2323
end
24-
@testset "XAIBase extension" begin
24+
@testset "XAIBase Explanations" begin
2525
@info "Testing heatmaps on XAIBase explanations..."
26-
include("test_xaibase_ext.jl")
26+
include("test_xaibase.jl")
2727
end
2828
end
File renamed without changes.

0 commit comments

Comments
 (0)