(self, inp_seq, eval=False)
return result.view(-1, n_classes)
Generator forward function.
Generator forward function.
Generator forward function .
def forward(self, inp_seq, eval=False):
        """Generator forward function."""
        if eval:
            self.eval()
        else:
            self.train()

        batch_size = inp_seq.size()[0]
        seq_len = inp_seq.size()[1]
        n_classes = self.MLP.hidden_size[-1]
        result = torch.zeros(batch_size, seq_len, n_classes, requires_grad=True)
        if self.use_cuda:
            result = result.cuda()
        hidden = self.Encoder.init_hidden(batch_size)
        if self.has_stack:
            stack = self.Stack.init_stack(batch_size)

        for c in range(seq_len):

            output, hidden, stack = self.forward_step(inp_seq[:, c],
                                                      hidden,
                                                      stack)
            result[:, c, :] = output

        return result.view(-1, n_classes)
def forward ( self , inp_seq , eval = False ) : if eval : self . eval ( ) else : self . train ( ) batch_size = inp_seq . size ( ) [ 0 ] seq_len = inp_seq . size ( ) [ 1 ] n_classes = self . MLP . hidden_size [ - 1 ] result = torch . zeros ( batch_size , seq_len , n_classes , requires_grad = True ) if self . use_cuda : result = result . cuda ( ) hidden = self . Encoder . init_hidden ( batch_size ) if self . has_stack : stack = self . Stack . init_stack ( batch_size ) for c in range ( seq_len ) : output , hidden , stack = self . forward_step ( inp_seq [ : , c ] , hidden , stack ) result [ : , c , : ] = output return result . view ( - 1 , n_classes )