Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
6aece506
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6aece506
编写于
11月 23, 2016
作者:
Y
Yu Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Stash
上级
2d1c405b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
36 addition
and
44 deletion
+36
-44
doc_cn/algorithm/rnn/hrnn_rnn_api_compare.rst
doc_cn/algorithm/rnn/hrnn_rnn_api_compare.rst
+6
-5
paddle/gserver/tests/sequence_nest_rnn_multi_unequalength_inputs.py
...rver/tests/sequence_nest_rnn_multi_unequalength_inputs.py
+30
-39
未找到文件。
doc_cn/algorithm/rnn/hrnn_rnn_api_compare.rst
浏览文件 @
6aece506
...
...
@@ -139,20 +139,21 @@
本例中的配置,使用了单层\ :ref:`glossary_RNN`\ 和\ :ref:`glossary_双层RNN`\ 使用一个\ :code:`recurrent_group`\ 将两个序列同时过完全连接的\ :ref:`glossary_RNN`\ 。对于单层\ :ref:`glossary_RNN`\ 的code如下。
.. literalinclude:: ../../../paddle/gserver/tests/sequence_rnn_multi_unequalength_inputs.
conf
.. literalinclude:: ../../../paddle/gserver/tests/sequence_rnn_multi_unequalength_inputs.
py
:language: python
:lines: 4
1-58
:lines: 4
2-59
:linenos:
- 双层序列\:
- 双层RNN中,对输入的两个特征分别求时序上的连续全连接(`inner_step1`和`inner_step2`分别处理fea1和fea2),其功能与示例2中`sequence_nest_rnn.conf`的`outer_step`函数完全相同。不同之处是,此时输入`[SubsequenceInput(emb1), SubsequenceInput(emb2)]`在各时刻并不等长。
- 函数`outer_step`中可以分别处理这两个特征,但我们需要用
<font color=red>targetInlink</font>
指定recurrent_group的输出的格式(各子句长度)只能和其中一个保持一致,如这里选择了和emb2的长度一致。
- 函数`outer_step`中可以分别处理这两个特征,但我们需要用
\ :red:`targetInlink`\
指定recurrent_group的输出的格式(各子句长度)只能和其中一个保持一致,如这里选择了和emb2的长度一致。
- 最后,依然是取encoder1_rep的最后一个时刻和encoder2_rep的所有时刻分别相加得到context。
.. literalinclude:: ../../../paddle/gserver/tests/sequence_nest_rnn_multi_unequalength_inputs.
conf
.. literalinclude:: ../../../paddle/gserver/tests/sequence_nest_rnn_multi_unequalength_inputs.
py
:language: python
:lines: 41-89
:lines: 42-75, 82-89
:linenos:
示例4:beam_search的生成
========================
...
...
paddle/gserver/tests/sequence_nest_rnn_multi_unequalength_inputs.py
浏览文件 @
6aece506
#edit-mode: -*- python -*-
#
edit-mode: -*- python -*-
# Copyright (c) 2016 Baidu, Inc. All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
...
...
@@ -35,46 +35,37 @@ speaker2 = data_layer(name="word2", size=dict_dim)
emb1
=
embedding_layer
(
input
=
speaker1
,
size
=
word_dim
)
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
# This hierarchical 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
)
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
)
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
)
return
out
encoder1
=
recurrent_group
(
step
=
inner_step1
,
name
=
'inner1'
,
input
=
x1
)
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'
)
index
=
[
0
]
def
inner_step
(
ipt
):
index
[
0
]
+=
1
i
=
index
[
0
]
outer_mem
=
memory
(
name
=
"outer_rnn_state_%d"
%
i
,
size
=
hidden_dim
)
def
inner_step_impl
(
y
):
inner_mem
=
memory
(
name
=
"inner_rnn_state_"
+
y
.
name
,
size
=
hidden_dim
,
boot_layer
=
outer_mem
)
out
=
fc_layer
(
input
=
[
y
,
inner_mem
],
size
=
hidden_dim
,
act
=
TanhActivation
(),
bias_attr
=
True
,
name
=
'inner_rnn_state_'
+
y
.
name
)
return
out
encoder
=
recurrent_group
(
step
=
inner_step_impl
,
name
=
'inner_%d'
%
i
,
input
=
ipt
)
last
=
last_seq
(
name
=
"outer_rnn_state_%d"
%
i
,
input
=
encoder
)
return
encoder
,
last
_
,
sentence_last_state1
=
inner_step
(
ipt
=
x1
)
encoder2
,
_
=
inner_step
(
ipt
=
x2
)
encoder1_expand
=
expand_layer
(
input
=
sentence_last_state1
,
expand_as
=
encoder2
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录