title: How to call reset_states() during training in keras?
body: <p>I have sequential data which is ..</p>
  
  <ul>
  <li>input dim of X are all same</li>
  <li>sequence length of x is different among X</li>
  </ul>
  
  <p>I am using LSTM, so I want to call reset_states for each <code>x</code> data (<code>x1</code> and <code>x2</code>).
  <code>x1</code> and <code>x2</code> are independent data, so I have to reset history of LSTM when I test <code>x2</code> after <code>x1</code>. </p>
  
  <p>My code is here. Should I use <code>stateful</code> option?</p>
  
  <pre><code># input dimension is two
  # but data length is differenct between x1 and y1
  x1 = [[1,2],[3,3],[2,1],[2,4]] # x1 length == 4
  y1 = [2,3,2,1]
  
  x2 = [[3,2], [2,1]] # x2 length == 2
  y2 = [2,4]
  
  input_dim = 2
  max_len = 4 # max(len(x1), len(x2)
  max_y = 4 # y -&gt; (1,2,3,4)
  
  trainX = [x1, x2]
  trainY = [y1, y2]
  
  m = Sequential()
  m.add(LSTM(128, 
        input_shape=(max_len, input_dim),
        activation='tanh', 
        return_sequences=True))
  m.add(TimeDistributed(Dense(max_y, activation='softmax')))
  m.compile(...)
  m.fit(trainX, trainY, nb_epoch=10)
  </code></pre>
  
  <h3>Edited</h3>
  
  <p>I found a stateful LSTM example. But it calls reset_states() every epoch. What I want to do is calling every <code>x</code>.
  <a href="https://github.com/fchollet/keras/blob/aff40d800891799dc9ed765617fcbfa665349d0d/examples/stateful_lstm.py" rel="nofollow noreferrer">https://github.com/fchollet/keras/blob/aff40d800891799dc9ed765617fcbfa665349d0d/examples/stateful_lstm.py</a></p>