merlin.models.tf.losses.BPRmaxLoss#

class merlin.models.tf.losses.BPRmaxLoss(reg_lambda: float = 1.0, **kwargs)[source]#

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

The BPR-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__(reg_lambda: float = 1.0, **kwargs)[source]#

[summary]

Parameters

reg_lambda (float, optional) – Regularization factor of the softmax(neg_scores) term, by default 1.0

Methods

__init__([reg_lambda])

[summary]

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)