ok I understand. In your example, you initialize the hidden and cell states. But do you know the default behaviour of the LSTM layer? Does it keep the hidden and cell states between batches by default? For instance,
After running: LSTM.forward(batch1), will the hidden and cell states be saved in the model, so that they will be used as initial hidden states in: LSTM.forward(batch2)? Is this the default behaviour?
If this is the default behaviour, then when we want to reset hidden states between batches, we need to set hidden, cell = 0 in model forward definition. If this is not the default behaviour, then when we want to remember hidden states between batches, we need to store the last step hidden states from previous batch and apply them as initial hidden state values in the current batch.