bpr_loss

paddle.fluid.layers.loss. bpr_loss ( input, label, name=None ) [source]

Bayesian Personalized Ranking Loss Operator

This operator belongs to pairwise ranking loss. Label is the desired item. The loss at a given point in one session is defined as:

\[Y[i] = 1/(N[i] - 1) * \sum_j{\log(\sigma(X[i, Label[i]]-X[i, j]))}\]

Learn more details by reading paper <session-based recommendations with recurrent neural networks>.

Parameters
  • input (Variable|list) – a 2-D tensor with shape [N x D], where N is the batch size and D is the number of positive classes and negative classes This input is not probability but logits.

  • label (Variable|list) – the ground truth which is a 2-D tensor. label is a tensor<int64> with shape [N x 1].

  • name (str|None) – A name for this layer(optional). If set None, the layer will be named automatically. Default: None.

Returns

A 2-D tensor with shape [N x 1], the bpr loss.

Examples

import paddle.fluid as fluid
import paddle

paddle.enable_static()

neg_size = 10
label = fluid.data(
          name="label", shape=[3, 1], dtype="int64")
predict = fluid.data(
          name="predict", shape=[3, neg_size + 1], dtype="float32")
cost = fluid.layers.bpr_loss(input=predict, label=label)