MarginRankingLoss¶
- class paddle.nn. MarginRankingLoss ( margin=0.0, reduction='mean', name=None ) [source]
- 
         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)\]If reductionset to'mean', the reduced mean loss is:\[Out = MEAN(margin\_rank\_loss)\]If reductionset to'sum', the reduced sum loss is:\[Out = SUM(margin\_rank\_loss)\]If reductionset to'none', just return the originmargin_rank_loss.- Parameters
- 
           - 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',- 'mean',- 'sum'.If- reductionis- 'none', the unreduced loss is returned; If- reductionis- 'mean', the reduced mean loss is returned. If- reductionis- 'sum', the reduced sum loss is returned. Default is- 'mean'.
- name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name. 
 
 Shape: 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. output: If reductionis'mean'or'sum', the out shape is \([1]\), otherwise the shape is the same as input .The same dtype as input tensor.- Returns
- 
           A callable object of MarginRankingLoss. 
 Examples 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] - 
            
           forward
           (
           input, 
           other, 
           label
           )
           forward¶
- 
           Defines the computation performed at every call. Should be overridden by all subclasses. - Parameters
- 
             - *inputs (tuple) – unpacked tuple arguments 
- **kwargs (dict) – unpacked dict arguments 
 
 
 
