Skip to content

Commit f8e7548

Browse files
committed
using OneHotArrays.jl
1 parent eccfd6b commit f8e7548

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

docs/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
44
Functors = "d9f16b24-f501-4c13-a1f2-28368ffc5196"
55
MLUtils = "f1d291b0-491e-4a28-83b9-f70985020b54"
66
NNlib = "872c559c-99b0-510c-b3b7-b6c96a88d5cd"
7+
OneHotArrays = "0b1bfda6-eb8a-41d2-88d8-f5af5cad476f"
78
Optimisers = "3bd65402-5787-11e9-1adc-39752487f4e2"
89

910
[compat]

docs/make.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
using Documenter, Flux, NNlib, Functors, MLUtils, BSON, Optimisers
1+
using Documenter, Flux, NNlib, Functors, MLUtils, BSON, Optimisers, OneHotArrays
22

33

44
DocMeta.setdocmeta!(Flux, :DocTestSetup, :(using Flux); recursive = true)
55

66
makedocs(
7-
modules = [Flux, NNlib, Functors, MLUtils, BSON, Optimisers],
7+
modules = [Flux, NNlib, Functors, MLUtils, BSON, Optimisers, OneHotArrays],
88
doctest = false,
99
sitename = "Flux",
1010
strict = [:cross_references],

docs/src/data/onehot.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# One-Hot Encoding
1+
# One-Hot Encoding with OneHotArrays.jl
22

3-
It's common to encode categorical variables (like `true`, `false` or `cat`, `dog`) in "one-of-k" or ["one-hot"](https://en.wikipedia.org/wiki/One-hot) form. Flux provides the `onehot` function to make this easy.
3+
It's common to encode categorical variables (like `true`, `false` or `cat`, `dog`) in "one-of-k" or ["one-hot"](https://en.wikipedia.org/wiki/One-hot) form. [OneHotArrays.jl](https://github.com/FluxML/OneHotArrays.jl) provides the `onehot` function to make this easy.
44

55
```jldoctest onehot
6-
julia> using Flux: onehot, onecold
6+
julia> using OneHotArrays
77
88
julia> onehot(:b, [:a, :b, :c])
99
3-element OneHotVector(::UInt32) with eltype Bool:
@@ -34,7 +34,7 @@ julia> onecold([0.3, 0.2, 0.5], [:a, :b, :c])
3434
For multiple samples at once, `onehotbatch` creates a batch (matrix) of one-hot vectors, and `onecold` treats matrices as batches.
3535

3636
```jldoctest onehot
37-
julia> using Flux: onehotbatch
37+
julia> using OneHotArrays
3838
3939
julia> onehotbatch([:b, :a, :b], [:a, :b, :c])
4040
3×3 OneHotMatrix(::Vector{UInt32}) with eltype Bool:
@@ -52,7 +52,9 @@ julia> onecold(ans, [:a, :b, :c])
5252
Note that these operations returned `OneHotVector` and `OneHotMatrix` rather than `Array`s. `OneHotVector`s behave like normal vectors but avoid any unnecessary cost compared to using an integer index directly. For example, multiplying a matrix with a one-hot vector simply slices out the relevant row of the matrix under the hood.
5353

5454
```@docs
55-
Flux.onehot
56-
Flux.onecold
57-
Flux.onehotbatch
55+
OneHotArrays.onehot
56+
OneHotArrays.onecold
57+
OneHotArrays.onehotbatch
58+
OneHotArrays.OneHotVector
59+
OneHotArrays.OneHotMatrix
5860
```

src/layers/basic.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ for a vocabulary of size `in`.
651651
652652
This layer is often used to store word embeddings and retrieve them using indices.
653653
The input to the layer can be either a vector of indexes
654-
or the corresponding [`onehot encoding`](@ref Flux.onehotbatch).
654+
or the corresponding [`onehot encoding`](@ref OneHotArrays.onehotbatch).
655655
656656
# Examples
657657
```jldoctest

0 commit comments

Comments
 (0)