Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
68c68ec9
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
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看板
提交
68c68ec9
编写于
6月 01, 2017
作者:
E
emailweixu
提交者:
GitHub
6月 01, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2218 from luotao1/rename
rename AggregateLevel and ExpandLevel
上级
303d2663
630b27ec
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
45 addition
and
37 deletion
+45
-37
doc/howto/deep_model/rnn/hierarchical_layer_cn.rst
doc/howto/deep_model/rnn/hierarchical_layer_cn.rst
+8
-8
doc/howto/deep_model/rnn/hrnn_rnn_api_compare_cn.rst
doc/howto/deep_model/rnn/hrnn_rnn_api_compare_cn.rst
+1
-1
paddle/gserver/tests/sequence_nest_layer_group.conf
paddle/gserver/tests/sequence_nest_layer_group.conf
+2
-2
python/paddle/trainer_config_helpers/layers.py
python/paddle/trainer_config_helpers/layers.py
+25
-20
python/paddle/trainer_config_helpers/tests/configs/last_first_seq.py
...le/trainer_config_helpers/tests/configs/last_first_seq.py
+3
-2
python/paddle/trainer_config_helpers/tests/configs/test_expand_layer.py
...trainer_config_helpers/tests/configs/test_expand_layer.py
+3
-1
python/paddle/trainer_config_helpers/tests/configs/test_sequence_pooling.py
...ner_config_helpers/tests/configs/test_sequence_pooling.py
+1
-1
python/paddle/v2/tests/test_layer.py
python/paddle/v2/tests/test_layer.py
+2
-2
未找到文件。
doc/howto/deep_model/rnn/hierarchical_layer_cn.rst
浏览文件 @
68c68ec9
...
...
@@ -28,17 +28,17 @@ pooling 的使用示例如下,详细见 :ref:`api_v2.layer_pooling` 配置API
seq_pool = pooling(input=layer,
pooling_type=pooling.Max(),
agg_level=AggregateLevel.
EACH
_SEQUENCE)
agg_level=AggregateLevel.
TO
_SEQUENCE)
- `pooling_type` 目前支持两种,分别是:pooling.Max()和pooling.Avg()。
- `agg_level=AggregateLevel.
EACH_TIMESTEP
` 时(默认值):
- `agg_level=AggregateLevel.
TO_NO_SEQUENCE
` 时(默认值):
- 作用:双层序列经过运算变成一个0层序列,或单层序列经过运算变成一个0层序列
- 输入:一个双层序列,或一个单层序列
- 输出:一个0层序列,即整个输入序列(单层或双层)的平均值(或最大值)
- `agg_level=AggregateLevel.
EACH
_SEQUENCE` 时:
- `agg_level=AggregateLevel.
TO
_SEQUENCE` 时:
- 作用:一个双层序列经过运算变成一个单层序列
- 输入:必须是一个双层序列
...
...
@@ -52,15 +52,15 @@ last_seq 的使用示例如下( :ref:`api_v2.layer_first_seq` 类似),详
.. code-block:: bash
last = last_seq(input=layer,
agg_level=AggregateLevel.
EACH
_SEQUENCE)
agg_level=AggregateLevel.
TO
_SEQUENCE)
- `agg_level=AggregateLevel.
EACH_TIMESTEP
` 时(默认值):
- `agg_level=AggregateLevel.
TO_NO_SEQUENCE
` 时(默认值):
- 作用:一个双层序列经过运算变成一个0层序列,或一个单层序列经过运算变成一个0层序列
- 输入:一个双层序列或一个单层序列
- 输出:一个0层序列,即整个输入序列(双层或者单层)最后一个,或第一个元素。
- `agg_level=AggregateLevel.
EACH
_SEQUENCE` 时:
- `agg_level=AggregateLevel.
TO
_SEQUENCE` 时:
- 作用:一个双层序列经过运算变成一个单层序列
- 输入:必须是一个双层序列
- 输出:一个单层序列,其中每个元素是双层序列中每个subseq最后一个(或第一个)元素。
...
...
@@ -74,9 +74,9 @@ expand 的使用示例如下,详细见 :ref:`api_v2.layer_expand` 配置API。
ex = expand(input=layer1,
expand_as=layer2,
expand_level=ExpandLevel.FROM_
TIMESTEP
)
expand_level=ExpandLevel.FROM_
NO_SEQUENCE
)
- `expand_level=ExpandLevel.FROM_
TIMESTEP
` 时(默认值):
- `expand_level=ExpandLevel.FROM_
NO_SEQUENCE
` 时(默认值):
- 作用:一个0层序列经过运算扩展成一个单层序列,或者一个双层序列
- 输入:layer1必须是一个0层序列,是待扩展的数据;layer2 可以是一个单层序列,或者是一个双层序列,提供扩展的长度信息
...
...
doc/howto/deep_model/rnn/hrnn_rnn_api_compare_cn.rst
浏览文件 @
68c68ec9
...
...
@@ -81,7 +81,7 @@
* 在本例中,我们将原始数据的每一组,通过\ :code:`recurrent_group`\ 进行拆解,拆解成的每一句话再通过一个LSTM网络。这和单层RNN的配置是等价的。
* 与单层RNN的配置类似,我们只需要使用LSTM encode成的最后一个向量。所以对\ :code:`recurrent_group`\ 进行了\ :code:`last_seq`\ 操作。但和单层RNN不同,我们是对每一个子序列取最后一个元素,因此\ :code:`agg_level=AggregateLevel.
EACH
_SEQUENCE`\ 。
* 与单层RNN的配置类似,我们只需要使用LSTM encode成的最后一个向量。所以对\ :code:`recurrent_group`\ 进行了\ :code:`last_seq`\ 操作。但和单层RNN不同,我们是对每一个子序列取最后一个元素,因此\ :code:`agg_level=AggregateLevel.
TO
_SEQUENCE`\ 。
* 至此,\ :code:`lstm_last`\ 便和单层RNN配置中的\ :code:`lstm_last`\ 具有相同的结果了。
...
...
paddle/gserver/tests/sequence_nest_layer_group.conf
浏览文件 @
68c68ec9
...
...
@@ -59,7 +59,7 @@ lstm_nest_group = recurrent_group(
input
=
SubsequenceInput
(
emb_group
),
step
=
lstm_group
,
name
=
"lstm_nest_group"
)
# hasSubseq ->(seqlastins) seq
lstm_last
=
last_seq
(
input
=
lstm_nest_group
,
agg_level
=
AggregateLevel
.
EACH
_SEQUENCE
)
input
=
lstm_nest_group
,
agg_level
=
AggregateLevel
.
TO
_SEQUENCE
)
# seq ->(expand) hasSubseq
lstm_expand
=
expand_layer
(
...
...
@@ -71,7 +71,7 @@ lstm_expand = expand_layer(
lstm_average
=
pooling_layer
(
input
=
lstm_expand
,
pooling_type
=
AvgPooling
(),
agg_level
=
AggregateLevel
.
EACH
_SEQUENCE
)
agg_level
=
AggregateLevel
.
TO
_SEQUENCE
)
with
mixed_layer
(
size
=
label_dim
,
act
=
SoftmaxActivation
(),
bias_attr
=
True
)
as
output
:
...
...
python/paddle/trainer_config_helpers/layers.py
浏览文件 @
68c68ec9
...
...
@@ -237,16 +237,19 @@ class AggregateLevel(object):
Accordingly, AggregateLevel supports two modes:
- :code:`AggregateLevel.
EACH_TIMESTEP
` means the aggregation acts on each
- :code:`AggregateLevel.
TO_NO_SEQUENCE
` means the aggregation acts on each
timestep of a sequence, both :code:`SUB_SEQUENCE` and :code:`SEQUENCE` will
be aggregated to :code:`NO_SEQUENCE`.
- :code:`AggregateLevel.
EACH
_SEQUENCE` means the aggregation acts on each
- :code:`AggregateLevel.
TO
_SEQUENCE` means the aggregation acts on each
sequence of a nested sequence, :code:`SUB_SEQUENCE` will be aggregated to
:code:`SEQUENCE`.
"""
EACH_TIMESTEP
=
'non-seq'
EACH_SEQUENCE
=
'seq'
TO_NO_SEQUENCE
=
'non-seq'
TO_SEQUENCE
=
'seq'
# compatible with previous configuration
EACH_TIMESTEP
=
TO_NO_SEQUENCE
EACH_SEQUENCE
=
TO_SEQUENCE
class
LayerOutput
(
object
):
...
...
@@ -1083,7 +1086,7 @@ def pooling_layer(input,
pooling_type
=
None
,
name
=
None
,
bias_attr
=
None
,
agg_level
=
AggregateLevel
.
EACH_TIMESTEP
,
agg_level
=
AggregateLevel
.
TO_NO_SEQUENCE
,
layer_attr
=
None
):
"""
Pooling layer for sequence inputs, not used for Image.
...
...
@@ -1094,10 +1097,10 @@ def pooling_layer(input,
seq_pool = pooling_layer(input=layer,
pooling_type=AvgPooling(),
agg_level=AggregateLevel.
EACH
_SEQUENCE)
agg_level=AggregateLevel.
TO_NO
_SEQUENCE)
:param agg_level: AggregateLevel.
EACH_TIMESTEP
or
AggregateLevel.
EACH
_SEQUENCE
:param agg_level: AggregateLevel.
TO_NO_SEQUENCE
or
AggregateLevel.
TO
_SEQUENCE
:type agg_level: AggregateLevel
:param name: layer name.
:type name: basestring
...
...
@@ -1367,7 +1370,7 @@ def grumemory(input,
@
layer_support
()
def
last_seq
(
input
,
name
=
None
,
agg_level
=
AggregateLevel
.
EACH_TIMESTEP
,
agg_level
=
AggregateLevel
.
TO_NO_SEQUENCE
,
stride
=-
1
,
layer_attr
=
None
):
"""
...
...
@@ -1402,7 +1405,7 @@ def last_seq(input,
" series information at all. Maybe you want to use"
" first_seq instead."
)
if
agg_level
==
AggregateLevel
.
EACH
_SEQUENCE
:
if
agg_level
==
AggregateLevel
.
TO
_SEQUENCE
:
assert
stride
==
-
1
Layer
(
...
...
@@ -1423,7 +1426,7 @@ def last_seq(input,
@
layer_support
()
def
first_seq
(
input
,
name
=
None
,
agg_level
=
AggregateLevel
.
EACH_TIMESTEP
,
agg_level
=
AggregateLevel
.
TO_NO_SEQUENCE
,
stride
=-
1
,
layer_attr
=
None
):
"""
...
...
@@ -1459,7 +1462,7 @@ def first_seq(input,
' time series information at all. Maybe you want to use'
' last_seq instead.'
)
if
agg_level
==
AggregateLevel
.
EACH
_SEQUENCE
:
if
agg_level
==
AggregateLevel
.
TO
_SEQUENCE
:
assert
stride
==
-
1
Layer
(
...
...
@@ -1482,16 +1485,18 @@ class ExpandLevel(object):
ExpandLevel supports two modes:
- :code:`ExpandLevel.FROM_
TIMESTEP` means the expandation acts on each
timestep of a sequence, :code:`NO_SEQUENCE`
will be expanded to
- :code:`ExpandLevel.FROM_
NO_SEQUENCE` means the expansion acts on
:code:`NO_SEQUENCE`, which
will be expanded to
:code:`SEQUENCE` or :code:`SUB_SEQUENCE`.
- :code:`ExpandLevel.FROM_SEQUENCE` means the expan
dation acts on each
sequence of a nested sequence, :code:`SEQUENCE`
will be expanded to
- :code:`ExpandLevel.FROM_SEQUENCE` means the expan
sion acts on
:code:`SEQUENCE`, which
will be expanded to
:code:`SUB_SEQUENCE`.
"""
FROM_TIMESTEP
=
AggregateLevel
.
EACH_TIMESTEP
FROM_SEQUENCE
=
AggregateLevel
.
EACH_SEQUENCE
FROM_NO_SEQUENCE
=
AggregateLevel
.
TO_NO_SEQUENCE
FROM_SEQUENCE
=
AggregateLevel
.
TO_SEQUENCE
# compatible with previous configuration
FROM_TIMESTEP
=
FROM_NO_SEQUENCE
@
wrap_name_default
()
...
...
@@ -1500,7 +1505,7 @@ def expand_layer(input,
expand_as
,
name
=
None
,
bias_attr
=
False
,
expand_level
=
ExpandLevel
.
FROM_
TIMESTEP
,
expand_level
=
ExpandLevel
.
FROM_
NO_SEQUENCE
,
layer_attr
=
None
):
"""
A layer for "Expand Dense data or (sequence data where the length of each
...
...
@@ -1512,7 +1517,7 @@ def expand_layer(input,
expand = expand_layer(input=layer1,
expand_as=layer2,
expand_level=ExpandLevel.FROM_
TIMESTEP
)
expand_level=ExpandLevel.FROM_
NO_SEQUENCE
)
:param input: Input layer
:type input: LayerOutput
...
...
python/paddle/trainer_config_helpers/tests/configs/last_first_seq.py
浏览文件 @
68c68ec9
...
...
@@ -6,7 +6,7 @@ din = data_layer(name='data', size=30)
seq_op
=
[
first_seq
,
last_seq
]
agg_level
=
[
AggregateLevel
.
EACH_SEQUENCE
,
AggregateLevel
.
EACH_TIMESTEP
]
agg_level
=
[
AggregateLevel
.
TO_SEQUENCE
,
AggregateLevel
.
TO_NO_SEQUENCE
]
opts
=
[]
...
...
@@ -15,6 +15,7 @@ for op in seq_op:
opts
.
append
(
op
(
input
=
din
,
agg_level
=
al
))
for
op
in
seq_op
:
opts
.
append
(
op
(
input
=
din
,
agg_level
=
AggregateLevel
.
EACH_TIMESTEP
,
stride
=
5
))
opts
.
append
(
op
(
input
=
din
,
agg_level
=
AggregateLevel
.
TO_NO_SEQUENCE
,
stride
=
5
))
outputs
(
opts
)
python/paddle/trainer_config_helpers/tests/configs/test_expand_layer.py
浏览文件 @
68c68ec9
...
...
@@ -9,4 +9,6 @@ outputs(
expand_layer
(
input
=
din
,
expand_as
=
data_seq
,
expand_level
=
ExpandLevel
.
FROM_SEQUENCE
),
expand_layer
(
input
=
din
,
expand_as
=
data_seq
,
expand_level
=
ExpandLevel
.
FROM_TIMESTEP
))
input
=
din
,
expand_as
=
data_seq
,
expand_level
=
ExpandLevel
.
FROM_NO_SEQUENCE
))
python/paddle/trainer_config_helpers/tests/configs/test_sequence_pooling.py
浏览文件 @
68c68ec9
...
...
@@ -6,7 +6,7 @@ din = data_layer(name='dat_in', size=100)
POOL_TYPE
=
[
MaxPooling
,
AvgPooling
,
SumPooling
]
AGG_LEVEL
=
[
AggregateLevel
.
EACH_SEQUENCE
,
AggregateLevel
.
EACH_TIMESTEP
]
AGG_LEVEL
=
[
AggregateLevel
.
TO_SEQUENCE
,
AggregateLevel
.
TO_NO_SEQUENCE
]
opts
=
[]
...
...
python/paddle/v2/tests/test_layer.py
浏览文件 @
68c68ec9
...
...
@@ -73,7 +73,7 @@ class AggregateLayerTest(unittest.TestCase):
pool
=
layer
.
pooling
(
input
=
pixel
,
pooling_type
=
pooling
.
Avg
(),
agg_level
=
layer
.
AggregateLevel
.
EACH
_SEQUENCE
)
agg_level
=
layer
.
AggregateLevel
.
TO
_SEQUENCE
)
last_seq
=
layer
.
last_seq
(
input
=
pixel
)
first_seq
=
layer
.
first_seq
(
input
=
pixel
)
concat
=
layer
.
concat
(
input
=
[
last_seq
,
first_seq
])
...
...
@@ -109,7 +109,7 @@ class ReshapeLayerTest(unittest.TestCase):
expand
=
layer
.
expand
(
input
=
weight
,
expand_as
=
pixel
,
expand_level
=
layer
.
ExpandLevel
.
FROM_
TIMESTEP
)
expand_level
=
layer
.
ExpandLevel
.
FROM_
NO_SEQUENCE
)
repeat
=
layer
.
repeat
(
input
=
pixel
,
num_repeats
=
4
)
reshape
=
layer
.
seq_reshape
(
input
=
pixel
,
reshape_size
=
4
)
rotate
=
layer
.
rotate
(
input
=
pixel
,
height
=
16
,
width
=
49
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录