Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
c0ecd5c4
P
Paddle
项目概览
Crayon鑫
/
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看板
提交
c0ecd5c4
编写于
7月 31, 2017
作者:
C
caoying03
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add config helper.
上级
0973c2c9
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
163 addition
and
98 deletion
+163
-98
proto/ModelConfig.proto
proto/ModelConfig.proto
+2
-0
python/paddle/trainer/config_parser.py
python/paddle/trainer/config_parser.py
+19
-0
python/paddle/trainer_config_helpers/layers.py
python/paddle/trainer_config_helpers/layers.py
+69
-97
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_select_layers.protostr
...rs/tests/configs/protostr/test_seq_select_layers.protostr
+63
-0
python/paddle/trainer_config_helpers/tests/configs/test_seq_select_layers.py
...er_config_helpers/tests/configs/test_seq_select_layers.py
+9
-0
未找到文件。
proto/ModelConfig.proto
浏览文件 @
c0ecd5c4
...
...
@@ -482,6 +482,8 @@ 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
浏览文件 @
c0ecd5c4
...
...
@@ -2614,6 +2614,25 @@ class SubSequenceLayer(LayerBase):
self
.
create_bias_parameter
(
bias
,
size
)
@
config_layer
(
'sub_nested_seq'
)
class
SubNestedSequenceLayer
(
LayerBase
):
def
__init__
(
self
,
name
,
inputs
,
top_k
=
1
,
bias
=
False
,
**
xargs
):
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. '
))
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
):
def
__init__
(
self
,
name
,
inputs
,
device
=
None
):
...
...
python/paddle/trainer_config_helpers/layers.py
浏览文件 @
c0ecd5c4
...
...
@@ -31,103 +31,33 @@ except ImportError:
import
copy
__all__
=
[
'full_matrix_projection'
,
'AggregateLevel'
,
'ExpandLevel'
,
'identity_projection'
,
'dotmul_projection'
,
'dotmul_operator'
,
'repeat_layer'
,
'seq_reshape_layer'
,
'table_projection'
,
'mixed_layer'
,
'data_layer'
,
'embedding_layer'
,
'fc_layer'
,
'grumemory'
,
'pooling_layer'
,
'lstmemory'
,
'last_seq'
,
'first_seq'
,
'cos_sim'
,
'hsigmoid'
,
'conv_projection'
,
'mse_cost'
,
'regression_cost'
,
'classification_cost'
,
'LayerOutput'
,
'img_conv_layer'
,
'img_pool_layer'
,
'batch_norm_layer'
,
'img_cmrnorm_layer'
,
'addto_layer'
,
'concat_layer'
,
'seq_concat_layer'
,
'lstm_step_layer'
,
'recurrent_group'
,
'memory'
,
'StaticInput'
,
'expand_layer'
,
'scaling_layer'
,
'scaling_projection'
,
'power_layer'
,
'interpolation_layer'
,
'bilinear_interp_layer'
,
'trans_layer'
,
'rotate_layer'
,
'sum_to_one_norm_layer'
,
'get_output_layer'
,
'LayerType'
,
'context_projection'
,
'beam_search'
,
'maxid_layer'
,
'GeneratedInput'
,
'SubsequenceInput'
,
'gru_step_layer'
,
'gru_step_naive_layer'
,
'recurrent_layer'
,
'BaseGeneratedInput'
,
'conv_operator'
,
'conv_shift_layer'
,
'tensor_layer'
,
'selective_fc_layer'
,
'sampling_id_layer'
,
'slope_intercept_layer'
,
'trans_full_matrix_projection'
,
'linear_comb_layer'
,
'convex_comb_layer'
,
'ctc_layer'
,
'warp_ctc_layer'
,
'crf_layer'
,
'crf_decoding_layer'
,
'nce_layer'
,
'cross_entropy_with_selfnorm'
,
'cross_entropy'
,
'multi_binary_label_cross_entropy'
,
'sum_cost'
,
'rank_cost'
,
'lambda_cost'
,
'huber_cost'
,
'block_expand_layer'
,
'maxout_layer'
,
'out_prod_layer'
,
'printer_layer'
,
'print_layer'
,
'priorbox_layer'
,
'cross_channel_norm_layer'
,
'multibox_loss_layer'
,
'detection_output_layer'
,
'spp_layer'
,
'pad_layer'
,
'eos_layer'
,
'smooth_l1_cost'
,
'layer_support'
,
'multiplex_layer'
,
'row_conv_layer'
,
'dropout_layer'
,
'prelu_layer'
,
'gated_unit_layer'
,
'crop_layer'
,
'full_matrix_projection'
,
'AggregateLevel'
,
'ExpandLevel'
,
'identity_projection'
,
'dotmul_projection'
,
'dotmul_operator'
,
'repeat_layer'
,
'seq_reshape_layer'
,
'table_projection'
,
'mixed_layer'
,
'data_layer'
,
'embedding_layer'
,
'fc_layer'
,
'grumemory'
,
'pooling_layer'
,
'lstmemory'
,
'last_seq'
,
'first_seq'
,
'cos_sim'
,
'hsigmoid'
,
'conv_projection'
,
'mse_cost'
,
'regression_cost'
,
'classification_cost'
,
'LayerOutput'
,
'img_conv_layer'
,
'img_pool_layer'
,
'batch_norm_layer'
,
'img_cmrnorm_layer'
,
'addto_layer'
,
'concat_layer'
,
'seq_concat_layer'
,
'lstm_step_layer'
,
'recurrent_group'
,
'memory'
,
'StaticInput'
,
'expand_layer'
,
'scaling_layer'
,
'scaling_projection'
,
'power_layer'
,
'interpolation_layer'
,
'bilinear_interp_layer'
,
'trans_layer'
,
'rotate_layer'
,
'sum_to_one_norm_layer'
,
'get_output_layer'
,
'LayerType'
,
'context_projection'
,
'beam_search'
,
'maxid_layer'
,
'GeneratedInput'
,
'SubsequenceInput'
,
'gru_step_layer'
,
'gru_step_naive_layer'
,
'recurrent_layer'
,
'BaseGeneratedInput'
,
'conv_operator'
,
'conv_shift_layer'
,
'tensor_layer'
,
'selective_fc_layer'
,
'sampling_id_layer'
,
'slope_intercept_layer'
,
'trans_full_matrix_projection'
,
'linear_comb_layer'
,
'convex_comb_layer'
,
'ctc_layer'
,
'warp_ctc_layer'
,
'crf_layer'
,
'crf_decoding_layer'
,
'nce_layer'
,
'cross_entropy_with_selfnorm'
,
'cross_entropy'
,
'multi_binary_label_cross_entropy'
,
'sum_cost'
,
'rank_cost'
,
'lambda_cost'
,
'huber_cost'
,
'block_expand_layer'
,
'maxout_layer'
,
'out_prod_layer'
,
'printer_layer'
,
'print_layer'
,
'priorbox_layer'
,
'cross_channel_norm_layer'
,
'multibox_loss_layer'
,
'detection_output_layer'
,
'spp_layer'
,
'pad_layer'
,
'eos_layer'
,
'smooth_l1_cost'
,
'layer_support'
,
'multiplex_layer'
,
'row_conv_layer'
,
'dropout_layer'
,
'prelu_layer'
,
'gated_unit_layer'
,
'crop_layer'
,
'sub_nested_seq_layer'
]
...
...
@@ -220,6 +150,7 @@ class LayerType(object):
PRELU
=
'prelu'
CROP_LAYER
=
'crop'
SUB_NESTED_SEQ
=
'sub_nested_seq'
@
staticmethod
def
is_layer_type
(
type_name
):
...
...
@@ -6006,3 +5937,44 @@ def crop_layer(input, offset, axis=2, shape=None, name=None, layer_attr=None):
layer_type
=
LayerType
.
CROP_LAYER
,
parents
=
input
,
size
=
l
.
config
.
size
)
@
wrap_name_default
()
@
layer_support
()
def
sub_nested_seq_layer
(
input
,
name
=
None
,
top_k
=
1
):
"""
The sub_nest_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.
Then sub_nest_seq_layer selects top k sentences with highest scores or
probabilites according to the second input.
The example usage is:
.. code-block:: python
prob = fc_layer(input=data, size=1, act=SequenceSoftmaxActivation())
sub_nest_seq = sub_nest_seq_layer(input=[data, prob], top_k=3)
: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.
: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.'
)
l
=
Layer
(
inputs
=
[
x
.
name
for
x
in
input
],
name
=
name
,
top_k
=
top_k
,
type
=
LayerType
.
SUB_NESTED_SEQ
)
return
LayerOutput
(
name
=
name
,
layer_type
=
LayerType
.
SUB_NESTED_SEQ
,
parents
=
input
,
size
=
l
.
config
.
size
)
python/paddle/trainer_config_helpers/tests/configs/file_list.sh
浏览文件 @
c0ecd5c4
...
...
@@ -7,6 +7,6 @@ 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_reshape test_pad test_smooth_l1 test_multiplex_layer
test_prelu_layer test_row_conv test_detection_output_layer test_multibox_loss_layer
test_recursive_topology test_gated_unit_layer
)
test_recursive_topology test_gated_unit_layer
test_seq_select_layers
)
export
whole_configs
=(
test_split_datasource
)
python/paddle/trainer_config_helpers/tests/configs/protostr/test_seq_select_layers.protostr
0 → 100644
浏览文件 @
c0ecd5c4
type: "nn"
layers {
name: "input"
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"
}
layers {
name: "__sub_nested_seq_layer_0__"
type: "sub_nested_seq"
size: 300
active_type: ""
inputs {
input_layer_name: "input"
}
inputs {
input_layer_name: "__fc_layer_0__"
}
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"
output_layer_names: "__sub_nested_seq_layer_0__"
sub_models {
name: "root"
layer_names: "input"
layer_names: "__fc_layer_0__"
layer_names: "__sub_nested_seq_layer_0__"
input_layer_names: "input"
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
0 → 100644
浏览文件 @
c0ecd5c4
#!/usr/bin/env python
#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
)
outputs
(
sub_nest_seq
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录