Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
12f2b8eb
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看板
提交
12f2b8eb
编写于
9月 25, 2017
作者:
L
Liu Yiqun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Correct the forward of sequence_softmax_op.
上级
4d929394
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
12 addition
and
7 deletion
+12
-7
paddle/operators/reshape_op.cc
paddle/operators/reshape_op.cc
+1
-2
paddle/operators/sequence_softmax_op.cc
paddle/operators/sequence_softmax_op.cc
+6
-4
paddle/operators/sequence_softmax_op.h
paddle/operators/sequence_softmax_op.h
+5
-1
未找到文件。
paddle/operators/reshape_op.cc
浏览文件 @
12f2b8eb
...
...
@@ -42,8 +42,7 @@ class ReshapeOp : public framework::OperatorWithKernel {
int64_t
capacity
=
std
::
accumulate
(
shape
.
begin
(),
shape
.
end
(),
1
,
std
::
multiplies
<
int
>
());
auto
*
in
=
ctx
.
Input
<
framework
::
Tensor
>
(
"X"
);
int64_t
in_size
=
framework
::
product
(
in
->
dims
());
PADDLE_ENFORCE_EQ
(
capacity
,
in_size
,
PADDLE_ENFORCE_EQ
(
capacity
,
in
->
numel
(),
"The size of Input(X) mismatches with Attr(shape)."
);
// resize output
std
::
vector
<
int64_t
>
shape_int64
(
shape
.
size
(),
0
);
...
...
paddle/operators/sequence_softmax_op.cc
浏览文件 @
12f2b8eb
...
...
@@ -30,18 +30,20 @@ class SequenceSoftmaxOp : public framework::OperatorWithKernel {
"Output(Out) of SequenceSoftmaxOp should not be null."
);
auto
*
x
=
ctx
.
Input
<
framework
::
LoDTensor
>
(
"X"
);
auto
dims
=
x
->
dims
();
auto
lod
=
x
->
lod
();
PADDLE_ENFORCE_EQ
(
lod
.
size
(),
1UL
,
"Only support one level sequence now."
);
auto
dims
=
x
->
dims
(
);
PADDLE_ENFORCE_GE
(
dims
[
0
],
/* batch_size */
static_cast
<
int64_t
>
(
lod
[
0
].
size
()
-
1
),
"The first dimension of Input(X) should be larger than batch size."
);
PADDLE_ENFORCE_EQ
(
x
->
numel
(),
static_cast
<
int64_t
>
(
lod
[
0
].
size
()
-
1
),
const
size_t
level
=
lod
.
size
()
-
1
;
PADDLE_ENFORCE_EQ
(
x
->
numel
(),
static_cast
<
int64_t
>
(
lod
[
level
].
back
()),
"The width of each timestep in Input(X) of "
"SequenceSoftmaxOp should be 1."
);
dims
[
0
]
=
lod
[
0
].
size
()
-
1
;
std
::
cout
<<
DebugString
()
<<
std
::
endl
;
ctx
.
Output
<
framework
::
LoDTensor
>
(
"Out"
)
->
Resize
({
dims
});
}
};
...
...
paddle/operators/sequence_softmax_op.h
浏览文件 @
12f2b8eb
...
...
@@ -38,7 +38,7 @@ class SequenceSoftmaxKernel : public framework::OpKernel {
auto
*
out
=
ctx
.
Output
<
LoDTensor
>
(
"Out"
);
auto
lod
=
x
->
lod
();
const
size_t
level
=
lod
.
size
();
const
size_t
level
=
lod
.
size
()
-
1
;
out
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
for
(
int
i
=
0
;
i
<
static_cast
<
int
>
(
lod
[
level
].
size
())
-
1
;
++
i
)
{
...
...
@@ -47,6 +47,10 @@ class SequenceSoftmaxKernel : public framework::OpKernel {
Tensor
x_i
=
x
->
Slice
<
T
>
(
start_pos
,
end_pos
);
Tensor
out_i
=
out
->
Slice
<
T
>
(
start_pos
,
end_pos
);
// Reshape from (end_pos - start_pos) x 1UL to 1UL x (end_pos - start_pos)
framework
::
DDim
dims
=
framework
::
make_ddim
({
1UL
,
end_pos
-
start_pos
});
x_i
.
Resize
(
dims
);
out_i
.
Resize
(
dims
);
math
::
SoftmaxFunctor
<
Place
,
T
>
()(
&
x_i
,
&
out_i
,
ctx
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录