Pytorch's lstm states

Hello everyone. I hope that you all are ok. I am a beginner to deep learning and, i have some questions.
1- Does a lstm reset his hidden state for each sequence in a batch ?
2- What is sliding windows technique and when should i use it with lstm ?

By default, yes. This means that the LSTM layer will initialize the hidden state if you don’t pass any as input. For example, say you define in your model self.lstm = LSTM(...), and in your forward() method you call:

out, (h, c) = self.lstm(inputs)

then the initialization is done automatically. However, you can also pass your own initial hidden state like:

out, (h, c) = self.lstm(inputs, (h, c))

In which case it’s up to you where those come from. Those can come from the last batch or from your own initialization.

I don’t think, there’s a single clear answer and most likely will depend on you concrete task. The common alternatives are obviously overlapping and non-overlapping windows. Overlapping seems to be the more intuitive choice to me, but I have nothing to back this up.

Thank you very much sir for answering to my questions :blush:. Do you know if pytorch lstm can use the last hidden state generated as initial hidden state for the next sequence in the batch ?
I mean a way to do it automatically.