From a9f9e208f5857c29565916e4875447d12aa1bb15 Mon Sep 17 00:00:00 2001 From: zhouxiao-coder Date: Tue, 31 Oct 2017 18:26:24 +0800 Subject: [PATCH] Add optional inputs and outputs to enable updating;Add weight to match original implementation --- paddle/operators/positive_negative_pair_op.cc | 15 +++++++++++---- .../tests/test_positive_negative_pair_op.py | 3 --- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/paddle/operators/positive_negative_pair_op.cc b/paddle/operators/positive_negative_pair_op.cc index b234e9c0de1..f740af1859c 100644 --- a/paddle/operators/positive_negative_pair_op.cc +++ b/paddle/operators/positive_negative_pair_op.cc @@ -129,7 +129,10 @@ class PositiveNegativePairOpMaker : public framework::OpProtoAndCheckerMaker { .AsDispensable(); AddInput("Weight", "(float) Optional. Weight of current item. If specified, its " - "shape should be the same as Label.") + "shape should be the same as Label, and the meaning of the output " + "changes from numbers of pairs to the total sum of pairs' " + "weights. Weight of a pair of items is the average of their " + "weights.") .AsDispensable(); AddOutput("PositivePair", "(float) Number of positive pairs, i.e. the pairs of " @@ -150,9 +153,13 @@ class PositiveNegativePairOpMaker : public framework::OpProtoAndCheckerMaker { "Noting that reducing on the first dim will make the LoD info lost.") .SetDefault(0); AddComment(R"DOC( - PositiveNegativePairOp can be used to evaluate Learning To Rank(LTR) model performance. - Within some context, e.g. the "query", a LTR model generates scores for a list of items, which gives a partial order of the items. - PositiveNegativePairOp takes a list of reference rank order (Input("Label")) and the model generated scores (Input(Score)) as inputs and counts the pairs that ranked correctly and incorrectly. + PositiveNegativePairOp can be used to evaluate Learning To Rank(LTR) + model performance. + Within some context, e.g. the "query", a LTR model generates scores + for a list of items, which gives a partial order of the items. + PositiveNegativePairOp takes a list of reference rank order + (Input("Label")) and the model generated scores (Input(Score)) as + inputs and counts the pairs that ranked correctly and incorrectly. )DOC"); } }; diff --git a/python/paddle/v2/framework/tests/test_positive_negative_pair_op.py b/python/paddle/v2/framework/tests/test_positive_negative_pair_op.py index 64438c09a65..cbd05a4f51f 100644 --- a/python/paddle/v2/framework/tests/test_positive_negative_pair_op.py +++ b/python/paddle/v2/framework/tests/test_positive_negative_pair_op.py @@ -12,9 +12,6 @@ def py_pnpair_op(score, label, query, column=-1, weight=None): if weight is None: weight = np.ones(shape=(batch_size, 1)).astype('float32') for s, l, q, w in zip(score, label, query, weight): - # s = s[column] - # q = q[0] - # w = w[0] s, l, q, w = s[column], l[0], q[0], w[0] if q not in predictions: predictions[q] = [] -- GitLab