recpack.algorithms.loss_functions.top1_loss
- recpack.algorithms.loss_functions.top1_loss(positive_scores: torch.Tensor, negative_scores: torch.Tensor) torch.Tensor
TOP1 Loss.
This is a pairwise loss function similar to BPR loss, but with an added score regularization term. It was devised specifically for use with the Session RNN. It can be defined as:
\[L_{top1} = \frac{1}{N_S} \sum\limits_{j=1}^{N_S} \sigma(r_j - r_i) + \sigma(r_j^2)\]where \(N_S\) is the number of negative samples, \(r_i\) is the target score and \(r_j\) is the score given to the sampled negative item.
See the 2016 paper “Session-based Recommendations with Recurrent Neural Networks” by Hidasi et al. for the motivation behind using it for top-k recommendations.
- Parameters
positive_scores (torch.Tensor) – Output values assigned to positive samples
negative_scores (torch.Tensor) – Output values assigned to negative samples
- Returns
Computed Top-1 Loss
- Return type
torch.Tensor