merlin.models.tf.losses.TOP1Loss#
- class merlin.models.tf.losses.TOP1Loss(reduction='auto', name=None)[source]#
Bases:
merlin.models.tf.losses.pairwise.PairwiseLoss
The TOP pairwise loss proposed in 1
References
- 1
B. Hidasi, A. Karatzoglou, L. Baltrunas, and D. Tikk, “Session-based recommendations with recurrent neural networks,” in Proceedings of Fourth International Conference on Learning Representations (ICLR’16), 2016. https://arxiv.org/abs/1511.06939
- __init__(reduction='auto', name=None)#
Initializes Loss class.
- Parameters
reduction –
Type of tf.keras.losses.Reduction to apply to loss. Default value is AUTO. AUTO indicates that the reduction option will be determined by the usage context. For almost all cases this defaults to SUM_OVER_BATCH_SIZE. When used under a tf.distribute.Strategy, except via Model.compile() and Model.fit(), using AUTO or SUM_OVER_BATCH_SIZE will raise an error. Please see this custom training [tutorial](
https://www.tensorflow.org/tutorials/distribute/custom_training) for more details.
name – Optional name for the instance.
Methods
__init__
([reduction, name])Initializes Loss class.
call
(y_true, y_pred)Loss computation.
compute
(positives_scores, negatives_scores)Computes the loss
from_config
(config)Instantiates a Loss from its config (output of get_config()).
get_config
()Returns the config dictionary for a Loss instance.
parse
(class_or_str)Attributes
registry
valid_negatives_mask
- compute(positives_scores: tensorflow.python.framework.ops.Tensor, negatives_scores: tensorflow.python.framework.ops.Tensor) tensorflow.python.framework.ops.Tensor [source]#
Computes the loss
- Parameters
positives_scores (tf.Tensor) – Prediction scores for the positive items (batch size x 1)
negatives_scores (tf.Tensor) – Prediction scores for the positive items (batch size x number negative samples)
- Returns
Loss per negative sample
- Return type
tf.Tensor (batch size x number negative samples)