-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
return OneHotArray on proper reshape? #30
Comments
The discussion is at FluxML/Flux.jl#1459. Some arguments were made in favor of allowing arbitrary reshaping, so we went with the ReshapedArray thing. I wonder how problematic type instability would be instead. |
The reshape there is implementing a particular multiplication, but looks like it could implement anything. A possible solution is to specify what it's doing at a higher level, and overload that operation for OneHotArray. Is this the right operation? https://juliamath.github.io/TensorCore.jl/dev/#TensorCore.boxdot |
Yes, \boxdot is the right operation. |
OneHotArrays.jl already has a solution for this: to dispatch on I suspect the downstream issue is caused by an outdated Flux (<0.13.7) before FluxML/Flux.jl#2084. Previously, Flux's julia> oh = Flux.onehotbatch(rand('a':'b', (3, 2)), 'a':'b')
2×3×2 OneHotArray(::Matrix{UInt32}) with eltype Bool:
[:, :, 1] =
1 0 0
0 1 1
[:, :, 2] =
0 0 0
1 1 1
julia> x = reshape(oh, 2, :)
2×6 reshape(OneHotArray(::Matrix{UInt32}), 2, 6) with eltype Bool:
1 ⋅ ⋅ ⋅ ⋅ ⋅
⋅ 1 1 1 1 1
julia> x isa AbstractMatrix{Bool}
true
julia> m = Embedding(2, 2)
Embedding(2 => 2) # 4 parameters
julia> m(x)
2×6 Matrix{Float32}:
-0.425469 -0.976092 -0.976092 -0.976092 -0.976092 -0.976092
0.770382 -0.165354 -0.165354 -0.165354 -0.165354 -0.165354 |
Right now a reshape of a OneHotArray that preserves the first dimension doesn't return a OneHotArray:
It would be convenient to return onehotarrays in that case, for convenience and in order to avoid downstream such as
FluxML/Flux.jl#2160.
If we want to do this we have two options:
I remember we already had a discussion on
reshape
somewhere, but maybe worth revisiting.The text was updated successfully, but these errors were encountered: