Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
6f08a219
P
Paddle
项目概览
机器未来
/
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看板
未验证
提交
6f08a219
编写于
12月 06, 2017
作者:
Y
Yan Chunwei
提交者:
GitHub
12月 06, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add gru unit layer wrapper (#6325)
上级
e09e21be
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
71 addition
and
0 deletion
+71
-0
python/paddle/v2/fluid/layers.py
python/paddle/v2/fluid/layers.py
+71
-0
未找到文件。
python/paddle/v2/fluid/layers.py
浏览文件 @
6f08a219
...
@@ -180,6 +180,77 @@ def dynamic_lstm(input,
...
@@ -180,6 +180,77 @@ def dynamic_lstm(input,
return
hidden
,
cell
return
hidden
,
cell
def
gru_unit
(
input
,
hidden
,
size
,
weight
=
None
,
bias
=
None
,
activation
=
'tanh'
,
gate_activation
=
'sigmoid'
,
main_program
=
None
,
startup_program
=
None
):
"""
GRUUnit Operator implements partial calculations of the GRU unit as following:
$$
update \ gate: u_t = actGate(xu_t + W_u * h_{t-1} + b_u)
\\
reset \ gate: r_t = actGate(xr_t + W_r * h_{t-1} + b_r)
\\
output \ candidate: {h}_t = actNode(xc_t + W_c * dot(r_t, h_{t-1}) + b_c)
\\
output: h_t = dot((1 - u_t), h_{t-1}) + dot(u_t, {h}_t)
$$
which is same as one time step of GRU Operator.
@note To implement the complete GRU unit, fully-connected operator must be
used before to feed xu, xr and xc as the Input of GRUUnit operator.
TODO(ChunweiYan) add more document here
"""
activation_dict
=
dict
(
identity
=
0
,
sigmoid
=
1
,
tanh
=
2
,
relu
=
3
,
)
activation
=
activation_dict
[
activation
]
gate_activation
=
activation_dict
[
gate_activation
]
helper
=
LayerHelper
(
'gru_unit'
,
**
locals
())
dtype
=
helper
.
input_dtype
()
size
=
size
/
3
# create weight
if
weight
is
None
:
weight
=
helper
.
create_parameter
(
attr
=
helper
.
param_attr
,
shape
=
[
size
,
3
*
size
],
dtype
=
dtype
)
# create bias
if
bias
is
None
:
bias_size
=
[
1
,
3
*
size
]
bias
=
helper
.
create_parameter
(
attr
=
helper
.
bias_attr
,
shape
=
bias_size
,
dtype
=
dtype
,
is_bias
=
True
)
gate
=
helper
.
create_tmp_variable
(
dtype
)
reset_hidden_pre
=
helper
.
create_tmp_variable
(
dtype
)
updated_hidden
=
helper
.
create_tmp_variable
(
dtype
)
helper
.
append_op
(
type
=
'gru_unit'
,
inputs
=
{
'Input'
:
input
,
'HiddenPrev'
:
hidden
,
'Weight'
:
weight
},
outputs
=
{
'Gate'
:
gate
,
'ResetHiddenPrev'
:
reset_hidden_pre
,
'Hidden'
:
updated_hidden
,
},
attrs
=
{
'activation'
:
0
,
'gate_activation'
:
1
,
})
return
updated_hidden
,
reset_hidden_pre
,
gate
def
data
(
name
,
def
data
(
name
,
shape
,
shape
,
append_batch_size
=
True
,
append_batch_size
=
True
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录