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)\]
  • 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.


The ranking loss.

Return type



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


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