recbole.model.loss¶
Common Loss in recommender system
- class recbole.model.loss.BPRLoss(gamma=1e-10)[source]¶
Bases:
torch.nn.modules.module.Module
BPRLoss, based on Bayesian Personalized Ranking
- Parameters
gamma (-) – Small value to avoid division by zero
- Shape:
Pos_score: (N)
Neg_score: (N), same shape as the Pos_score
Output: scalar.
Examples:
>>> loss = BPRLoss() >>> pos_score = torch.randn(3, requires_grad=True) >>> neg_score = torch.randn(3, requires_grad=True) >>> output = loss(pos_score, neg_score) >>> output.backward()
- forward(pos_score, neg_score)[source]¶
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool¶
- class recbole.model.loss.EmbLoss(norm=2)[source]¶
Bases:
torch.nn.modules.module.Module
EmbLoss, regularization on embeddings
- forward(*embeddings, require_pow=False)[source]¶
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool¶
- class recbole.model.loss.EmbMarginLoss(power=2)[source]¶
Bases:
torch.nn.modules.module.Module
EmbMarginLoss, regularization on embeddings
- forward(*embeddings)[source]¶
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool¶
- class recbole.model.loss.RegLoss[source]¶
Bases:
torch.nn.modules.module.Module
RegLoss, L2 regularization on model parameters
- forward(parameters)[source]¶
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool¶