(self, x_emb, dec_logit)
return log_fused_prob
Takes context and decoder logit to perform word embedding fusion
Takes context and decoder logit to perform word embedding fusion
Takes context and decoder logit to perform word embedding fusion
def fuse_prob(self, x_emb, dec_logit):
        ''' Takes context and decoder logit to perform word embedding fusion '''
        # Compute distribution for dec/emb
        if self.fuse_normalize:
            emb_logit = nn.functional.linear(nn.functional.normalize(x_emb, dim=-1),
                                             nn.functional.normalize(self.emb_table.weight, dim=-1))
        else:
            emb_logit = nn.functional.linear(x_emb, self.emb_table.weight)
        emb_prob = (nn.functional.relu(self.temp)*emb_logit).softmax(dim=-1)
        dec_prob = dec_logit.softmax(dim=-1)
        # Mix distribution
        if self.fuse_learnable:
            fused_prob = (1-torch.sigmoid(self.fuse_lambda))*dec_prob +\
                torch.sigmoid(self.fuse_lambda)*emb_prob
        else:
            fused_prob = (1-self.fuse_lambda)*dec_prob + \
                self.fuse_lambda*emb_prob
        # Log-prob
        log_fused_prob = (fused_prob+self.eps).log()

        return log_fused_prob
def fuse_prob ( self , x_emb , dec_logit ) : # Compute distribution for dec/emb if self . fuse_normalize : emb_logit = nn . functional . linear ( nn . functional . normalize ( x_emb , dim = - 1 ) , nn . functional . normalize ( self . emb_table . weight , dim = - 1 ) ) else : emb_logit = nn . functional . linear ( x_emb , self . emb_table . weight ) emb_prob = ( nn . functional . relu ( self . temp ) * emb_logit ) . softmax ( dim = - 1 ) dec_prob = dec_logit . softmax ( dim = - 1 ) # Mix distribution if self . fuse_learnable : fused_prob = ( 1 - torch . sigmoid ( self . fuse_lambda ) ) * dec_prob + torch . sigmoid ( self . fuse_lambda ) * emb_prob else : fused_prob = ( 1 - self . fuse_lambda ) * dec_prob + self . fuse_lambda * emb_prob # Log-prob log_fused_prob = ( fused_prob + self . eps ) . log ( ) return log_fused_prob