What is the best (recommended) way to store sequence data for recurrence models in Flux when it is aimed to be used in ‘batches’? At the moment I store the X data (features) as onehot hot encoded where the features span the rows (as with images) and the data for each step (time unit) spans the columns, eg:
2×8 OneHotMatrix(::Vector{UInt32}) with eltype Bool:
1 1 ⋅ ⋅ ⋅ ⋅ 1 1
⋅ ⋅ 1 1 1 1 ⋅ ⋅
where each row corresponds to a features dimension and each column to the data of a ‘time step’. But I am wondering if this is the advised approach since when using non-recurrence models these columns correspond to separate independent data points. This form makes it a bit cumbersome when using the DataLoader and batches since within each epoch, and within each iteration of the DataLoader batch set, this restructuring has to occur for data ‘x’
x_batch_tt = [Flux.stack([Float32.(x[ii][:,tt]) for ii in 1:length(x)],dims=2) for tt in 1:length(x[1][1,:]) ]
(take each time point ‘tt’ data for each batch ‘ii’ and stack that data into a separate array). Then this means that each element of ‘x_batch_tt’, becomes a matrix where the features for that time tt span rows and the independent sequences for that feature of time tt span columns. I wonder if having to compute this restructuring for each batch sample is wasteful. I also wonder if the original formatting of having the time steps span the columns in the data in the first place is not how it should be done for recurrence data since the columns should be independent samples.
Essentially the data is going from labels (one cold) into an array of 2x8
matrices and being batched into an array of 10
holding 2x8
matrices which I restructure in each iteration (not epoch) to become an array of 8
elements each holding a 2x10
array (the features for the first sequence step across independent sequences) which I loop over.
Can someone please recommend a best practice solution for working with recurrence data that will make the usage of the data in batches simple/straightforward? Is it by using a 3D matrix by any chance?