def forward(self, node_ids, neighbor_ids, label): node_embedding = self.node_emd(node_ids) neighbor_node_embedding = self.node_emd(neighbor_ids) bias = self.bias_vector.gather(0, neighbor_ids) score = (node_embedding*neighbor_node_embedding).sum(dim=1)+bias loss = (F.binary_cross_entropy_with_logits(score, label)).mean() + \ self.lambda_dis * (l2_loss(node_embedding)+l2_loss(neighbor_node_embedding)+l2_loss(bias)) return loss
def forward(self, node_ids, neighbor_ids, reward): node_embedding = self.node_emd(node_ids) neighbor_node_embedding = self.node_emd(neighbor_ids) bias = self.bias_vector.gather(0, neighbor_ids) score = (node_embedding*neighbor_node_embedding).sum(dim=1)+bias prob = score.sigmoid().clamp(1e-5, 1) loss = -(prob.log()*reward).mean() + self.lambda_gen * (l2_loss(node_embedding)+l2_loss(neighbor_node_embedding)+l2_loss(bias)) return loss
def forward_taxo(self, node_ids, category_ids, label, levels): if self.transform: transforms = F.normalize(self.transforms, p=2, dim=1) # transforms = self.transforms node_embedding = self.node_emd(node_ids).unsqueeze( 1) @ transforms[levels] else: node_embedding = self.node_emd(node_ids) category_embedding = self.taxo_emd(category_ids) bias = self.taxo_bias_vector.gather(0, category_ids) score = (node_embedding.squeeze(1) * category_embedding).sum(dim=1) + bias loss = F.binary_cross_entropy_with_logits( score, label) + self.lamb * (l2_loss(bias)) return loss * self.lambda_taxo
def forward_taxo(self, node_ids, category_ids, reward, levels): if self.transform: transforms = F.normalize(self.transforms, p=2, dim=1) # transforms = self.transforms node_embedding = self.node_emd(node_ids).unsqueeze( 1) @ transforms[levels] else: node_embedding = self.node_emd(node_ids) category_embedding = self.taxo_emd(category_ids) bias = self.taxo_bias_vector.gather(0, category_ids) score = (node_embedding.squeeze(1) * category_embedding).sum(dim=1) + bias prob = score.sigmoid().clamp(1e-5, 1) loss = -(prob.log() * reward).mean() + self.lamb * (l2_loss(bias)) return loss * self.lambda_taxo