merlin.models.tf.losses.BPRLoss#

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

Bases: merlin.models.tf.losses.pairwise.PairwiseLoss

The Bayesian Personalised Ranking (BPR) pairwise loss 1

References

1

Rendle, S., Freudenthaler, C., Gantner, Z., and Schmidt-Thieme, L. BPR: Bayesian personalized ranking from implicit feedback. In UAI’09: 25th Conf. on Uncertainty in Artificial Intelligence. https://arxiv.org/pdf/1205.2618.pdf

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