12

The dimensions for the input data for LSTM are [Batch Size, Sequence Length, Input Dimension] in tensorflow.

  1. What is the meaning of Sequence Length & Input Dimension ?
  2. How do we assign the values to them if my input data is of the form : [[[1.23] [2.24] [5.68] [9.54] [6.90] [7.74] [3.26]]] ?
Stuti Kalra
  • 133
  • 1
  • 1
  • 6

2 Answers2

19

LSTMs are a subclass of recurrent neural networks. Recurrent neural nets are by definition applied on sequential data, which without loss of generality means data samples that change over a time axis. A full history of a data sample is then described by the sample values over a finite time window, i.e. if your data live in an N-dimensional space and evolve over t-time steps, your input representation must be of shape (num_samples, t, N).

Your data does not fit the above description. I assume, however, that this representation means you have a scalar value x which evolves over 7 time instances, such that x[0] = 1.23, x[1] = 2.24, etc.

If that is the case, you need to reshape your input such that instead of a list of 7 elements, you have an array of shape (7,1). Then, your full data can be described by a 3rd order tensor of shape (num_samples, 7, 1) which can be accepted by a LSTM.

KonstantinosKokos
  • 3,369
  • 1
  • 11
  • 21
0

Simply put seq_len is number of time steps that will be inputted into LSTM network, Let's understand this by example... Suppose you are doing a sentiment classification using LSTM. Your input sentence to the network is =["I hate to eat apples"]. Every single token would be fed as input at each timestep, So accordingly here the seq_Len would total number of tokens in a sentence that is 5. Coming to the input_dim you might know we can't directly feed words to the netowrk you would need to encode those words into numbers. In Pytorch/tensorflow embedding layers are used where we have to specify embedding dimension. Suppose your embedding dimension is 50 that means that embedding layer will take index of respective token and convert it into vector representation of size 50. So the input dim to LSTM network would become 50.