I have this configuration of my encoder :
-
class Encoder_LSTM(nn.Module):
-
def __init__(self,dict_config = dict_config):
-
super(Encoder_LSTM, self).__init__()
-
self.input_size = dict_config["input_dim"]
-
self.hidden_size = dict_config["hid_dim"]
-
self.output_size = dict_config["output_dim"]
-
self.num_layer = dict_config["num_layer"]
-
self.Encoder_LSTM = nn.LSTM(self.input_size, self.hidden_size , batch_first=True , num_layers=self.num_layer , dropout=0.2 )
-
def forward(self, input):
-
self.batch_size = input.shape[0]
-
self.hidden_init = torch.zeros(self.num_layer, self.batch_size, self.hidden_size, device=device)
-
self.h_0 = self.hidden_init
-
self.c_0 = self.hidden_init
-
self.output, (h,c) = self.Encoder_LSTM(input, (self.h_0, self.c_0))
-
return self.output
I think I am a bit confused about the “forward” method. It seems like every time you call it, it initialize the hid_state/cell_state. Now, I was wandering , when you have a sequence , is the forward method call on each timestep? If yes, wouldn’t it mean that for each time step the hid_state/cell_state are reset ?