@@ -5830,25 +5830,31 @@ def rank_loss(label, left, right, name=None):
5830
5830
5831
5831
def margin_rank_loss (label , left , right , margin = 0.1 , name = None ):
5832
5832
"""
5833
- **Margin Rank loss layer for rank problem**
5834
- Args:
5835
- label (Variable): Indicats whether left higher than (right + margin) or not.
5836
- left (Variable): rank score for left.
5837
- right (Variable): rank score for right.
5838
- margin (float): Indicates the margin to be added to right
5839
- name (str|None): A name for this layer (optional). If set None, the layer
5840
- will be named automatically.
5841
- Returns:
5842
- list: The value of rank loss.
5843
- Raises:
5844
- ValueError: Any of label, left, and right is not a variable.
5845
- Examples:
5846
- .. code-block:: python
5847
- label = fluid.layers.data(name="label", shape=[4, 1], dtype="float32")
5848
- left = fluid.layers.data(name="left", shape=[4, 1], dtype="float32")
5849
- right = fluid.layers.data(name="right", shape=[4, 1], dtype="float32")
5850
- out = fluid.layers.margin_rank_loss(label, left, right)
5851
- """
5833
+ Margin Rank loss layer for rank problem, which comparing left value and right value be passed in.
5834
+ The rank loss can be defined as below equation:
5835
+
5836
+ .. math::
5837
+
5838
+ rank\_loss &= max(0, -label * (left - right) + margin)
5839
+
5840
+ Args:
5841
+ label (Variable): Indicats whether left higher than (right + margin) or not.
5842
+ left (Variable): rank score for left.
5843
+ right (Variable): rank score for right.
5844
+ margin (float): Indicates the margin to be added to right
5845
+ name (str|None): A name for this layer (optional). If set None, the layer
5846
+ will be named automatically.
5847
+ Returns:
5848
+ list: The value of rank loss.
5849
+ Raises:
5850
+ ValueError: Any of label, left, and right is not a variable.
5851
+ Examples:
5852
+ .. code-block:: python
5853
+ label = fluid.layers.data(name="label", shape=[4, 1], dtype="float32")
5854
+ left = fluid.layers.data(name="left", shape=[4, 1], dtype="float32")
5855
+ right = fluid.layers.data(name="right", shape=[4, 1], dtype="float32")
5856
+ out = fluid.layers.margin_rank_loss(label, left, right)
5857
+ """
5852
5858
helper = LayerHelper ('margin_rank_loss' , ** locals ())
5853
5859
if not (isinstance (label , Variable )):
5854
5860
raise ValueError ("The label should be a Variable" )
0 commit comments