Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
48f5612b
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看板
提交
48f5612b
编写于
4月 16, 2018
作者:
G
gongweibao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
clearnup
上级
6fc711cd
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
22 addition
and
1 deletion
+22
-1
fluid/neural_machine_translation/transformer_nist_base/nmt_fluid.py
...al_machine_translation/transformer_nist_base/nmt_fluid.py
+21
-1
fluid/neural_machine_translation/transformer_nist_base/optim.py
...neural_machine_translation/transformer_nist_base/optim.py
+1
-0
未找到文件。
fluid/neural_machine_translation/transformer_nist_base/nmt_fluid.py
浏览文件 @
48f5612b
...
@@ -173,6 +173,14 @@ def prepare_batch_input(insts, input_data_names, src_pad_idx, trg_pad_idx,
...
@@ -173,6 +173,14 @@ def prepare_batch_input(insts, input_data_names, src_pad_idx, trg_pad_idx,
return
input_dict
return
input_dict
def
get_var
(
name
,
value
):
return
fluid
.
layers
.
create_global_var
(
name
=
name
,
shape
=
[
1
],
value
=
float
(
value
),
dtype
=
"float32"
,
persistable
=
True
)
def
main
():
def
main
():
place
=
core
.
CPUPlace
()
if
args
.
device
==
'CPU'
else
core
.
CUDAPlace
(
place
=
core
.
CPUPlace
()
if
args
.
device
==
'CPU'
else
core
.
CUDAPlace
(
args
.
device_id
)
args
.
device_id
)
...
@@ -185,11 +193,21 @@ def main():
...
@@ -185,11 +193,21 @@ def main():
ModelHyperParams
.
d_value
,
ModelHyperParams
.
d_model
,
ModelHyperParams
.
d_value
,
ModelHyperParams
.
d_model
,
ModelHyperParams
.
d_inner_hid
,
ModelHyperParams
.
dropout
)
ModelHyperParams
.
d_inner_hid
,
ModelHyperParams
.
dropout
)
'''
lr_scheduler = LearningRateScheduler(ModelHyperParams.d_model,
lr_scheduler = LearningRateScheduler(ModelHyperParams.d_model,
TrainTaskConfig.warmup_steps, place,
TrainTaskConfig.warmup_steps, place,
TrainTaskConfig.learning_rate)
TrainTaskConfig.learning_rate)
'''
warmup_steps
=
get_var
(
"warmup_steps"
,
value
=
TrainTaskConfig
.
warmup_steps
)
d_model
=
get_var
(
"d_model"
,
value
=
ModelHyperParams
.
d_model
)
lr_decay
=
fluid
.
layers
\
.
learning_rate_scheduler
\
.
nmt_nist_decay
(
d_model
,
warmup_steps
)
optimizer
=
fluid
.
optimizer
.
Adam
(
optimizer
=
fluid
.
optimizer
.
Adam
(
learning_rate
=
lr_scheduler
.
learning_rate
,
learning_rate
=
lr_decay
,
beta1
=
TrainTaskConfig
.
beta1
,
beta1
=
TrainTaskConfig
.
beta1
,
beta2
=
TrainTaskConfig
.
beta2
,
beta2
=
TrainTaskConfig
.
beta2
,
epsilon
=
TrainTaskConfig
.
eps
)
epsilon
=
TrainTaskConfig
.
eps
)
...
@@ -251,8 +269,10 @@ def main():
...
@@ -251,8 +269,10 @@ def main():
label_data_names
,
ModelHyperParams
.
eos_idx
,
label_data_names
,
ModelHyperParams
.
eos_idx
,
ModelHyperParams
.
eos_idx
,
ModelHyperParams
.
n_head
,
ModelHyperParams
.
eos_idx
,
ModelHyperParams
.
n_head
,
ModelHyperParams
.
d_model
)
ModelHyperParams
.
d_model
)
'''
if args.local:
if args.local:
lr_scheduler.update_learning_rate(data_input)
lr_scheduler.update_learning_rate(data_input)
'''
outs
=
exe
.
run
(
trainer_prog
,
outs
=
exe
.
run
(
trainer_prog
,
feed
=
data_input
,
feed
=
data_input
,
fetch_list
=
[
sum_cost
,
avg_cost
],
fetch_list
=
[
sum_cost
,
avg_cost
],
...
...
fluid/neural_machine_translation/transformer_nist_base/optim.py
浏览文件 @
48f5612b
...
@@ -39,3 +39,4 @@ class LearningRateScheduler(object):
...
@@ -39,3 +39,4 @@ class LearningRateScheduler(object):
lr_tensor
.
set
(
np
.
array
([
lr_value
],
dtype
=
"float32"
),
self
.
place
)
lr_tensor
.
set
(
np
.
array
([
lr_value
],
dtype
=
"float32"
),
self
.
place
)
data_input
[
self
.
learning_rate
.
name
]
=
lr_tensor
data_input
[
self
.
learning_rate
.
name
]
=
lr_tensor
layers
.
Print
(
self
.
learning_rate
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录