- class paddle.nn. MarginRankingLoss ( margin=0.0, reduction='mean', name=None )
This interface is used to construct a callable object of the
MarginRankingLossclass. The MarginRankingLoss layer calculates the margin rank loss between the input, other and label , use the math function as follows.\[margin\_rank\_loss = max(0, -label * (input - other) + margin)\]
'mean', the reduced mean loss is:\[Out = MEAN(margin\_rank\_loss)\]
'sum', the reduced sum loss is:\[Out = SUM(margin\_rank\_loss)\]
'none', just return the origin
margin (float, optional) – The margin value to add, default value is 0;
reduction (str, optional) – Indicate the reduction to apply to the loss, the candicates are
'none', the unreduced loss is returned; If
'mean', the reduced mean loss is returned. If
'sum', the reduced sum loss is returned. Default is
name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.
input: N-D Tensor, the shape is [N, *], N is batch size and * means any number of additional dimensions, available dtype is float32, float64.
other: N-D Tensor, other have the same shape and dtype as input.
label: N-D Tensor, label have the same shape and dtype as input.
'sum', the out shape is \(\), otherwise the shape is the same as input .The same dtype as input tensor.
A callable object of MarginRankingLoss.
import paddle input = paddle.to_tensor([[1, 2], [3, 4]], dtype="float32") other = paddle.to_tensor([[2, 1], [2, 4]], dtype="float32") label = paddle.to_tensor([[1, -1], [-1, -1]], dtype="float32") margin_rank_loss = paddle.nn.MarginRankingLoss() loss = margin_rank_loss(input, other, label) print(loss) # 0.75
Defines the computation performed at every call. Should be overridden by all subclasses.
*inputs (tuple) – unpacked tuple arguments
**kwargs (dict) – unpacked dict arguments