Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
13b7d928
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
13b7d928
编写于
10月 11, 2017
作者:
Y
Yibing Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
improve doc in margin_rank_loss_op
上级
240adef1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
21 addition
and
15 deletion
+21
-15
paddle/operators/margin_rank_loss_op.cc
paddle/operators/margin_rank_loss_op.cc
+19
-13
paddle/operators/margin_rank_loss_op.h
paddle/operators/margin_rank_loss_op.h
+2
-2
未找到文件。
paddle/operators/margin_rank_loss_op.cc
浏览文件 @
13b7d928
...
...
@@ -22,7 +22,7 @@ class MarginRankLossOp : public framework::OperatorWithKernel {
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
protected:
void
InferShape
(
framework
::
InferShapeContext
Base
*
ctx
)
const
override
{
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
// input check
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"Label"
),
"Input(Label) shouldn't be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X1"
),
"Input(X1) shouldn't be null."
);
...
...
@@ -47,11 +47,11 @@ class MarginRankLossOpMaker : public framework::OpProtoAndCheckerMaker {
framework
::
OpAttrChecker
*
op_checker
)
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddInput
(
"X1"
,
"(2-D tensor with shape [batch_size x 1])
In pairwise ranking,
"
"
X1 is the score for one item to be ranked
."
);
"(2-D tensor with shape [batch_size x 1])
The score for
"
"
one item X1 to be ranked, from pairwise ranking model
."
);
AddInput
(
"X2"
,
"(2-D tensor with shape [batch_size x 1])
In pairwise ranking,
"
"
X2 is the score for another item to be ranked
."
);
"(2-D tensor with shape [batch_size x 1])
The score for
"
"
another item X2 to be ranked, from pairwise ranking model
."
);
AddInput
(
"Label"
,
"(2-D tensor with shape [batch_size x 1]) "
"The label indicating X1 ranked higher than X2 or not, "
...
...
@@ -63,19 +63,25 @@ class MarginRankLossOpMaker : public framework::OpProtoAndCheckerMaker {
"to indicate whether each element of Output(Out) is activated."
)
.
AsIntermediate
();
AddOutput
(
"Out"
,
"(2-D tensor with shape [batch_size x 1])"
"(2-D tensor with shape [batch_size x 1])
"
"The output loss of MarginRankLoss operator."
);
AddComment
(
R"DOC(
MarginRankLoss operator measures the loss given a pair of input {`X1`, `X2`}
and the `Label` with attribute `margin`, where `Label = +1` indicating X1 is
ranked higher than `X2`, otherwise `Label = -1`. The loss turns out
MarginRankLoss operator measures the loss given a pair of training sample
{`X1`, `X2`} and the `Label` with attribute `margin`, where `Label = +1`
indicating X1 is ranked higher than `X2`, otherwise `Label = -1`. The loss
turns out
loss(X1, X2, Label) = max(0, -Label * (X1 - X2) + margin)
loss(X1, X2, Label) = max(0, -Label * (X1 - X2) + margin)
.
The attribute `margin` involved here helps make the predictions more robust.
Only when the difference between `X1` and `X2` is greater than `margin`, it is
possible for these two items contribute to the final loss.
Denote the item ranked higher as the positive sample, otherwise negative
sample. If the score of the two samples statisfies
positive sample - negative sample < margin,
the pair of samples will contribute to the loss, which will backpropogate and
train the ranking model to enlarge the difference of the two score.
For batch input with size `batch_size`, `X1`, `X2` and `Label`
all have the same shape [batch_size x 1].
...
...
@@ -89,7 +95,7 @@ class MarginRankLossGradOp : public framework::OperatorWithKernel {
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
protected:
void
InferShape
(
framework
::
InferShapeContext
Base
*
ctx
)
const
override
{
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"Label"
),
"Input(Label) shouldn't be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X1"
),
"Input(X1) shouldn't be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X2"
),
"Input(X2) shouldn't be null."
);
...
...
paddle/operators/margin_rank_loss_op.h
浏览文件 @
13b7d928
...
...
@@ -35,7 +35,7 @@ struct Heaviside {
};
template
<
typename
Place
,
typename
T
>
class
MarginRankLossKernel
:
public
framework
::
OpKernel
{
class
MarginRankLossKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
{
auto
*
out_t
=
ctx
.
Output
<
framework
::
Tensor
>
(
"Out"
);
...
...
@@ -63,7 +63,7 @@ class MarginRankLossKernel : public framework::OpKernel {
};
template
<
typename
Place
,
typename
T
>
class
MarginRankLossGradKernel
:
public
framework
::
OpKernel
{
class
MarginRankLossGradKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
{
auto
*
d_x1_t
=
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录