Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
29520d77
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
29520d77
编写于
5月 26, 2017
作者:
C
Cao Ying
提交者:
GitHub
5月 26, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2273 from luotao1/reverse
Expose the "reverse" argument for recurrent_group in V2 API.
上级
62149e1e
0ee31a03
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
11 addition
and
8 deletion
+11
-8
python/paddle/v2/layer.py
python/paddle/v2/layer.py
+8
-6
python/paddle/v2/tests/test_rnn_layer.py
python/paddle/v2/tests/test_rnn_layer.py
+3
-2
未找到文件。
python/paddle/v2/layer.py
浏览文件 @
29520d77
...
...
@@ -360,7 +360,7 @@ mixed.__doc__ = conf_helps.mixed_layer.__doc__
class
RecurrentLayerInput
(
Layer
):
def
__init__
(
self
,
recurrent_name
,
index
,
parent_layers
):
def
__init__
(
self
,
recurrent_name
,
index
,
parent_layers
,
reverse
):
parents_len
=
len
(
parent_layers
)
assert
parents_len
<=
1
if
parents_len
==
0
:
...
...
@@ -368,6 +368,7 @@ class RecurrentLayerInput(Layer):
else
:
self
.
__parents__
=
parent_layers
.
values
()[
0
]
self
.
__recurrent_name__
=
recurrent_name
self
.
__reverse__
=
reverse
name
=
self
.
__parents__
[
index
].
name
if
index
>=
0
else
self
.
context_name
()
super
(
RecurrentLayerInput
,
self
).
__init__
(
...
...
@@ -380,7 +381,8 @@ class RecurrentLayerInput(Layer):
model_type
(
'recurrent_nn'
)
RecurrentLayerGroupWithoutOutLinksBegin
(
name
=
self
.
__recurrent_name__
,
in_links
=
map
(
lambda
x
:
x
.
name
,
self
.
__parents__
))
in_links
=
map
(
lambda
x
:
x
.
name
,
self
.
__parents__
),
seq_reversed
=
self
.
__reverse__
)
return
self
...
...
@@ -461,7 +463,7 @@ del each_layer_name
@
wrap_name_default
()
def
recurrent_group
(
step
,
input
,
name
=
None
):
def
recurrent_group
(
step
,
input
,
reverse
=
False
,
name
=
None
):
if
not
isinstance
(
input
,
collections
.
Sequence
):
input
=
[
input
]
...
...
@@ -471,14 +473,14 @@ def recurrent_group(step, input, name=None):
RecurrentLayerInput
(
recurrent_name
=
name
,
index
=
i
,
parent_layers
=
{
'recurrent_inputs'
:
non_static_inputs
}
)
for
i
in
xrange
(
len
(
non_static_inputs
))
parent_layers
=
{
'recurrent_inputs'
:
non_static_inputs
}
,
reverse
=
reverse
)
for
i
in
xrange
(
len
(
non_static_inputs
))
]
extra_input
=
None
if
len
(
non_static_inputs
)
==
0
:
extra_input
=
RecurrentLayerInput
(
recurrent_name
=
name
,
index
=-
1
,
parent_layers
=
{})
recurrent_name
=
name
,
index
=-
1
,
parent_layers
=
{}
,
reverse
=
reverse
)
def
__real_step__
(
*
args
):
rnn_input
=
list
(
args
)
...
...
python/paddle/v2/tests/test_rnn_layer.py
浏览文件 @
29520d77
...
...
@@ -42,7 +42,8 @@ class RNNTest(unittest.TestCase):
def
test
():
data
=
conf_helps
.
data_layer
(
name
=
"word"
,
size
=
dict_dim
)
embd
=
conf_helps
.
embedding_layer
(
input
=
data
,
size
=
word_dim
)
conf_helps
.
recurrent_group
(
name
=
"rnn"
,
step
=
step
,
input
=
embd
)
conf_helps
.
recurrent_group
(
name
=
"rnn"
,
step
=
step
,
input
=
embd
,
reverse
=
True
)
return
str
(
parse_network
(
test
))
...
...
@@ -60,7 +61,7 @@ class RNNTest(unittest.TestCase):
name
=
"word"
,
type
=
data_type
.
integer_value
(
dict_dim
))
embd
=
layer
.
embedding
(
input
=
data
,
size
=
word_dim
)
rnn_layer
=
layer
.
recurrent_group
(
name
=
"rnn"
,
step
=
new_step
,
input
=
embd
)
name
=
"rnn"
,
step
=
new_step
,
input
=
embd
,
reverse
=
True
)
return
str
(
layer
.
parse_network
(
rnn_layer
))
diff
=
difflib
.
unified_diff
(
parse_old_rnn
().
splitlines
(
1
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录