Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sven357
Paddle
提交
0b673756
P
Paddle
项目概览
sven357
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0b673756
编写于
2月 21, 2017
作者:
L
Luo Tao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add SequenceReshapeLayer in trainer_config_helpers
上级
14ee4b80
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
91 addition
and
6 deletion
+91
-6
doc/api/trainer_config_helpers/layers.rst
doc/api/trainer_config_helpers/layers.rst
+6
-0
paddle/gserver/layers/SequenceReshapeLayer.cpp
paddle/gserver/layers/SequenceReshapeLayer.cpp
+6
-3
python/paddle/trainer_config_helpers/layers.py
python/paddle/trainer_config_helpers/layers.py
+61
-0
python/paddle/trainer_config_helpers/tests/configs/file_list.sh
.../paddle/trainer_config_helpers/tests/configs/file_list.sh
+1
-1
python/paddle/trainer_config_helpers/tests/configs/protostr/test_seq_concat_reshape.protostr
...s/tests/configs/protostr/test_seq_concat_reshape.protostr
+12
-0
python/paddle/trainer_config_helpers/tests/configs/test_seq_concat_reshape.py
...r_config_helpers/tests/configs/test_seq_concat_reshape.py
+5
-2
未找到文件。
doc/api/trainer_config_helpers/layers.rst
浏览文件 @
0b673756
...
...
@@ -308,6 +308,12 @@ repeat_layer
:members: repeat_layer
:noindex:
seq_reshape_layer
-----------------
.. automodule:: paddle.trainer_config_helpers.layers
:members: seq_reshape_layer
:noindex:
Math Layers
===========
...
...
paddle/gserver/layers/SequenceReshapeLayer.cpp
浏览文件 @
0b673756
...
...
@@ -20,9 +20,12 @@ limitations under the License. */
namespace
paddle
{
/**
* A layer for reshaping the sequence
* Input: a sequence
* Output: a sequence
* A layer for reshaping the sequence. Assume the input sequence has
* T instances, the dimension of each instance is M, and the input
* reshape_dim is N, then the output sequence has T*M/N instances,
* the dimension of each instance is N.
*
* Note that T*M/N must be an integer.
*/
class
SequenceReshapeLayer
:
public
Layer
{
...
...
python/paddle/trainer_config_helpers/layers.py
浏览文件 @
0b673756
...
...
@@ -37,6 +37,7 @@ __all__ = [
"dotmul_projection"
,
"dotmul_operator"
,
"repeat_layer"
,
"seq_reshape_layer"
,
"table_projection"
,
"mixed_layer"
,
"data_layer"
,
...
...
@@ -125,6 +126,7 @@ class LayerType(object):
GRUMEMORY
=
"gated_recurrent"
SEQUENCE_LAST_INSTANCE
=
"seqlastins"
SEQUENCE_FIRST_INSTANCE
=
"seqfirstins"
SEQUENCE_RESHAPE
=
"seqreshape"
POOLING_MAX
=
"max"
POOLING_AVG
=
'average'
FC_LAYER
=
"fc"
...
...
@@ -1450,6 +1452,61 @@ def repeat_layer(input, num_repeats, name=None, layer_attr=None):
parents
=
[
input
])
@
wrap_name_default
(
"seqreshape"
)
@
wrap_act_default
(
act
=
IdentityActivation
())
@
wrap_bias_attr_default
(
has_bias
=
False
)
@
layer_support
()
def
seq_reshape_layer
(
input
,
reshape_size
,
act
=
None
,
name
=
None
,
layer_attr
=
None
,
bias_attr
=
None
):
"""
A layer for reshaping the sequence. Assume the input sequence has T instances,
the dimension of each instance is M, and the input reshape_size is N, then the
output sequence has T*M/N instances, the dimension of each instance is N.
Note that T*M/N must be an integer.
The example usage is:
.. code-block:: python
reshape = seq_reshape_layer(input=layer, reshape_size=4)
:param input: Input layer.
:type input: LayerOutput
:param reshape_size: the size of reshaped sequence.
:type reshape_size: int
:param name: Layer name.
:type name: basestring
:param act: Activation type.
:type act: BaseActivation
:param layer_attr: extra layer attributes.
:type layer_attr: ExtraLayerAttribute.
:param bias_attr: The Bias Attribute. If no bias, then pass False or
something not type of ParameterAttribute. None will get a
default Bias.
:type bias_attr: ParameterAttribute or None or bool
:return: LayerOutput object.
:rtype: LayerOutput
"""
Layer
(
inputs
=
[
input
.
name
],
name
=
name
,
size
=
reshape_size
,
type
=
LayerType
.
SEQUENCE_RESHAPE
,
bias
=
ParamAttr
.
to_bias
(
bias_attr
),
**
ExtraAttr
.
to_kwargs
(
layer_attr
))
return
LayerOutput
(
name
=
name
,
size
=
reshape_size
,
layer_type
=
LayerType
.
SEQUENCE_RESHAPE
,
parents
=
[
input
])
@
wrap_name_default
()
@
layer_support
()
def
interpolation_layer
(
input
,
weight
,
name
=
None
,
layer_attr
=
None
):
...
...
@@ -2604,6 +2661,10 @@ def seq_concat_layer(a, b, act=None, name=None, layer_attr=None,
:type act: BaseActivation
:param layer_attr: Extra Layer Attribute.
:type layer_attr: ExtraLayerAttribute
:param bias_attr: The Bias Attribute. If no bias, then pass False or
something not type of ParameterAttribute. None will get a
default Bias.
:type bias_attr: ParameterAttribute or None or bool
:return: LayerOutput object.
:rtype: LayerOutput
"""
...
...
python/paddle/trainer_config_helpers/tests/configs/file_list.sh
浏览文件 @
0b673756
...
...
@@ -5,6 +5,6 @@ last_first_seq test_expand_layer test_ntm_layers test_hsigmoid
img_layers img_trans_layers util_layers simple_rnn_layers unused_layers test_cost_layers
test_rnn_group shared_fc shared_lstm shared_gru test_cost_layers_with_weight
test_spp_layer test_bilinear_interp test_maxout test_bi_grumemory math_ops
test_seq_concat
)
test_seq_concat
_reshape
)
export
whole_configs
=(
test_split_datasource
)
python/paddle/trainer_config_helpers/tests/configs/protostr/test_seq_concat.protostr
→
python/paddle/trainer_config_helpers/tests/configs/protostr/test_seq_concat
_reshape
.protostr
浏览文件 @
0b673756
...
...
@@ -23,17 +23,29 @@ layers {
input_layer_name: "data2"
}
}
layers {
name: "__seqreshape_0__"
type: "seqreshape"
size: 5
active_type: "linear"
inputs {
input_layer_name: "data1"
}
}
input_layer_names: "data1"
input_layer_names: "data2"
output_layer_names: "__seqconcat_0__"
output_layer_names: "__seqreshape_0__"
sub_models {
name: "root"
layer_names: "data1"
layer_names: "data2"
layer_names: "__seqconcat_0__"
layer_names: "__seqreshape_0__"
input_layer_names: "data1"
input_layer_names: "data2"
output_layer_names: "__seqconcat_0__"
output_layer_names: "__seqreshape_0__"
is_recurrent_layer_group: false
}
python/paddle/trainer_config_helpers/tests/configs/test_seq_concat.py
→
python/paddle/trainer_config_helpers/tests/configs/test_seq_concat
_reshape
.py
浏览文件 @
0b673756
...
...
@@ -3,7 +3,10 @@ from paddle.trainer_config_helpers import *
settings
(
batch_size
=
1000
,
learning_rate
=
1e-5
)
din1
=
data_layer
(
name
=
'data1'
,
size
=
30
)
din2
=
data_layer
(
name
=
'data2'
,
size
=
30
)
outputs
(
seq_concat_layer
(
a
=
din1
,
b
=
din2
))
opts
=
[]
opts
.
append
(
seq_concat_layer
(
a
=
din1
,
b
=
din2
))
opts
.
append
(
seq_reshape_layer
(
input
=
din1
,
reshape_size
=
5
))
outputs
(
opts
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录