(self, inputs, init_h=None, encoder_outputs=None, input_valid_length=None,
                decode=False)
Train (decode=False)
            Args:
                inputs (Variable, LongTensor): [batch_size, seq_len]
                init_h: (Variable, FloatTensor): [num_layers, batch_size, hidden_size]
            Return:
                out   : [batch_size, seq_len, vocab_size]
        Test (decode=True)
            Args:
                inputs: None
                init_h: (Variable, FloatTensor): [num_layers, batch_size, hidden_size]
            Return:
                out   : [batch_size, seq_len]
Train (decode=False)
            Args:
                inputs (Variable, LongTensor): [batch_size, seq_len]
                init_h: (Variable, FloatTensor): [num_layers, batch_size, hidden_size]
            Return:
                out   : [batch_size, seq_len, vocab_size]
        Test (decode=True)
            Args:
                inputs: None
                init_h: (Variable, FloatTensor): [num_layers, batch_size, hidden_size]
            Return:
                out   : [batch_size, seq_len]
Train ( decode = False ) Args : inputs ( Variable LongTensor ) : [ batch_size seq_len ] init_h : ( Variable FloatTensor ) : [ num_layers batch_size hidden_size ] Return : out : [ batch_size seq_len vocab_size ] Test ( decode = True ) Args : inputs : None init_h : ( Variable FloatTensor ) : [ num_layers batch_size hidden_size ] Return : out : [ batch_size seq_len ]
def forward(self, inputs, init_h=None, encoder_outputs=None, input_valid_length=None,
                decode=False):
        """
        Train (decode=False)
            Args:
                inputs (Variable, LongTensor): [batch_size, seq_len]
                init_h: (Variable, FloatTensor): [num_layers, batch_size, hidden_size]
            Return:
                out   : [batch_size, seq_len, vocab_size]
        Test (decode=True)
            Args:
                inputs: None
                init_h: (Variable, FloatTensor): [num_layers, batch_size, hidden_size]
            Return:
                out   : [batch_size, seq_len]
        """
        batch_size = self.batch_size(inputs, init_h)

        # x: [batch_size]
        x = self.init_token(batch_size, SOS_ID)

        # h: [num_layers, batch_size, hidden_size]
        h = self.init_h(batch_size, hidden=init_h)


        if not decode:
            out_list = []
            seq_len = inputs.size(1)
            for i in range(seq_len):

                # x: [batch_size]
                # =>
                # out: [batch_size, vocab_size]
                # h: [num_layers, batch_size, hidden_size] (h and c from all layers)
                out, h = self.forward_step(x, h)

                out_list.append(out)
                x = inputs[:, i]

            # [batch_size, max_target_len, vocab_size]
            return torch.stack(out_list, dim=1)
        else:
            x_list = []
            for i in range(self.max_unroll):

                # x: [batch_size]
                # =>
                # out: [batch_size, vocab_size]
                # h: [num_layers, batch_size, hidden_size] (h and c from all layers)
                out, h = self.forward_step(x, h)

                # out: [batch_size, vocab_size]
                # => x: [batch_size]
                x = self.decode(out)
                x_list.append(x)

            # [batch_size, max_target_len]
            return torch.stack(x_list, dim=1)
def forward ( self , inputs , init_h = None , encoder_outputs = None , input_valid_length = None , decode = False ) : batch_size = self . batch_size ( inputs , init_h ) # x: [batch_size] x = self . init_token ( batch_size , SOS_ID ) # h: [num_layers, batch_size, hidden_size] h = self . init_h ( batch_size , hidden = init_h ) if not decode : out_list = [ ] seq_len = inputs . size ( 1 ) for i in range ( seq_len ) : # x: [batch_size] # => # out: [batch_size, vocab_size] # h: [num_layers, batch_size, hidden_size] (h and c from all layers) out , h = self . forward_step ( x , h ) out_list . append ( out ) x = inputs [ : , i ] # [batch_size, max_target_len, vocab_size] return torch . stack ( out_list , dim = 1 ) else : x_list = [ ] for i in range ( self . max_unroll ) : # x: [batch_size] # => # out: [batch_size, vocab_size] # h: [num_layers, batch_size, hidden_size] (h and c from all layers) out , h = self . forward_step ( x , h ) # out: [batch_size, vocab_size] # => x: [batch_size] x = self . decode ( out ) x_list . append ( x ) # [batch_size, max_target_len] return torch . stack ( x_list , dim = 1 )