merlin.models.tf.losses.TOP1maxLoss
-
class
merlin.models.tf.losses.
TOP1maxLoss
(reduction='auto', name=None)[source] Bases:
merlin.models.utils.registry.RegistryMixin
[LossRegistryMixin
]The TOP1-max pairwise loss proposed in 1
References
- 1
Hidasi, Balázs, and Alexandros Karatzoglou. “Recurrent neural networks with top-k gains for session-based recommendations.” Proceedings of the 27th ACM international conference on information and knowledge management. 2018. https://arxiv.org/abs/1706.03847
-
__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 with tf.distribute.Strategy, outside of built-in training loops such as tf.keras compile and 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)