def calculate_loss(self, interaction):
    user = interaction[self.USER_ID]
    pos_item = interaction[self.ITEM_ID]
    neg_item = interaction[self.NEG_ITEM_ID]
    target = torch.zeros((len(user) * 2), dtype=torch.float32).to(self.device)
    target[:len(user)] = 1
    users = torch.cat((user, user))
    items = torch.cat((pos_item, neg_item))
    (user_e, item_e) = self.forward(users, items)
    predict = torch.mul(user_e, item_e).sum(dim=1)
    rec_loss = self.bce_loss(predict, target)
    ls_loss = self.calculate_ls_loss(users, items, target)
    l2_loss = self.l2_loss(user_e, item_e)
    loss = ((rec_loss + (self.ls_weight * ls_loss)) + (self.reg_weight * l2_loss))
    return loss
def calculate_loss(self, interaction):
    user = interaction[self.USER_ID]
    pos_item = interaction[self.ITEM_ID]
    neg_item = interaction[self.NEG_ITEM_ID]
    target = torch.zeros((len(user) * 2), dtype=torch.float32).to(self.device)
    target[:len(user)] = 1
    users = torch.cat((user, user))
    items = torch.cat((pos_item, neg_item))
    (user_e, item_e) = self.forward(users, items)
    predict = torch.mul(user_e, item_e).sum(dim=1)
    rec_loss = self.bce_loss(predict, target)
    ls_loss = self.calculate_ls_loss(users, items, target)
    l2_loss = self.l2_loss(user_e, item_e)
    loss = ((rec_loss + (self.ls_weight * ls_loss)) + (self.reg_weight * l2_loss))
    return loss