提交 a7cae62b 编写于 作者: M minqiyang

Polish code

test=develop
上级 7f6ff6f5
...@@ -5830,24 +5830,25 @@ def rank_loss(label, left, right, name=None): ...@@ -5830,24 +5830,25 @@ def rank_loss(label, left, right, name=None):
def margin_rank_loss(label, left, right, margin=0.1, name=None): def margin_rank_loss(label, left, right, margin=0.1, name=None):
""" """
Margin Rank loss layer for rank problem, which comparing left value and right value be passed in. Margin Ranking Loss Layer for ranking problem,
The rank loss can be defined as below equation: which compare left score and right score passed in.
The ranking loss can be defined as following equation:
.. math:: .. math::
rank\_loss &= max(0, -label * (left - right) + margin) rank\_loss &= max(0, -label * (left - right) + margin)
Args: Args:
label (Variable): Indicats whether left higher than (right + margin) or not. label (Variable): Indicates whether the left is ranked higher than the right or not.
left (Variable): rank score for left. left (Variable): ranking score for left.
right (Variable): rank score for right. right (Variable): ranking score for right.
margin (float): Indicates the margin to be added to right margin (float): Indicates the given margin to be added to right
name (str|None): A name for this layer (optional). If set None, the layer name (str|None): A name for this layer (optional). If set None, the layer
will be named automatically. will be named automatically.
Returns: Returns:
list: The value of rank loss. list: The Variable of ranking loss.
Raises: Raises:
ValueError: Any of label, left, and right is not a variable. ValueError: Any of label, left, and right is not a Variable.
Examples: Examples:
.. code-block:: python .. code-block:: python
label = fluid.layers.data(name="label", shape=[4, 1], dtype="float32") label = fluid.layers.data(name="label", shape=[4, 1], dtype="float32")
...@@ -5862,8 +5863,8 @@ def margin_rank_loss(label, left, right, margin=0.1, name=None): ...@@ -5862,8 +5863,8 @@ def margin_rank_loss(label, left, right, margin=0.1, name=None):
raise ValueError("The left should be a Variable") raise ValueError("The left should be a Variable")
if not (isinstance(right, Variable)): if not (isinstance(right, Variable)):
raise ValueError("The right should be a Variable") raise ValueError("The right should be a Variable")
out = helper.create_tmp_variable("float32") out = helper.create_tmp_variable(left.dtype)
act = helper.create_tmp_variable("float32") act = helper.create_tmp_variable(left.dtype)
helper.append_op( helper.append_op(
type='margin_rank_loss', type='margin_rank_loss',
inputs={"Label": label, inputs={"Label": label,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册