Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
ee46d363
M
models
项目概览
PaddlePaddle
/
models
1 年多 前同步成功
通知
222
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
ee46d363
编写于
9月 13, 2017
作者:
R
ranqiu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
initial weight boot
上级
848bb8ab
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
15 addition
and
6 deletion
+15
-6
mt_with_external_memory/external_memory.py
mt_with_external_memory/external_memory.py
+5
-6
mt_with_external_memory/model.py
mt_with_external_memory/model.py
+10
-0
未找到文件。
mt_with_external_memory/external_memory.py
浏览文件 @
ee46d363
...
...
@@ -35,6 +35,8 @@ class ExternalMemory(object):
sequence layer has sequence length indicating the number
of memory slots, and size as memory slot size.
:type boot_layer: LayerOutput
:param initial_weight: Initializer for addressing weights.
:type initial_weight: LayerOutput
:param readonly: If true, the memory is read-only, and write function cannot
be called. Default is false.
:type readonly: bool
...
...
@@ -49,6 +51,7 @@ class ExternalMemory(object):
name
,
mem_slot_size
,
boot_layer
,
initial_weight
,
readonly
=
False
,
enable_interpolation
=
True
):
self
.
name
=
name
...
...
@@ -57,11 +60,7 @@ class ExternalMemory(object):
self
.
enable_interpolation
=
enable_interpolation
self
.
external_memory
=
paddle
.
layer
.
memory
(
name
=
self
.
name
,
size
=
self
.
mem_slot_size
,
boot_layer
=
boot_layer
)
# prepare a constant (zero) intializer for addressing weights
self
.
zero_addressing_init
=
paddle
.
layer
.
slope_intercept
(
input
=
paddle
.
layer
.
fc
(
input
=
boot_layer
,
size
=
1
),
slope
=
0.0
,
intercept
=
0.0
)
self
.
initial_weight
=
initial_weight
# set memory to constant when readonly=True
if
self
.
readonly
:
self
.
updated_external_memory
=
paddle
.
layer
.
mixed
(
...
...
@@ -111,7 +110,7 @@ class ExternalMemory(object):
last_addressing_weight
=
paddle
.
layer
.
memory
(
name
=
self
.
name
+
"_addressing_weight_"
+
head_name
,
size
=
1
,
boot_layer
=
self
.
zero_addressing_ini
t
)
boot_layer
=
self
.
initial_weigh
t
)
interpolated_weight
=
paddle
.
layer
.
interpolation
(
name
=
self
.
name
+
"_addressing_weight_"
+
head_name
,
input
=
[
addressing_weight
,
addressing_weight
],
...
...
mt_with_external_memory/model.py
浏览文件 @
ee46d363
...
...
@@ -125,7 +125,15 @@ def memory_enhanced_decoder(input, target, initial_state, source_context, size,
bounded_memory_perturbation
],
act
=
paddle
.
activation
.
Linear
())
bounded_memory_weight_init
=
paddle
.
layer
.
slope_intercept
(
input
=
paddle
.
layer
.
fc
(
input
=
bounded_memory_init
,
size
=
1
),
slope
=
0.0
,
intercept
=
0.0
)
unbounded_memory_init
=
source_context
unbounded_memory_weight_init
=
paddle
.
layer
.
slope_intercept
(
input
=
paddle
.
layer
.
fc
(
input
=
unbounded_memory_init
,
size
=
1
),
slope
=
0.0
,
intercept
=
0.0
)
# prepare step function for reccurent group
def
recurrent_decoder_step
(
cur_embedding
):
...
...
@@ -136,12 +144,14 @@ def memory_enhanced_decoder(input, target, initial_state, source_context, size,
name
=
"bounded_memory"
,
mem_slot_size
=
size
,
boot_layer
=
bounded_memory_init
,
initial_weight
=
bounded_memory_weight_init
,
readonly
=
False
,
enable_interpolation
=
True
)
unbounded_memory
=
ExternalMemory
(
name
=
"unbounded_memory"
,
mem_slot_size
=
size
*
2
,
boot_layer
=
unbounded_memory_init
,
initial_weight
=
unbounded_memory_weight_init
,
readonly
=
True
,
enable_interpolation
=
False
)
# write bounded memory
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录