Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
da7c0f13
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
694
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
da7c0f13
编写于
11月 23, 2016
作者:
Y
Yu Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Format sequence_nest_rnn_multi_unequalength*.conf
上级
0c981164
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
151 addition
and
43 deletion
+151
-43
paddle/gserver/tests/sequence_nest_rnn_multi_unequalength_inputs.py
...rver/tests/sequence_nest_rnn_multi_unequalength_inputs.py
+107
-0
paddle/gserver/tests/sequence_rnn_multi_unequalength_inputs.py
...e/gserver/tests/sequence_rnn_multi_unequalength_inputs.py
+35
-33
paddle/gserver/tests/test_RecurrentGradientMachine.cpp
paddle/gserver/tests/test_RecurrentGradientMachine.cpp
+9
-10
未找到文件。
paddle/gserver/tests/sequence_nest_rnn_multi_unequalength_inputs.
conf
→
paddle/gserver/tests/sequence_nest_rnn_multi_unequalength_inputs.
py
浏览文件 @
da7c0f13
...
...
@@ -16,11 +16,11 @@
from
paddle.trainer_config_helpers
import
*
######################## data source ################################
define_py_data_sources2
(
train_list
=
'gserver/tests/Sequence/dummy.list'
,
test_list
=
None
,
module
=
'rnn_data_provider'
,
obj
=
'process_unequalength_subseq'
)
define_py_data_sources2
(
train_list
=
'gserver/tests/Sequence/dummy.list'
,
test_list
=
None
,
module
=
'rnn_data_provider'
,
obj
=
'process_unequalength_subseq'
)
settings
(
batch_size
=
2
,
learning_rate
=
0.01
)
######################## network configure ################################
...
...
@@ -38,46 +38,46 @@ emb2 = embedding_layer(input=speaker2, size=word_dim)
# This hierachical RNN is designed to be equivalent to the simple RNN in
# sequence_rnn_multi_unequalength_inputs.conf
def
outer_step
(
x1
,
x2
):
outer_mem1
=
memory
(
name
=
"outer_rnn_state1"
,
size
=
hidden_dim
)
outer_mem2
=
memory
(
name
=
"outer_rnn_state2"
,
size
=
hidden_dim
)
outer_mem1
=
memory
(
name
=
"outer_rnn_state1"
,
size
=
hidden_dim
)
outer_mem2
=
memory
(
name
=
"outer_rnn_state2"
,
size
=
hidden_dim
)
def
inner_step1
(
y
):
inner_mem
=
memory
(
name
=
'inner_rnn_state_'
+
y
.
name
,
size
=
hidden_dim
,
boot_layer
=
outer_mem1
)
out
=
fc_layer
(
input
= [
y
,
inner_mem
],
size
=
hidden_dim
,
act
=
TanhActivation
(),
bias_attr
=
True
,
name
=
'inner_rnn_state_'
+
y
.
name
)
inner_mem
=
memory
(
name
=
'inner_rnn_state_'
+
y
.
name
,
size
=
hidden_dim
,
boot_layer
=
outer_mem1
)
out
=
fc_layer
(
input
=
[
y
,
inner_mem
],
size
=
hidden_dim
,
act
=
TanhActivation
(),
bias_attr
=
True
,
name
=
'inner_rnn_state_'
+
y
.
name
)
return
out
def
inner_step2
(
y
):
inner_mem
=
memory
(
name
=
'inner_rnn_state_'
+
y
.
name
,
size
=
hidden_dim
,
boot_layer
=
outer_mem2
)
out
=
fc_layer
(
input
= [
y
,
inner_mem
],
size
=
hidden_dim
,
act
=
TanhActivation
(),
bias_attr
=
True
,
name
=
'inner_rnn_state_'
+
y
.
name
)
inner_mem
=
memory
(
name
=
'inner_rnn_state_'
+
y
.
name
,
size
=
hidden_dim
,
boot_layer
=
outer_mem2
)
out
=
fc_layer
(
input
=
[
y
,
inner_mem
],
size
=
hidden_dim
,
act
=
TanhActivation
(),
bias_attr
=
True
,
name
=
'inner_rnn_state_'
+
y
.
name
)
return
out
encoder1
=
recurrent_group
(
step
=
inner_step1
,
name
=
'inner1'
,
input
=
x1
)
encoder1
=
recurrent_group
(
step
=
inner_step1
,
name
=
'inner1'
,
input
=
x1
)
encoder2
=
recurrent_group
(
step
=
inner_step2
,
name
=
'inner2'
,
input
=
x2
)
encoder2
=
recurrent_group
(
step
=
inner_step2
,
name
=
'inner2'
,
input
=
x2
)
sentence_last_state1
=
last_seq
(
input
=
encoder1
,
name
=
'outer_rnn_state1'
)
sentence_last_state2_
=
last_seq
(
input
=
encoder2
,
name
=
'outer_rnn_state2'
)
sentence_last_state1
=
last_seq
(
input
=
encoder1
,
name
=
'outer_rnn_state1'
)
sentence_last_state2_
=
last_seq
(
input
=
encoder2
,
name
=
'outer_rnn_state2'
)
encoder1_expand
=
expand_layer
(
input
=
sentence_last_state1
,
expand_as
=
encoder2
)
encoder1_expand
=
expand_layer
(
input
=
sentence_last_state1
,
expand_as
=
encoder2
)
return
[
encoder1_expand
,
encoder2
]
...
...
@@ -88,19 +88,20 @@ encoder1_rep, encoder2_rep = recurrent_group(
input
=
[
SubsequenceInput
(
emb1
),
SubsequenceInput
(
emb2
)],
targetInlink
=
emb2
)
encoder1_last
=
last_seq
(
input
=
encoder1_rep
)
encoder1_expandlast
=
expand_layer
(
input
=
encoder1_last
,
expand_as
=
encoder2_rep
)
context
=
mixed_layer
(
input
= [
identity_projection
(
encoder1_expandlast
),
identity_projection
(
encoder2_rep
)],
size
=
hidden_dim
)
encoder1_last
=
last_seq
(
input
=
encoder1_rep
)
encoder1_expandlast
=
expand_layer
(
input
=
encoder1_last
,
expand_as
=
encoder2_rep
)
context
=
mixed_layer
(
input
=
[
identity_projection
(
encoder1_expandlast
),
identity_projection
(
encoder2_rep
)
],
size
=
hidden_dim
)
rep
=
last_seq
(
input
=
context
)
prob
=
fc_layer
(
size
=
label_dim
,
input
=
rep
,
act
=
SoftmaxActivation
(),
bias_attr
=
True
)
outputs
(
classification_cost
(
input
=
prob
,
label
=
data_layer
(
name
=
"label"
,
size
=
label_dim
)))
prob
=
fc_layer
(
size
=
label_dim
,
input
=
rep
,
act
=
SoftmaxActivation
(),
bias_attr
=
True
)
outputs
(
classification_cost
(
input
=
prob
,
label
=
data_layer
(
name
=
"label"
,
size
=
label_dim
)))
paddle/gserver/tests/sequence_rnn_multi_unequalength_inputs.
conf
→
paddle/gserver/tests/sequence_rnn_multi_unequalength_inputs.
py
浏览文件 @
da7c0f13
...
...
@@ -16,11 +16,11 @@
from
paddle.trainer_config_helpers
import
*
######################## data source ################################
define_py_data_sources2
(
train_list
=
'gserver/tests/Sequence/dummy.list'
,
test_list
=
None
,
module
=
'rnn_data_provider'
,
obj
=
'process_unequalength_seq'
)
define_py_data_sources2
(
train_list
=
'gserver/tests/Sequence/dummy.list'
,
test_list
=
None
,
module
=
'rnn_data_provider'
,
obj
=
'process_unequalength_seq'
)
settings
(
batch_size
=
2
,
learning_rate
=
0.01
)
######################## network configure ################################
...
...
@@ -38,38 +38,40 @@ emb2 = embedding_layer(input=speaker2, size=word_dim)
# This hierachical RNN is designed to be equivalent to the RNN in
# sequence_nest_rnn_multi_unequalength_inputs.conf
def
step
(
x1
,
x2
):
def
calrnn
(
y
):
mem
=
memory
(
name
=
'rnn_state_'
+
y
.
name
,
size
=
hidden_dim
)
out
=
fc_layer
(
input
= [
y
,
mem
],
size
=
hidden_dim
,
act
=
TanhActivation
(),
bias_attr
=
True
,
name
=
'rnn_state_'
+
y
.
name
)
return
out
encoder1
=
calrnn
(
x1
)
encoder2
=
calrnn
(
x2
)
return
[
encoder1
,
encoder2
]
def
calrnn
(
y
):
mem
=
memory
(
name
=
'rnn_state_'
+
y
.
name
,
size
=
hidden_dim
)
out
=
fc_layer
(
input
=
[
y
,
mem
],
size
=
hidden_dim
,
act
=
TanhActivation
(),
bias_attr
=
True
,
name
=
'rnn_state_'
+
y
.
name
)
return
out
encoder1
=
calrnn
(
x1
)
encoder2
=
calrnn
(
x2
)
return
[
encoder1
,
encoder2
]
encoder1_rep
,
encoder2_rep
=
recurrent_group
(
name
=
"stepout"
,
step
=
step
,
input
=[
emb1
,
emb2
])
name
=
"stepout"
,
step
=
step
,
input
=
[
emb1
,
emb2
])
encoder1_last
=
last_seq
(
input
=
encoder1_rep
)
encoder1_expandlast
=
expand_layer
(
input
=
encoder1_last
,
expand_as
=
encoder2_rep
)
context
=
mixed_layer
(
input
= [
identity_projection
(
encoder1_expandlast
),
identity_projection
(
encoder2_rep
)],
size
=
hidden_dim
)
encoder1_last
=
last_seq
(
input
=
encoder1_rep
)
encoder1_expandlast
=
expand_layer
(
input
=
encoder1_last
,
expand_as
=
encoder2_rep
)
context
=
mixed_layer
(
input
=
[
identity_projection
(
encoder1_expandlast
),
identity_projection
(
encoder2_rep
)
],
size
=
hidden_dim
)
rep
=
last_seq
(
input
=
context
)
prob
=
fc_layer
(
size
=
label_dim
,
input
=
rep
,
act
=
SoftmaxActivation
(),
bias_attr
=
True
)
outputs
(
classification_cost
(
input
=
prob
,
label
=
data_layer
(
name
=
"label"
,
size
=
label_dim
)))
prob
=
fc_layer
(
size
=
label_dim
,
input
=
rep
,
act
=
SoftmaxActivation
(),
bias_attr
=
True
)
outputs
(
classification_cost
(
input
=
prob
,
label
=
data_layer
(
name
=
"label"
,
size
=
label_dim
)))
paddle/gserver/tests/test_RecurrentGradientMachine.cpp
浏览文件 @
da7c0f13
...
...
@@ -13,12 +13,12 @@ See the License for the specific language governing permissions and
limitations under the License. */
#include <gtest/gtest.h>
#include <paddle/utils/Util.h>
#include <paddle/utils/Version.h>
#include <paddle/utils/PythonUtil.h>
#include <paddle/gserver/gradientmachines/GradientMachine.h>
#include <paddle/trainer/Trainer.h>
#include <paddle/trainer/TrainerInternal.h>
#include <paddle/gserver/gradientmachines/GradientMachine.h>
#include <paddle/utils/PythonUtil.h>
#include <paddle/utils/Util.h>
#include <paddle/utils/Version.h>
P_DECLARE_int32
(
seed
);
...
...
@@ -45,10 +45,9 @@ public:
auto
p
=
const_cast
<
TrainerForTest
*>
(
this
);
auto
&
params
=
p
->
getGradientMachine
()
->
getParameters
();
return
std
::
accumulate
(
params
.
begin
(),
params
.
end
(),
0UL
,
[](
size_t
a
,
const
ParameterPtr
&
p
)
{
return
a
+
p
->
getSize
();
});
params
.
begin
(),
params
.
end
(),
0UL
,
[](
size_t
a
,
const
ParameterPtr
&
p
)
{
return
a
+
p
->
getSize
();
});
}
};
...
...
@@ -148,8 +147,8 @@ TEST(RecurrentGradientMachine, rnn_multi_input) {
TEST
(
RecurrentGradientMachine
,
rnn_multi_unequalength_input
)
{
for
(
bool
useGpu
:
{
false
,
true
})
{
test
(
"gserver/tests/sequence_rnn_multi_unequalength_inputs.
conf
"
,
"gserver/tests/sequence_nest_rnn_multi_unequalength_inputs.
conf
"
,
test
(
"gserver/tests/sequence_rnn_multi_unequalength_inputs.
py
"
,
"gserver/tests/sequence_nest_rnn_multi_unequalength_inputs.
py
"
,
1e-6
,
useGpu
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录