weiyinwei / MMGCN

MMGCN: Multi-modal Graph Convolution Network forPersonalized Recommendation of Micro-video
286 stars 53 forks source link

关于Model_MMGCN.py 里的Net类中loss的计算方法 #50

Open hyc9 opened 2 years ago

hyc9 commented 2 years ago

您好!在运行您的代码时,我发现在Net类的loss函数中:

def loss(self, user_tensor, item_tensor) :
        user_tensor = user_tensor.view(-1)
        item_tensor = item_tensor.view(-1)
        out = self.forward()
        user_score = out[user_tensor]     
        item_score = out[item_tensor]       # Here
        score = torch.sum(user_score*item_score, dim=1).view(-1, 2)
        loss = -torch.mean(torch.log(torch.sigmoid(torch.matmul(score, self.weight))))
        reg_embedding_loss = (self.id_embedding[user_tensor]**2 + self.id_embedding[item_tensor]**2).mean()+(self.v_gcn.preference**2).mean()
        reg_loss = self.reg_weight * (reg_embedding_loss)
        return loss+reg_loss, reg_loss, loss, reg_embedding_loss, reg_embedding_loss

从仓库中提供的movielens sample数据集来看,#user = 100, #item = 1141, 故out.shape[0]是1241. 然而在代码的dataset写法中,并没有对positive item的index做特殊处理,即范围仍是[0, 1140] , 所以在如上的loss函数中,user[0]和positive item[0]对应着相同的embedding, 此处是否有问题呢?感谢您的回复!

weiyinwei commented 2 years ago

您好,感谢您对于我们工作的关注。我们对于user和item是统一编码的,也就是说item是从num_user开始进行编号的。不过对于toy dataset,我并没有单独进行处理。