Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
35279398
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看板
提交
35279398
编写于
12月 21, 2016
作者:
P
Peng Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix merge and style error
上级
b063b0c4
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
23 addition
and
26 deletion
+23
-26
paddle/gserver/layers/CRFLayer.cpp
paddle/gserver/layers/CRFLayer.cpp
+8
-7
paddle/gserver/layers/CRFLayer.h
paddle/gserver/layers/CRFLayer.h
+2
-2
paddle/gserver/tests/test_CRFLayerGrad.cpp
paddle/gserver/tests/test_CRFLayerGrad.cpp
+13
-17
未找到文件。
paddle/gserver/layers/CRFLayer.cpp
浏览文件 @
35279398
...
@@ -42,8 +42,7 @@ bool CRFLayer::init(const LayerMap& layerMap,
...
@@ -42,8 +42,7 @@ bool CRFLayer::init(const LayerMap& layerMap,
CHECK_EQ
(
parameters_
[
0
]
->
getSize
(),
numClasses_
*
(
numClasses_
+
2
));
CHECK_EQ
(
parameters_
[
0
]
->
getSize
(),
numClasses_
*
(
numClasses_
+
2
));
parameter_
=
parameters_
[
0
];
parameter_
=
parameters_
[
0
];
weight_
.
reset
(
weight_
.
reset
(
new
Weight
(
numClasses_
+
2
,
numClasses_
,
parameter_
));
new
Weight
(
numClasses_
+
2
,
numClasses_
,
parameter_
));
// We don't need sequenceStartPositions because each sample of output_ is
// We don't need sequenceStartPositions because each sample of output_ is
// for the cost of one sequence.
// for the cost of one sequence.
...
@@ -95,16 +94,18 @@ void CRFLayer::backward(const UpdateCallback& callback) {
...
@@ -95,16 +94,18 @@ void CRFLayer::backward(const UpdateCallback& callback) {
for
(
int
i
=
0
;
i
<
numSequences
;
++
i
)
{
for
(
int
i
=
0
;
i
<
numSequences
;
++
i
)
{
crfs_
[
i
].
backward
(
output
.
value
->
getData
()
+
numClasses_
*
starts
[
i
],
crfs_
[
i
].
backward
(
output
.
value
->
getData
()
+
numClasses_
*
starts
[
i
],
label
.
ids
->
getData
()
+
starts
[
i
],
label
.
ids
->
getData
()
+
starts
[
i
],
starts
[
i
+
1
]
-
starts
[
i
],
needWGrad
);
starts
[
i
+
1
]
-
starts
[
i
],
real
instanceWeight
=
weightLayer_
?
needWGrad
);
getInputValue
(
*
weightLayer_
)
->
getElement
(
i
,
0
)
:
real
(
1.0
f
);
real
instanceWeight
=
weightLayer_
?
getInputValue
(
*
weightLayer_
)
->
getElement
(
i
,
0
)
:
real
(
1.0
f
);
instanceWeight
*=
coeff_
;
instanceWeight
*=
coeff_
;
MatrixPtr
grad
=
output
.
grad
->
subRowMatrix
(
starts
[
i
],
starts
[
i
+
1
]);
MatrixPtr
grad
=
output
.
grad
->
subRowMatrix
(
starts
[
i
],
starts
[
i
+
1
]);
grad
->
add
(
*
crfs_
[
i
].
getXGrad
(),
real
(
1.0
f
),
instanceWeight
);
grad
->
add
(
*
crfs_
[
i
].
getXGrad
(),
real
(
1.0
f
),
instanceWeight
);
if
(
needWGrad
)
{
if
(
needWGrad
)
{
weight_
->
getWGrad
()
->
add
(
*
crfs_
[
i
].
getWGrad
(),
real
(
1.0
f
),
weight_
->
getWGrad
()
->
add
(
instanceWeight
);
*
crfs_
[
i
].
getWGrad
(),
real
(
1.0
f
),
instanceWeight
);
}
}
}
}
...
...
paddle/gserver/layers/CRFLayer.h
浏览文件 @
35279398
paddle/gserver/tests/test_CRFLayerGrad.cpp
浏览文件 @
35279398
...
@@ -23,11 +23,8 @@ limitations under the License. */
...
@@ -23,11 +23,8 @@ limitations under the License. */
using
namespace
paddle
;
// NOLINT
using
namespace
paddle
;
// NOLINT
P_DECLARE_bool
(
use_gpu
);
DECLARE_int32
(
gpu_id
);
P_DECLARE_int32
(
gpu_id
);
DECLARE_bool
(
thread_local_rand_use_global_seed
);
P_DECLARE_double
(
checkgrad_eps
);
P_DECLARE_bool
(
thread_local_rand_use_global_seed
);
P_DECLARE_bool
(
prev_batch_state
);
static
inline
bool
getNextSequence
(
std
::
vector
<
int
>&
seq
,
int
numClasses
)
{
static
inline
bool
getNextSequence
(
std
::
vector
<
int
>&
seq
,
int
numClasses
)
{
for
(
auto
&
v
:
seq
)
{
for
(
auto
&
v
:
seq
)
{
...
@@ -96,8 +93,8 @@ TEST(CRFLayer, cost) {
...
@@ -96,8 +93,8 @@ TEST(CRFLayer, cost) {
real
diff
=
fabs
(
trueCost
-
cost
);
real
diff
=
fabs
(
trueCost
-
cost
);
diff
/=
fabs
(
cost
)
<
fabs
(
trueCost
)
?
fabs
(
cost
)
:
fabs
(
trueCost
);
diff
/=
fabs
(
cost
)
<
fabs
(
trueCost
)
?
fabs
(
cost
)
:
fabs
(
trueCost
);
VLOG
(
1
)
<<
"cost="
<<
cost
<<
" trueCost="
<<
trueCost
VLOG
(
1
)
<<
"cost="
<<
cost
<<
" trueCost="
<<
trueCost
<<
" diff="
<<
diff
<<
" diff="
<<
diff
<<
std
::
endl
;
<<
std
::
endl
;
if
(
typeid
(
real
)
==
typeid
(
double
))
{
// NOLINT
if
(
typeid
(
real
)
==
typeid
(
double
))
{
// NOLINT
EXPECT_LE
(
diff
,
1e-10
);
EXPECT_LE
(
diff
,
1e-10
);
}
else
{
}
else
{
...
@@ -107,9 +104,7 @@ TEST(CRFLayer, cost) {
...
@@ -107,9 +104,7 @@ TEST(CRFLayer, cost) {
}
}
}
}
inline
real
epsilon
()
{
inline
real
epsilon
()
{
return
typeid
(
real
)
==
typeid
(
double
)
?
1e-10
:
0.06
;
}
return
typeid
(
real
)
==
typeid
(
double
)
?
1e-10
:
0.06
;
}
TestConfig
initTestConfig
(
size_t
numClasses
,
bool
withWeight
)
{
TestConfig
initTestConfig
(
size_t
numClasses
,
bool
withWeight
)
{
TestConfig
config
;
TestConfig
config
;
...
@@ -117,16 +112,17 @@ TestConfig initTestConfig(size_t numClasses, bool withWeight) {
...
@@ -117,16 +112,17 @@ TestConfig initTestConfig(size_t numClasses, bool withWeight) {
config
.
layerConfig
.
set_size
(
numClasses
);
config
.
layerConfig
.
set_size
(
numClasses
);
config
.
biasSize
=
0
;
config
.
biasSize
=
0
;
config
.
inputDefs
.
push_back
({
INPUT_SEQUENCE_DATA
,
"layer_0"
,
config
.
inputDefs
.
push_back
({
INPUT_SEQUENCE_DATA
,
numClasses
,
numClasses
*
(
numClasses
+
2
)});
"layer_0"
,
numClasses
,
numClasses
*
(
numClasses
+
2
)});
config
.
layerConfig
.
add_inputs
();
config
.
layerConfig
.
add_inputs
();
config
.
inputDefs
.
push_back
(
{
INPUT_SEQUENCE_LABEL
,
"layer_label"
,
config
.
inputDefs
.
push_back
(
numClasses
,
0
});
{
INPUT_SEQUENCE_LABEL
,
"layer_label"
,
numClasses
,
0
});
config
.
layerConfig
.
add_inputs
();
config
.
layerConfig
.
add_inputs
();
if
(
withWeight
)
{
if
(
withWeight
)
{
config
.
inputDefs
.
push_back
({
INPUT_DENSE_DIM_DATA
,
"layer_weight"
,
config
.
inputDefs
.
push_back
({
INPUT_DENSE_DIM_DATA
,
"layer_weight"
,
1
,
0
});
1
,
0
});
config
.
layerConfig
.
add_inputs
();
config
.
layerConfig
.
add_inputs
();
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录