Evaluate variable-length input array RNN in Julia Flux

HerAdri
Thu, 09 Jun 2022 07:51:55 +0000
General Usage

How to create a vector of a matrice for variable sequence length data to evaluate untrained RNN?
Following the idea developed in these [link1, link2] it is possible to carry out the evaluation for a vector;

using Flux

simple_rnn = Flux.RNN(1, 1, (x -> x))

#simple_rnn.([1, 2, 3])

v = Vector{Vector{Float32}}([[1], [2], [3]])

simple_rnn.(v)

v=[2,4,5,6]

vv=[Vector{Float32}([i]) for i in v]

simple_rnn.(vv)

seq = [Vector{Float32}([i]) for i = rand(10)]

simple_rnn.(seq)

but for the matrix for variable sequence length data, I get the following alert:

julia> b=[[1, 2, 3],[2,4,5,6],[6.0, 7.0, 7.0, 10.0, 7.0, 8.0]]
3-element Vector{Vector{Float64}}:
[1.0, 2.0, 3.0]
[2.0, 4.0, 5.0, 6.0]
[6.0, 7.0, 7.0, 10.0, 7.0, 8.0]

julia> c=[[Vector{Float32}([j]) for j in i] for i in b]
3-element Vector{Vector{Vector{Float32}}}:
[[1.0], [2.0], [3.0]]
[[2.0], [4.0], [5.0], [6.0]]
[[6.0], [7.0], [7.0], [10.0], [7.0], [8.0]]

simple_rnn.(c)
ERROR: MethodError: no method matching (::Flux.RNNCell{var"#5#6", Matrix{Float32}, Vector{Float32}, Matrix{Float32}})(::
Matrix{Float32}, ::Vector{Vector{Float32}})
Closest candidates are:
 (::Flux.RNNCell{F, A, V, <:AbstractMatrix{T}})(::Any, ::Union{AbstractMatrix{T}, AbstractVector{T}, Flux.OneHotArray})
where {F, A, V, T} at C:\Users\Hermesr\.julia\packages\Flux\js6mP\src\layers\recurrent.jl:138
Stacktrace:
[1] (::Flux.Recur{Flux.RNNCell{var"#5#6", Matrix{Float32}, Vector{Float32}, Matrix{Float32}}, Matrix{Float32}})(x::Vect
or{Vector{Float32}})
. . .

[7] top-level scope
 @ REPL[24]:1
[8] top-level scope
 @ C:\Users\Hermesr\.julia\packages\CUDA\qAl31\src\initialization.jl:52

If the solution is possible by correctly interpreting the error alert shown by Julia. I would be very grateful if you could enlighten me!!!

5 posts - 2 participants