Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
83ce2dce
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看板
提交
83ce2dce
编写于
8月 05, 2017
作者:
C
caoying03
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
split sorting into another layer. fix config helper.
上级
00b6d266
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
51 addition
and
67 deletion
+51
-67
proto/ModelConfig.proto
proto/ModelConfig.proto
+0
-2
python/paddle/trainer/config_parser.py
python/paddle/trainer/config_parser.py
+17
-11
python/paddle/trainer_config_helpers/layers.py
python/paddle/trainer_config_helpers/layers.py
+19
-15
python/paddle/trainer_config_helpers/tests/configs/protostr/test_seq_select_layers.protostr
...rs/tests/configs/protostr/test_seq_select_layers.protostr
+10
-36
python/paddle/trainer_config_helpers/tests/configs/test_seq_select_layers.py
...er_config_helpers/tests/configs/test_seq_select_layers.py
+5
-3
未找到文件。
proto/ModelConfig.proto
浏览文件 @
83ce2dce
...
...
@@ -497,8 +497,6 @@ message LayerConfig {
repeated
uint32
offset
=
55
;
repeated
uint32
shape
=
56
;
// for sub_nest_seq layer to select top k sequence with highest scores
optional
uint32
top_k
=
57
[
default
=
1
];
}
message
EvaluatorConfig
{
...
...
python/paddle/trainer/config_parser.py
浏览文件 @
83ce2dce
...
...
@@ -2659,22 +2659,28 @@ class SubSequenceLayer(LayerBase):
@
config_layer
(
'sub_nested_seq'
)
class
SubNestedSequenceLayer
(
LayerBase
):
def
__init__
(
self
,
name
,
inputs
,
top_k
=
1
,
bias
=
False
,
**
xargs
):
def
__init__
(
self
,
name
,
inputs
,
selected_indices
,
bias
=
False
,
**
xargs
):
if
isinstance
(
inputs
,
list
):
assert
len
(
inputs
)
==
1
,
(
'the first input of sub_nested_seq '
'layer is a single nested sequence.'
)
inputs
=
inputs
[
0
]
if
isinstance
(
selected_indices
,
list
):
assert
len
(
selected_indices
)
==
1
,
(
'the second input of '
'sub_nested_seq layer is a single layer which is a '
'set of selected indices.'
)
selected_indices
=
selected_indices
[
0
]
super
(
SubNestedSequenceLayer
,
self
).
__init__
(
name
,
'sub_nested_seq'
,
0
,
inputs
=
inputs
,
**
xargs
)
config_assert
(
len
(
inputs
)
==
2
,
(
'SubNestSequenceLayer must have 2 inputs: '
'input1 is a nested sequence; input2 is a learnable distribution '
'or scores over each sentence in the nested sequence. '
))
name
,
'sub_nested_seq'
,
0
,
inputs
=
[
inputs
,
selected_indices
],
**
xargs
)
input_layer0
=
self
.
get_input_layer
(
0
)
size
=
input_layer0
.
size
self
.
set_layer_size
(
size
)
self
.
config
.
top_k
=
top_k
input_layer1
=
self
.
get_input_layer
(
1
)
assert
(
input_layer1
.
size
==
1
)
@
config_layer
(
'out_prod'
)
class
OuterProdLayer
(
LayerBase
):
...
...
python/paddle/trainer_config_helpers/layers.py
浏览文件 @
83ce2dce
...
...
@@ -6092,37 +6092,41 @@ def crop_layer(input, offset, axis=2, shape=None, name=None, layer_attr=None):
@
wrap_name_default
()
@
layer_support
()
def
sub_nested_seq_layer
(
input
,
name
=
None
,
top_k
=
1
):
def
sub_nested_seq_layer
(
input
,
selected_indices
,
name
=
None
):
"""
The sub_nested_seq_layer accepts two inputs: the first one is a nested
sequence in PaddlePaddle; the second one is a learnable score or
distribution over each sequence in the nested sequence.
sequence; the second one is a set of selceted indices in the nested sequence.
Then sub_nest_seq_layer selects top k sentences with highest scores or
probabilites according to the second input.
Then sub_nest_seq_layer selects trims the first input according to the
selected indices to give a new output. This layer is used in beam training.
The example usage is:
.. code-block:: python
prob = fc_layer(input=data, size=1, act=SequenceSoftmaxActivation()
)
sub_nest_seq = sub_nested_seq_layer(input=[data, prob], top_k=3)
sub_nest_seq = sub_nested_seq_layer(input=[data, selected_indices]
)
:param input: The two input layers. The first input must be a nested
sequence. The second input is a learnable scores, whose size must be 1.
:param input: A nested sequence.
:type input: LayerOutput
:param selected_indices: a set of sequence indices in the nested sequence.
:type input: LayerOutput
:param name: name of this layer.
:type name: basestring
:param top_k: number of sequences with highest probabilies to select.
:type top_k: int
:return: LayerOutput object.
:rtype: LayerOutput
"""
assert
isinstance
(
input
,
collections
.
Sequence
)
and
len
(
input
)
==
2
,
(
'sub_nest_seq_layer has exactly two inputs.'
)
assert
isinstance
(
input
,
LayerOutput
),
(
'The first input of '
'sub_nested_seq_layer must be a Paddle layer.'
)
assert
isinstance
(
selected_indices
,
LayerOutput
),
(
'The second input of '
'sub_nested_seq_layer must be a Paddle layer.'
)
l
=
Layer
(
inputs
=
[
x
.
name
for
x
in
input
],
inputs
=
input
.
name
,
selected_indices
=
selected_indices
.
name
,
name
=
name
,
top_k
=
top_k
,
type
=
LayerType
.
SUB_NESTED_SEQ
)
return
LayerOutput
(
name
=
name
,
...
...
python/paddle/trainer_config_helpers/tests/configs/protostr/test_seq_select_layers.protostr
浏览文件 @
83ce2dce
type: "nn"
layers {
name: "input"
name: "input
_seq
"
type: "data"
size: 300
active_type: ""
}
layers {
name: "__fc_layer_0__"
type: "fc"
size: 1
active_type: "sequence_softmax"
inputs {
input_layer_name: "input"
input_parameter_name: "___fc_layer_0__.w0"
}
bias_parameter_name: "___fc_layer_0__.wbias"
name: "input"
type: "data"
size: 5
active_type: ""
}
layers {
name: "__sub_nested_seq_layer_0__"
...
...
@@ -22,41 +17,20 @@ layers {
size: 300
active_type: ""
inputs {
input_layer_name: "input"
input_layer_name: "input
_seq
"
}
inputs {
input_layer_name: "
__fc_layer_0__
"
input_layer_name: "
input
"
}
top_k: 1
}
parameters {
name: "___fc_layer_0__.w0"
size: 300
initial_mean: 0.0
initial_std: 0.057735026919
dims: 300
dims: 1
initial_strategy: 0
initial_smart: true
}
parameters {
name: "___fc_layer_0__.wbias"
size: 1
initial_mean: 0.0
initial_std: 0.0
dims: 1
dims: 1
initial_strategy: 0
initial_smart: false
}
input_layer_names: "input"
input_layer_names: "input
_seq
"
output_layer_names: "__sub_nested_seq_layer_0__"
sub_models {
name: "root"
layer_names: "input_seq"
layer_names: "input"
layer_names: "__fc_layer_0__"
layer_names: "__sub_nested_seq_layer_0__"
input_layer_names: "input"
input_layer_names: "input
_seq
"
output_layer_names: "__sub_nested_seq_layer_0__"
is_recurrent_layer_group: false
}
...
...
python/paddle/trainer_config_helpers/tests/configs/test_seq_select_layers.py
浏览文件 @
83ce2dce
...
...
@@ -2,8 +2,10 @@
#coding=utf-8
from
paddle.trainer_config_helpers
import
*
data
=
data_layer
(
name
=
'input'
,
size
=
300
)
prob
=
fc_layer
(
input
=
data
,
size
=
1
,
act
=
SequenceSoftmaxActivation
())
sub_nest_seq
=
sub_nested_seq_layer
(
input
=
[
data
,
prob
],
top_k
=
1
)
beam_size
=
5
data
=
data_layer
(
name
=
'input_seq'
,
size
=
300
)
selected_ids
=
data_layer
(
name
=
'input'
,
size
=
beam_size
)
sub_nest_seq
=
sub_nested_seq_layer
(
input
=
data
,
selected_indices
=
selected_ids
)
outputs
(
sub_nest_seq
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录