CCIIPLab / GCE-GNN

The source code for "Global Context Enhanced Graph Neural Network for Session-based Recommendation".
125 stars 30 forks source link

Calaulation of loss value #4

Closed caiyongqi closed 3 years ago

caiyongqi commented 3 years ago

loss = model.loss_function(scores, targets - 1) Why is the targets minus 1?

Mikrokosmos1997 commented 3 years ago

Thank you for your interest. We use 0 to pad the sequence and neglect it when we compute the score of each item,

b = self.embedding.weight[1:]  # n_nodes x latent_size
scores = torch.matmul(select, b.transpose(1, 0))

The first score in the score list is corresponding to item 1, while its index is 0. So we use targets - 1 to match the target items with the index of scores.

caiyongqi commented 3 years ago

Thank you for your interest. We use 0 to pad the sequence and neglect it when we compute the score of each item,

b = self.embedding.weight[1:]  # n_nodes x latent_size
scores = torch.matmul(select, b.transpose(1, 0))

The first score in the score list is corresponding to item 1, while its index is 0. So we use targets - 1 to match the target items with the index of scores.

Thank you.