I'm trying to implement a stateful LSTM in Tensorflow.
This is a related question TensorFlow: Remember LSTM state for next batch (stateful LSTM)
When I print out the hidden state h, it does update on each iteration. However, the neural net is not learning anything (even though it was learning when I was passing the entire dataset to the neural net).
Any suggestion regarding what's going on?
lstm = tf.contrib.rnn.BasicLSTMCell(sizes[0], state_is_tuple=True)
lstm2 = tf.contrib.rnn.BasicLSTMCell(sizes[1],state_is_tuple=True)
stacked_lstm = tf.nn.rnn_cell.MultiRNNCell([lstm, lstm2])
hidden_state_in = stacked_lstm.zero_state(48, tf.float32)
output, state = tf.nn.dynamic_rnn(stacked_lstm, x, initial_state=hidden_state_in)
with tf.Session() as sess:
for ep in range(0, epochs):
t=0
all_ll = []
while t < len(df_x)-48:
dx = df_x[t:t+48]
dy = df_y[t:t+48]
if t == 0:
h = sess.run(hidden_state_in)
_, out, ll, hidden_state = sess.run([train_op, p, loss, state],
feed_dict={hidden_state_in: h,
x: np.reshape(dx, (-1, timestep, feat)),
Y: np.reshape(dy, (-1, timestep))})
else:
_, out, ll, hidden_state = sess.run([train_op, p, loss, state],
feed_dict={hidden_state_in: hidden_state,
x: np.reshape(dx, (-1, timestep, feat)),
Y: np.reshape(dy, (-1, timestep))})