Skip to content
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

batchseq for sequences of matrices #118

Closed
etpinard opened this issue Aug 22, 2022 · 1 comment · Fixed by #126
Closed

batchseq for sequences of matrices #118

etpinard opened this issue Aug 22, 2022 · 1 comment · Fixed by #126

Comments

@etpinard
Copy link

I find batchseq quite useful to reshape data in preparation for training a recurrent model in Flux.

Unfortunately, looks like batchseq only works for sequences of vectors (i.e.1-feature inputs) not sequences of matrices (multi-feature inputs). Consider

# ex.jl
using MLUtils: batchseq

seqlen = 2

seq_a = [[1, 2, 3] for i in 1:seqlen]
@show seq_a
batched_seq_a = batchseq(seq_a)
@show batched_seq_a

seq_B = [[1 2 3; 4 5 6] for i in 1:seqlen]
@show seq_B
batched_seq_B = batchseq(seq_B)

with MLUtils@v0.2.10 this gives

click here to see results
julia> include("ex.jl")
seq_a = [[1, 2, 3], [1, 2, 3]]
batched_seq_a = [[1, 1], [2, 2], [3, 3]]
seq_B = [[1 2 3; 4 5 6], [1 2 3; 4 5 6]]
ERROR: LoadError: MethodError: no method matching rpad(::Matrix{Int64}, ::Int64, ::Nothing)
Closest candidates are:
  rpad(::Any, ::Integer, ::Union{AbstractChar, AbstractString}) at ~/bin/julia-1.7.2/share/julia/base/strings/util.jl:371
  rpad(::AbstractVector, ::Integer, ::Any) at ~/.julia/dev/MLUtils/src/utils.jl:412
  rpad(::Any, ::Integer) at ~/bin/julia-1.7.2/share/julia/base/strings/util.jl:371
  ...
Stacktrace:
 [1] (::MLUtils.var"#130#135"{Nothing, Int64})(x::Matrix{Int64})
   @ MLUtils ./none:0
 [2] iterate
   @ ./generator.jl:47 [inlined]
 [3] collect
   @ ./array.jl:724 [inlined]
 [4] batchseq (repeats 2 times)
   @ ~/.julia/dev/MLUtils/src/utils.jl:433 [inlined]
 [5] top-level scope
   @ ~/.julia/dev/MLUtils/ex.jl:12
 [6] include(fname::String)
   @ Base.MainInclude ./client.jl:451
 [7] top-level scope
   @ REPL[1]:1
in expression starting at /home/etetreault/.julia/dev/MLUtils/ex.jl:12

  • Is making batchseq work for sequences of matrices something in the plans for MLUtils?
  • Would you be willing to accept a PR that adds this functionality?

Thank you very much!

@CarloLucibello
Copy link
Member

Is the desired behavior the following?
Given an input list xs containing B arrays of size * x Li, where * is common to all arrays and Li can vary,
return a list of length Lmax where the elements have size * x B.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants