(self, encoder_hidden, conversation_length, hidden=None)
return outputs, hidden
Args:
            encoder_hidden (Variable, FloatTensor): [batch_size, max_len, num_layers * direction * hidden_size]
            conversation_length (Variable, LongTensor): [batch_size]
        Return:
            outputs (Variable): [batch_size, max_seq_len, 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:
            encoder_hidden (Variable, FloatTensor): [batch_size, max_len, num_layers * direction * hidden_size]
            conversation_length (Variable, LongTensor): [batch_size]
        Return:
            outputs (Variable): [batch_size, max_seq_len, 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 : encoder_hidden ( Variable FloatTensor ) : [ batch_size max_len num_layers * direction * hidden_size ] conversation_length ( Variable LongTensor ) : [ batch_size ] Return : outputs ( Variable ) : [ batch_size max_seq_len 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, encoder_hidden, conversation_length, hidden=None):
        """
        Args:
            encoder_hidden (Variable, FloatTensor): [batch_size, max_len, num_layers * direction * hidden_size]
            conversation_length (Variable, LongTensor): [batch_size]
        Return:
            outputs (Variable): [batch_size, max_seq_len, 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, _  = encoder_hidden.size()

        # Sort for PackedSequence
        conv_length_sorted, indices = conversation_length.sort(descending=True)
        conv_length_sorted = conv_length_sorted.data.tolist()
        encoder_hidden_sorted = encoder_hidden.index_select(0, indices)

        rnn_input = pack_padded_sequence(encoder_hidden_sorted, conv_length_sorted, batch_first=True)

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

        self.rnn.flatten_parameters()
        outputs, hidden = self.rnn(rnn_input, hidden)

        # outputs: [batch_size, max_conversation_length, context_size]
        outputs, outputs_length = pad_packed_sequence(outputs, batch_first=True)

        # 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)

        # outputs: [batch, seq_len, hidden_size * num_directions]
        # hidden: [num_layers * num_directions, batch, hidden_size]
        return outputs, hidden
def forward ( self , encoder_hidden , conversation_length , hidden = None ) : batch_size , seq_len , _ = encoder_hidden . size ( ) # Sort for PackedSequence conv_length_sorted , indices = conversation_length . sort ( descending = True ) conv_length_sorted = conv_length_sorted . data . tolist ( ) encoder_hidden_sorted = encoder_hidden . index_select ( 0 , indices ) rnn_input = pack_padded_sequence ( encoder_hidden_sorted , conv_length_sorted , batch_first = True ) hidden = self . init_h ( batch_size , hidden = hidden ) self . rnn . flatten_parameters ( ) outputs , hidden = self . rnn ( rnn_input , hidden ) # outputs: [batch_size, max_conversation_length, context_size] outputs , outputs_length = pad_packed_sequence ( outputs , batch_first = True ) # 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 ) # outputs: [batch, seq_len, hidden_size * num_directions] # hidden: [num_layers * num_directions, batch, hidden_size] return outputs , hidden