(self, x, y=None)
return outputs
Compute the loss, and optionally the scores.
Compute the loss, and optionally the scores.
Compute the loss and optionally the scores .
def forward(self, x, y=None):
        """ Compute the loss, and optionally the scores.
        """
        outputs = ()
        if self.asm is False:
            scores = self.proj(x)
            outputs = (scores,) + outputs
            if y is not None:
                loss = F.cross_entropy(scores.view(-1, self.n_words), y.view(-1), reduction='elementwise_mean')
                outputs = (loss,) + outputs
        else:
            scores = self.proj.log_prob(x)
            outputs = (scores,) + outputs
            if y is not None:
                _, loss = self.proj(x, y)
                outputs = (loss,) + outputs

        return outputs
def forward ( self , x , y = None ) : outputs = ( ) if self . asm is False : scores = self . proj ( x ) outputs = ( scores , ) + outputs if y is not None : loss = F . cross_entropy ( scores . view ( - 1 , self . n_words ) , y . view ( - 1 ) , reduction = 'elementwise_mean' ) outputs = ( loss , ) + outputs else : scores = self . proj . log_prob ( x ) outputs = ( scores , ) + outputs if y is not None : _ , loss = self . proj ( x , y ) outputs = ( loss , ) + outputs return outputs