Reputation: 12689
I am trying to learn LSTM and i have one confusion , if i have a list of words like :
vocabulary=['hello','how','are','you','tell','me','something','about','yourself']
Now i want to give one input :
ex : input_data = ['hello']
and i want it should predict next three words :
ex : output_data = ['how','are','you']
So i want to train LSTM by choosing randomly 4 words and then chunk that list of words as 1 as input and rest 3 as output.
Let's take simple one example :
ex : input_data = ['hello']
ex : output_data = ['how','are','you']
after converting them into one hot :
final_input=[]
for i in x_data:
matrix = [0] * len(main_vocabulary)
matrix[main_vocabulary.index(i)]=1
final_input.append(matrix)
output=[main_vocabulary.index(i) for i in y_data]
print(final_input)
print(output)
:
[[1, 0, 0, 0, 0, 0, 0, 0, 0]]
[1, 2, 3]
Now my confusion is how to feed this format to LSTM ?
Because i have read LSTM input and output vector shape should be same , is it True ?
input_placeholder=tf.placeholder(tf.float32,[None,1,9])
output_placeholder=tf.placeholder(tf.int32,[None,3])
But i don't think this is correct , How to feed please suggest.
And what would be number of num_units in rnn.BasicLSTMCell(num_units=?,state_is_tuple=True)
what i am thinking yet that num_units should be same as column of data so here it should be 9 .
Upvotes: 1
Views: 849
Reputation: 761
Conceptually, the simplest method would be a sequence to sequence RNN. It should be possible to use a plain RNN as well, though variable lengths on both the input and output would be fiddly to program (if you want to change them in the future).
Have a look at http://karpathy.github.io/2015/05/21/rnn-effectiveness/ (the standard RNN intro blog - I'm sure you've seen this before) and pay attention to the diagram illustrating the various types of RNN. You want a one-to-many configuration.
To be honest, it sounds like you may be a little in over your head. I'd suggest trying to understand the fundamentals of RNNs by studying https://github.com/guillaume-chevalier/seq2seq-signal-prediction
Upvotes: 1