[docs]classBPRLoss(nn.Module):"""BPRLoss, based on Bayesian Personalized Ranking Args: - gamma(float): Small value to avoid division by zero Shape: - Pos_score: (N) - Neg_score: (N), same shape as the Pos_score - Output: scalar. Examples:: >>> loss = BPRLoss() >>> pos_score = torch.randn(3, requires_grad=True) >>> neg_score = torch.randn(3, requires_grad=True) >>> output = loss(pos_score, neg_score) >>> output.backward() """def__init__(self,gamma=1e-10):super(BPRLoss,self).__init__()self.gamma=gamma
[docs]classEmbMarginLoss(nn.Module):"""EmbMarginLoss, regularization on embeddings"""def__init__(self,power=2):super(EmbMarginLoss,self).__init__()self.power=power