Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
3afb9dc8
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
3afb9dc8
编写于
10月 27, 2017
作者:
C
caoying03
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use double in unittest.
上级
bce4f7d6
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
10 addition
and
16 deletion
+10
-16
paddle/operators/linear_chain_crf_op.cc
paddle/operators/linear_chain_crf_op.cc
+5
-5
python/paddle/v2/framework/tests/test_linear_chain_crf_op.py
python/paddle/v2/framework/tests/test_linear_chain_crf_op.py
+5
-11
未找到文件。
paddle/operators/linear_chain_crf_op.cc
浏览文件 @
3afb9dc8
...
...
@@ -195,8 +195,6 @@ class LinearChainCRFOp : public framework::OperatorWithKernel {
// is the sequence number in a mini-batch. The dimension set here should be
// resized to its correct size in the function Compute.
ctx
->
SetOutputDim
(
"LogLikelihood"
,
{
emission_dims
[
0
],
1
});
ctx
->
ShareLoD
(
"Emission"
,
/*->*/
"EmissionExps"
);
}
protected:
...
...
@@ -402,7 +400,7 @@ class LinearChainCRFGradOp : public framework::OperatorWithKernel {
// operator is determined by its input "EmissionExps".
framework
::
DataType
IndicateDataType
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
return
framework
::
ToDataType
(
ctx
.
Input
<
LoDTensor
>
(
"
EmissionExps
"
)
->
type
());
return
framework
::
ToDataType
(
ctx
.
Input
<
LoDTensor
>
(
"
LogLikelihood
"
)
->
type
());
}
};
...
...
@@ -562,7 +560,9 @@ REGISTER_OP(linear_chain_crf, ops::LinearChainCRFOp, ops::LinearChainCRFOpMaker,
linear_chain_crf_grad
,
ops
::
LinearChainCRFGradOp
);
REGISTER_OP_CPU_KERNEL
(
linear_chain_crf
,
ops
::
LinearChainCRFOpKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
ops
::
LinearChainCRFOpKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
,
ops
::
LinearChainCRFOpKernel
<
paddle
::
platform
::
CPUPlace
,
double
>
);
REGISTER_OP_CPU_KERNEL
(
linear_chain_crf_grad
,
ops
::
LinearChainCRFGradOpKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
ops
::
LinearChainCRFGradOpKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
,
ops
::
LinearChainCRFGradOpKernel
<
paddle
::
platform
::
CPUPlace
,
double
>
);
python/paddle/v2/framework/tests/test_linear_chain_crf_op.py
浏览文件 @
3afb9dc8
...
...
@@ -32,7 +32,7 @@ class LinearChainCrfForward(object):
# alpha is a memo table in dynamic programming to caculate
# nomalization factor.
self
.
alpha
=
np
.
zeros
(
(
seq_start_positions
[
-
1
],
self
.
tag_num
),
dtype
=
"float
32
"
)
(
seq_start_positions
[
-
1
],
self
.
tag_num
),
dtype
=
"float
64
"
)
self
.
log_likelihood
=
np
.
zeros
((
self
.
seq_num
,
1
))
def
_l1_norm
(
self
,
x
):
...
...
@@ -92,12 +92,12 @@ class TestLinearChainCrfOp(OpTest):
for
i
in
range
(
SEQ_NUM
):
lod
[
-
1
].
append
(
lod
[
-
1
][
-
1
]
+
random
.
randint
(
1
,
MAX_SEQ_LEN
))
emission
=
np
.
random
.
uniform
(
-
1
,
1
,
[
lod
[
-
1
][
-
1
],
TAG_NUM
]).
astype
(
"float
32
"
)
[
lod
[
-
1
][
-
1
],
TAG_NUM
]).
astype
(
"float
64
"
)
emission_row_max
=
np
.
amax
(
emission
,
axis
=
1
,
keepdims
=
True
)
emission_exps
=
np
.
exp
(
emission
-
emission_row_max
)
transition
=
np
.
random
.
uniform
(
-
0.5
,
0.5
,
[
TAG_NUM
+
2
,
TAG_NUM
]).
astype
(
"float
32
"
)
[
TAG_NUM
+
2
,
TAG_NUM
]).
astype
(
"float
64
"
)
transition_exps
=
np
.
exp
(
transition
)
labels
=
np
.
random
.
randint
(
...
...
@@ -128,17 +128,11 @@ class TestLinearChainCrfOp(OpTest):
self
.
check_output
()
def
test_check_grad
(
self
):
self
.
check_grad
(
[
"Emission"
,
"Transition"
],
"LogLikelihood"
,
max_relative_error
=
0.05
)
self
.
check_grad
([
"Emission"
,
"Transition"
],
"LogLikelihood"
)
def
test_check_grad_ignore_transition
(
self
):
self
.
check_grad
(
[
"Emission"
],
"LogLikelihood"
,
max_relative_error
=
0.05
,
no_grad_set
=
set
(
"Transition"
))
[
"Emission"
],
"LogLikelihood"
,
no_grad_set
=
set
(
"Transition"
))
if
__name__
==
"__main__"
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录