margin_rank_loss

paddle.fluid.layers.loss. margin_rank_loss ( label, left, right, margin=0.1, name=None ) [source]

Margin Ranking Loss Layer for ranking problem, which compares left score and right score passed in. The ranking loss can be defined as following equation:

\[rank\_loss = max(0, -label * (left - right) + margin)\]
Parameters
  • label (Variable) – Indicates whether the left is ranked higher than the right or not. Data type is float32.

  • left (Variable) – Ranking score for left. Data type float32.

  • right (Variable) – Ranking score for right. Data type float32.

  • margin (float) – Indicates the given margin.

  • name (str|None) – For detailed information, please refer to Name . Usually name is no need to set and None by default.

Returns

The ranking loss.

Return type

Variable

Raises

ValueError – Any of label, left, and right is not a Variable.

Examples

import paddle.fluid as fluid
label = fluid.data(name="label", shape=[-1, 1], dtype="float32")
left = fluid.data(name="left", shape=[-1, 1], dtype="float32")
right = fluid.data(name="right", shape=[-1, 1], dtype="float32")
out = fluid.layers.margin_rank_loss(label, left, right)