ptrblck:

which is not using the last timestep, but the complete sequence.


But I’m taking the output of the second LSTM as _, (x, _) = self.lstmLayer2(x), which according to the docs produces output, (h_n, c_n) that is the output of the last timestep.
The  x = x.view(x.shape[1], x.shape[2]) after the second LSTM was to reshape (seq_len, batch) into (batch, seq_len) to be fed into the dense layer.


Use x = x.permute(2, 0, 1) instead to permute the dimensions.


Yes! I changed the view reshaping before convLayer and lstmLayer1 to permute and that got it working. Thanks a lot!
This works perfectly now :
    def forward(self, x):
        
        # Forming embeddings
        x = self.embeddingLayer(x)
        
        # Convolution and pooling
        x = x.permute(0, 2, 1)
        x = F.relu(self.convLayer(x))
        x = F.max_pool1d(x, kernel_size=pool_length)
        
        # LSTM layers
        x = x.permute(2, 0, 1)
        x = F.dropout(x, p=0.2, training=self.training)
        x, _ = self.lstmLayer1(x)
        x = F.dropout(x, p=0.2, training=self.training)
        _, (x, _) = self.lstmLayer2(x)
        
        # Dense layer
        x = x.view(x.shape[1], x.shape[2])
        x = self.denseLayer(x)
        
        return x

But I can’t understand why view doesn’t work here. What do you mean by interleaving the signal?