LSTM model implementation in PyTorch
I was trying to implement CNN+LSTM model in PyTorch, but I have problem with LSTM part (I never used LSTM before). Could you write Many-to-one-LSTM model class (Image-link: https://i.ibb.co/SRGWT5j/lstm.png  )...

For nn.LSTM in Pytorch , as per docs https://pytorch.org/docs/stable/nn.html?highlight=lstm#torch.nn.LSTM

it takes input as (embedding_size_dimension , hidden_size_dimension , number_of_layers)
(currently ignoring bidirectional parameter , we can also pass initial hidden_state and cell_state )

so we need to pass a tensor of shape [max sentence length , batch size , embedding size ]

just a sample model

class Model(nn.Module):
    def __init__(self, vocab_size, output_size, embedding_dim, hidden_dim, n_layers, drop_prob=0.5):
        super(Model, self).__init__()
        self.output_size = output_size
        self.n_layers = n_layers
        self.hidden_dim = hidden_dim

        self.embedding = nn.Embedding(vocab_size, embedding_dim)
        self.lstm = nn.LSTM(embedding_dim, hidden_dim, n_layers, dropout=drop_prob)

    def forward(self, sentence):
        batch_size = sentence.size(0)
        sentence = sentence.long()
        embeds = self.embedding(sentence)
        lstm_out, hidden = self.lstm(embeds)
        # so here lstm_out will be of [max sentence length , batch size , hidden size]
        # so for simple many-to-one we can just use output of last cell of LSTM
        out = lstm_out[-1,:,:]
        return out


You can refer this link , is has really nicely explained about LSTM in pytorch , it also has one sample example of SentimentNet model

https://blog.floydhub.com/long-short-term-memory-from-zero-to-hero-with-pytorch/
