def forward(self, input, lengths, return_all=False, pool="last"):
        """Propogate input through the encoder.

        Args:
            input(torch.Tensor): Embedding matrix
            lengths (torch.Tensor): list of sequences lengths of each batch element.
            return_all (bool): Return all or only the last hidden state.
            pool(str): Type of getting hidden state.

        Returns:
            torch.Tensor: Return last or all hidden states.

        """
        embedding = self.src_embedding(input)
        src_emb = pack_padded_sequence(embedding, lengths, batch_first=True)
        if self.rnn_type == "LSTM":
            h, (h_t, _) = self.encoder(src_emb)
        else:
            h, h_t = self.encoder(src_emb)

        # Get hidden state via max-pooling or h_t
        if pool == "last":
            h_t = torch.cat((h_t[-1], h_t[-2]), 1)
        elif pool == "max":
            h_tmp, _ = pad_packed_sequence(h, batch_first=True)
            h_t = torch.max(h_tmp, 1)[0].squeeze()
        else:
            raise ValueError("Pool %s is not valid " % (pool))

        # Return all or only the last hidden state
        if return_all:
            h, _ = pad_packed_sequence(h, batch_first=True)
            return h, h_t
        else:
            return h_t
Propogate input through the encoder.

        Args:
            input(torch.Tensor): Embedding matrix
            lengths (torch.Tensor): list of sequences lengths of each batch element.
            return_all (bool): Return all or only the last hidden state.
            pool(str): Type of getting hidden state.

        Returns:
            torch.Tensor: Return last or all hidden states.

        
utils_nlp/models/gensen/gensen.py