(self, inputs, input_length, hidden=None)
return outputs, hidden
Args:
            inputs (Variable, LongTensor): [num_setences, max_seq_len]
            input_length (Variable, LongTensor): [num_sentences]
        Return:
            outputs (Variable): [max_source_length, batch_size, hidden_size]
                - list of all hidden states
            hidden ((tuple of) Variable): [num_layers*num_directions, batch_size, hidden_size]
                - last hidden state
                - (h, c) or h
Args:
            inputs (Variable, LongTensor): [num_setences, max_seq_len]
            input_length (Variable, LongTensor): [num_sentences]
        Return:
            outputs (Variable): [max_source_length, batch_size, hidden_size]
                - list of all hidden states
            hidden ((tuple of) Variable): [num_layers*num_directions, batch_size, hidden_size]
                - last hidden state
                - (h, c) or h
Args : inputs ( Variable LongTensor ) : [ num_setences max_seq_len ] input_length ( Variable LongTensor ) : [ num_sentences ] Return : outputs ( Variable ) : [ max_source_length batch_size hidden_size ] - list of all hidden states hidden (( tuple of ) Variable ) : [ num_layers * num_directions batch_size hidden_size ] - last hidden state - ( h c ) or h
def forward(self, inputs, input_length, hidden=None):
        """
        Args:
            inputs (Variable, LongTensor): [num_setences, max_seq_len]
            input_length (Variable, LongTensor): [num_sentences]
        Return:
            outputs (Variable): [max_source_length, batch_size, hidden_size]
                - list of all hidden states
            hidden ((tuple of) Variable): [num_layers*num_directions, batch_size, hidden_size]
                - last hidden state
                - (h, c) or h
        """
        batch_size, seq_len = inputs.size()

        # Sort in decreasing order of length for pack_padded_sequence()
        input_length_sorted, indices = input_length.sort(descending=True)

        input_length_sorted = input_length_sorted.data.tolist()

        # [num_sentences, max_source_length]
        inputs_sorted = inputs.index_select(0, indices)

        # [num_sentences, max_source_length, embedding_dim]
        embedded = self.embedding(inputs_sorted)

        # batch_first=True
        rnn_input = pack_padded_sequence(embedded, input_length_sorted,
                                            batch_first=self.batch_first)

        hidden = self.init_h(batch_size, hidden=hidden)

        # outputs: [batch, seq_len, hidden_size * num_directions]
        # hidden: [num_layers * num_directions, batch, hidden_size]
        self.rnn.flatten_parameters()
        outputs, hidden = self.rnn(rnn_input, hidden)
        outputs, outputs_lengths = pad_packed_sequence(outputs, batch_first=self.batch_first)

        # Reorder outputs and hidden
        _, inverse_indices = indices.sort()
        outputs = outputs.index_select(0, inverse_indices)

        if self.use_lstm:
            hidden = (hidden[0].index_select(1, inverse_indices),
                        hidden[1].index_select(1, inverse_indices))
        else:
            hidden = hidden.index_select(1, inverse_indices)

        return outputs, hidden
def forward ( self , inputs , input_length , hidden = None ) : batch_size , seq_len = inputs . size ( ) # Sort in decreasing order of length for pack_padded_sequence() input_length_sorted , indices = input_length . sort ( descending = True ) input_length_sorted = input_length_sorted . data . tolist ( ) # [num_sentences, max_source_length] inputs_sorted = inputs . index_select ( 0 , indices ) # [num_sentences, max_source_length, embedding_dim] embedded = self . embedding ( inputs_sorted ) # batch_first=True rnn_input = pack_padded_sequence ( embedded , input_length_sorted , batch_first = self . batch_first ) hidden = self . init_h ( batch_size , hidden = hidden ) # outputs: [batch, seq_len, hidden_size * num_directions] # hidden: [num_layers * num_directions, batch, hidden_size] self . rnn . flatten_parameters ( ) outputs , hidden = self . rnn ( rnn_input , hidden ) outputs , outputs_lengths = pad_packed_sequence ( outputs , batch_first = self . batch_first ) # Reorder outputs and hidden _ , inverse_indices = indices . sort ( ) outputs = outputs . index_select ( 0 , inverse_indices ) if self . use_lstm : hidden = ( hidden [ 0 ] . index_select ( 1 , inverse_indices ) , hidden [ 1 ] . index_select ( 1 , inverse_indices ) ) else : hidden = hidden . index_select ( 1 , inverse_indices ) return outputs , hidden