merlin.models.tf.losses.LogisticLoss

class merlin.models.tf.losses.LogisticLoss(reduction='auto', name=None)[source]

Bases: merlin.models.utils.registry.RegistryMixin[LossRegistryMixin]

Pairwise log loss, as described in 1: log(1 + exp(r_uj - r_ui)), where r_ui is the score of the positive item and r_uj the score of negative items.

References

1

Sun, Zhu, et al. “Are we evaluating rigorously? benchmarking recommendation for reproducible evaluation and fair comparison.” Fourteenth ACM conference on recommender systems. 2020.

__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](

  • 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)