Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
cf4b2db7
P
Paddle
项目概览
机器未来
/
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看板
提交
cf4b2db7
编写于
9月 21, 2017
作者:
Y
Yibing Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change the dims of input of rank_loss_op
上级
ece32910
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
9 addition
and
11 deletion
+9
-11
paddle/operators/rank_loss_op.cc
paddle/operators/rank_loss_op.cc
+6
-8
python/paddle/v2/framework/tests/test_rank_loss_op.py
python/paddle/v2/framework/tests/test_rank_loss_op.py
+3
-3
未找到文件。
paddle/operators/rank_loss_op.cc
浏览文件 @
cf4b2db7
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
...
...
@@ -37,11 +36,10 @@ class RankLossOp : public framework::OperatorWithKernel {
auto
label_dims
=
ctx
.
Input
<
framework
::
Tensor
>
(
"Label"
)
->
dims
();
auto
left_dims
=
ctx
.
Input
<
framework
::
Tensor
>
(
"Left"
)
->
dims
();
auto
right_dims
=
ctx
.
Input
<
framework
::
Tensor
>
(
"Right"
)
->
dims
();
PADDLE_ENFORCE
((
label_dims
.
size
()
==
1
)
&&
(
left_dims
.
size
()
==
1
)
&&
(
right_dims
.
size
()
==
1
),
"The rank of all inputs must be 1."
);
PADDLE_ENFORCE
((
label_dims
==
left_dims
)
&&
(
left_dims
==
right_dims
),
"All inputs must have the same size"
);
PADDLE_ENFORCE
((
label_dims
.
size
()
==
2
)
&&
(
label_dims
[
1
]
==
1
),
"All inputs must be row vector with size batch_sizex1."
);
ctx
.
Output
<
framework
::
LoDTensor
>
(
"Out"
)
->
Resize
(
label_dims
);
}
};
...
...
@@ -52,10 +50,10 @@ class RankLossOpMaker : public framework::OpProtoAndCheckerMaker {
framework
::
OpAttrChecker
*
op_checker
)
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddInput
(
"Label"
,
"The label indicating A ranked higher than B or not,
1-D tens
or."
);
AddInput
(
"Left"
,
"The output of RankNet for doc A,
1-D tens
or."
);
AddInput
(
"Right"
,
"The output of RankNet for doc B,
1-D tens
or"
);
AddOutput
(
"Out"
,
"The output loss of RankLoss operator,
1-D tens
or."
);
"The label indicating A ranked higher than B or not,
row vect
or."
);
AddInput
(
"Left"
,
"The output of RankNet for doc A,
vect
or."
);
AddInput
(
"Right"
,
"The output of RankNet for doc B,
vet
or"
);
AddOutput
(
"Out"
,
"The output loss of RankLoss operator,
vect
or."
);
AddComment
(
R"DOC(RankLoss operator
Rank loss operator for RankNet[1]. RankNet is a pairwise ranking model with
...
...
python/paddle/v2/framework/tests/test_rank_loss_op.py
浏览文件 @
cf4b2db7
...
...
@@ -8,9 +8,9 @@ class TestRankLossOp(OpTest):
self
.
op_type
=
"rank_loss"
batch_size
=
5
# labels_{i} = {0, 1.0} or {0, 0.5, 1.0}
label
=
np
.
random
.
randint
(
0
,
2
,
size
=
(
batch_size
,
)).
astype
(
"float32"
)
left
=
np
.
random
.
random
((
batch_size
,
)).
astype
(
"float32"
)
right
=
np
.
random
.
random
((
batch_size
,
)).
astype
(
"float32"
)
label
=
np
.
random
.
randint
(
0
,
2
,
size
=
(
batch_size
,
1
)).
astype
(
"float32"
)
left
=
np
.
random
.
random
((
batch_size
,
1
)).
astype
(
"float32"
)
right
=
np
.
random
.
random
((
batch_size
,
1
)).
astype
(
"float32"
)
loss
=
np
.
log
(
1.0
+
np
.
exp
(
left
-
right
))
-
label
*
(
left
-
right
)
self
.
inputs
=
{
'Label'
:
label
,
'Left'
:
left
,
'Right'
:
right
}
self
.
outputs
=
{
'Out'
:
loss
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录