title: Can I split my long sequences into 3 smaller ones and use a stateful LSTM for 3 samples?
body: <p>I am doing a time-series sequence classification problem.</p>
  <p>I have 80 time-series all length 1002. Each seq corresponds to 1 of 4 categories (copper, cadmium, lead, mercury). I want to use Keras LSTMs to model this. These models require data to be fed in the form <code>[batches, timesteps, features]</code>. As each seq is independent, the most basic setup is for <code>X_train</code> to have shape <code>[80, 1002, 1]</code>. This works fine in an LSTM (with <code>stateful=False</code>)</p>
  <p>But, 1002 is quite a long seq length. A smaller size could perform better.</p>
  <p>Let's say I split each seq up into 3 parts of 334. I could continue to use a stateless LSTM. But (I think?) it makes sense to have it be stateful for 3 samples and then reset state (since the 3 chunks are related).</p>
  <p>How do I implement this in Keras?</p>
  <p>First, I transform the data into shape <code>[240, 334, 1]</code> using a simple <code>X_train.reshape(-1, 334, 1)</code> but how do I maintain the state for 3 samples and then reset the state in <code>model.fit()</code>?</p>
  <p>I know I need to call <code>model.reset_states()</code> somewhere but couldn't find any sample code out there showing me how to work it. Do I have to subclass a model? Can I do this using <code>for epoch in range(num_epochs)</code> and <code>GradientTape</code>? What are my options? How can I implement this?</p>
  <p>Also, if I split the sequences up, what do I do with the labels? Do I multiply them by the number of chunks each seq is split up into (3 in this case)? Is there a way for an LSTM to ingest 3 samples and then spit out one prediction? Or does each sample have to correspond to a prediction?</p>
  <p>Finally, if I split my sequences up into 3 subsequences, do I have to have a batch size of 3? Or can I choose any multiple of 3?</p>
  <p>Here is the super basic code I used with <code>X_train.shape == [80, 1002, 1]</code>.</p>
  <pre class="lang-py prettyprint-override"><code>model = Sequential([
      LSTM(10, batch_input_shape=(10, 1002, 1)), # 10 samples per batch
      Dense(4, activation='sigmoid')
  ])
  model.compile(loss='categorical_crossentropy',
               optimizer='rmsprop',
               metrics=['accuracy'])
  model.fit(X_train, y_train, epochs=3, batch_size=10, shuffle=False)
  </code></pre>
  <p>I know there are loads of questions here, happy to make separate ones if this is too much for one.</p>