Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
0b7d82be
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
0b7d82be
编写于
8月 31, 2018
作者:
C
chenweihang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
doc: refine English description
上级
0c4697f8
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
37 addition
and
17 deletion
+37
-17
paddle/fluid/operators/sequence_enumerate_op.cc
paddle/fluid/operators/sequence_enumerate_op.cc
+7
-8
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+8
-9
python/paddle/fluid/tests/unittests/test_sequence_enumerate_op.py
...addle/fluid/tests/unittests/test_sequence_enumerate_op.py
+22
-0
未找到文件。
paddle/fluid/operators/sequence_enumerate_op.cc
浏览文件 @
0b7d82be
...
...
@@ -50,24 +50,23 @@ class SequenceEnumerateOpMaker : public framework::OpProtoAndCheckerMaker {
"(2-D LoDTensor with the 2nd dimension equal to 1) "
"Input LoDTensor of SequenceEnumerate operator."
);
AddOutput
(
"Out"
,
"(2-D LoDTensor with the 2nd dimension equal to
1
) "
"(2-D LoDTensor with the 2nd dimension equal to
win_size
) "
"Output LoDTensor of SequenceEnumerate operator."
);
AddAttr
<
int
>
(
"win_size"
,
"(int) The enumerate sequence window size."
)
.
AddCustomChecker
([](
const
int
&
win_size
)
{
PADDLE_ENFORCE
(
win_size
>=
2
,
"The window size should be
greater
than 2."
);
"The window size should be
not less
than 2."
);
});
AddAttr
<
int
>
(
"pad_value"
,
"(int) The enumerate sequence padding value."
)
.
SetDefault
(
0
);
AddComment
(
R"DOC(
Sequence Enumerate Operator.
Sequence enumerate operator generate a new LoDTensor
with the same 1st dimension length as the original LoDTensor,
and with the 2nd dimension equal to the input window length,
the new sub-sequence on 2nd dimension is enumerated one by one on the original sequence.
The values of the last insufficient part areall filled with the input pad_value.
Generate a new sequence for the input index sequence, which enumerates all the
sub-sequences with length win_size of the input.
The enumerated sequence has the same 1st dimension with variable input, and
the 2nd dimension is win_size, padded by pad_value if necessary in generation.
Examples:
Case 1:
Input:
...
...
python/paddle/fluid/layers/nn.py
浏览文件 @
0b7d82be
...
...
@@ -5522,13 +5522,12 @@ def flatten(x, axis=1, name=None):
return
out
def
sequence_enumerate
(
input
,
win_size
,
pad_value
,
name
=
None
):
def
sequence_enumerate
(
input
,
win_size
,
pad_value
=
0
,
name
=
None
):
"""
Generate a new LoDTensor
with the same 1st dimension length as the original LoDTensor,
and with the 2nd dimension equal to the input window length,
the new sub-sequence on 2nd dimension is enumerated one by one on the original sequence.
The values of the last insufficient part areall filled with the input pad_value.
Generate a new sequence for the input index sequence, which enumerates all the
sub-sequences with length win_size of the input.
The enumerated sequence has the same 1st dimension with variable input, and
the 2nd dimension is win_size, padded by pad_value if necessary in generation.
Examples:
Case 1:
...
...
@@ -5545,9 +5544,9 @@ def sequence_enumerate(input, win_size, pad_value, name=None):
Out.dims = [5, 2]
Args:
input (Variable): The input variable which is a
LoDTensor
win_size (int): The
enumerate sequence window size
.
pad_value (int): The
enumerate sequence padding value
.
input (Variable): The input variable which is a
index sequence.
win_size (int): The
window size for enumerating all sub-sequences
.
pad_value (int): The
padding value, default 0
.
Returns:
Variable: The enumerate sequence variable which is a LoDTensor.
...
...
python/paddle/fluid/tests/unittests/test_sequence_enumerate_op.py
浏览文件 @
0b7d82be
...
...
@@ -68,6 +68,17 @@ class TesSequenceEnumerateOpInt64(TestSequenceEnumerateOp):
self
.
out_seq
=
np
.
array
(
out_seq
).
astype
(
"int64"
)
class
TestSequenceEnumerateOpLargeWinSize
(
TestSequenceEnumerateOp
):
def
init_test_case
(
self
):
self
.
in_seq
=
np
.
random
.
randint
(
0
,
10
,
(
30
,
1
)).
astype
(
"int32"
)
self
.
lod
=
[[
9
,
4
,
11
,
6
]]
self
.
win_size
=
5
self
.
pad_value
=
0
out_seq
=
sequence_enumerate
(
self
.
in_seq
,
self
.
lod
,
self
.
win_size
,
self
.
pad_value
)
self
.
out_seq
=
np
.
array
(
out_seq
).
astype
(
"int32"
)
class
TestSequenceEnumerateOpMaxWinSize
(
TestSequenceEnumerateOp
):
def
init_test_case
(
self
):
self
.
in_seq
=
np
.
random
.
randint
(
0
,
10
,
(
30
,
1
)).
astype
(
"int32"
)
...
...
@@ -79,5 +90,16 @@ class TestSequenceEnumerateOpMaxWinSize(TestSequenceEnumerateOp):
self
.
out_seq
=
np
.
array
(
out_seq
).
astype
(
"int32"
)
class
TestSequenceEnumerateOpLargePadValue
(
TestSequenceEnumerateOp
):
def
init_test_case
(
self
):
self
.
in_seq
=
np
.
random
.
randint
(
0
,
10
,
(
30
,
1
)).
astype
(
"int32"
)
self
.
lod
=
[[
9
,
4
,
11
,
6
]]
self
.
win_size
=
5
self
.
pad_value
=
5
out_seq
=
sequence_enumerate
(
self
.
in_seq
,
self
.
lod
,
self
.
win_size
,
self
.
pad_value
)
self
.
out_seq
=
np
.
array
(
out_seq
).
astype
(
"int32"
)
if
__name__
==
"__main__"
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录