Search code examples
rlstmmxnet

MXNet: sequence length in LSTM in a non-sequence data (R)


My data are not timeseries, but it has sequential properties.

Consider one sample:

data1 = matrix(rnorm(10, 0, 1), nrow = 1)
label1 = rnorm(1, 0, 1)

label1 is a function of the data1, but the data matrix is not a timeseries. I suppose that label is a function of not just one data sample, but more older samples, which are naturally ordered in time (not sampled randomly), in other words, data samples are dependent with one another.

I have a batch of examples, say, 16.

With that I want to understand how I can design an RNN/LSTM model which will memorize all 16 examples from the batch to construct the internal state. I am especially confused with the seq_len parameter, which as I understand is specifically about the length of the timeseries used as an input to a network, which is not case.

Now this piece of code (taken from a timeseries example) only confuses me because I don't see how my task fits in.

rm(symbol)

symbol <- rnn.graph.unroll(seq_len = 5, 
                           num_rnn_layer =  1, 
                           num_hidden = 50,
                           input_size = NULL,
                           num_embed = NULL, 
                           num_decode = 1,
                           masking = F, 
                           loss_output = "linear",
                           dropout = 0.2, 
                           ignore_label = -1,
                           cell_type = "lstm",
                           output_last_state = F,
                           config = "seq-to-one")

graph.viz(symbol, type = "graph", direction = "LR", 
          graph.height.px = 600, graph.width.px = 800)

train.data <- mx.io.arrayiter(
          data = matrix(rnorm(100, 0, 1), ncol = 20)
          , label = rnorm(20, 0, 1)
          , batch.size = 20
          , shuffle = F
                 )

Solution

  • Sure, you can treat them as time steps, and apply LSTM. Also check out this example: https://github.com/apache/incubator-mxnet/tree/master/example/multivariate_time_series as it might be relevant for your case.