rank_loss¶
- paddle.fluid.layers.loss. rank_loss ( label, left, right, name=None ) [source]
-
This operator implements the sort loss layer in the RankNet model. RankNet is a pairwise ranking model with a training sample consisting of a pair of documents (A and B), The label (P) indicates whether A is ranked higher than B or not. Please refer to more details: RankNet
Rank loss layer takes three inputs: left ( oi ), right ( oj ) and label ( Pi,j ). The inputs respectively represent RankNet’s output scores for documents A and B and the value of label P. Rank loss layer takes batch inputs with size batch_size (batch_size >= 1), P = {0, 1} or {0, 0.5, 1}, where 0.5 means that there is no information about the rank of the input pair. The following equation computes rank loss C_{i,j} from the inputs:
Ci,j=−tildePij∗oi,j+log(1+eoi,j)oi,j=oi−ojtildePi,j=left{0,0.5,1right} or left{0,1right}- Parameters
-
label (Variable) – 2-D
Tensor
with the shape of [batch,1], the data type is float32, batch indicates the size of the data. Indicats whether A ranked higher than B or not.left (Variable) – 2-D
Tensor
with the shape of [batch,1], the data type is float32. RankNet’s output score for doc A.right (Variable) – 2-D
Tensor
with the shape of [batch,1], the data type is float32. RankNet’s output score for doc B.name (str|None) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name .
- Returns
-
Tensor
indicating the output value of the sort loss layer, the data type is float32, and the return value’s shape is [batch,1] . - Return type
-
Variable
- Raises
-
ValueError – Any of label, left, and right is not a
Variable
.
Examples
import paddle.fluid as fluid import paddle paddle.enable_static() label = fluid.data(name="label", shape=[-1, 1], dtype="float32") left = fluid.data(name="left", shape=[-1, 1], dtype="float32") right = fluid.data(name="right", shape=[-1, 1], dtype="float32") out = fluid.layers.rank_loss(label, left, right)