Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
81d4a313
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看板
提交
81d4a313
编写于
11月 01, 2018
作者:
X
xuezhong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix bug for L2DecayRegularizer
上级
a01821e7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
17 addition
and
12 deletion
+17
-12
fluid/machine_reading_comprehension/run.py
fluid/machine_reading_comprehension/run.py
+17
-12
未找到文件。
fluid/machine_reading_comprehension/run.py
浏览文件 @
81d4a313
...
@@ -312,6 +312,15 @@ def validation(inference_program, avg_cost, s_probs, e_probs, match, feed_order,
...
@@ -312,6 +312,15 @@ def validation(inference_program, avg_cost, s_probs, e_probs, match, feed_order,
return
ave_loss
,
bleu_rouge
return
ave_loss
,
bleu_rouge
def
l2_loss
(
train_prog
):
param_list
=
train_prog
.
block
(
0
).
all_parameters
()
para_sum
=
[]
for
para
in
param_list
:
para_mul
=
fluid
.
layers
.
elementwise_mul
(
x
=
para
,
y
=
para
,
axis
=
0
)
para_sum
.
append
(
fluid
.
layers
.
reduce_sum
(
input
=
para_mul
,
dim
=
None
))
return
fluid
.
layers
.
sums
(
para_sum
)
*
0.5
def
train
(
logger
,
args
):
def
train
(
logger
,
args
):
logger
.
info
(
'Load data_set and vocab...'
)
logger
.
info
(
'Load data_set and vocab...'
)
with
open
(
os
.
path
.
join
(
args
.
vocab_dir
,
'vocab.data'
),
'rb'
)
as
fin
:
with
open
(
os
.
path
.
join
(
args
.
vocab_dir
,
'vocab.data'
),
'rb'
)
as
fin
:
...
@@ -349,24 +358,20 @@ def train(logger, args):
...
@@ -349,24 +358,20 @@ def train(logger, args):
# build optimizer
# build optimizer
if
args
.
optim
==
'sgd'
:
if
args
.
optim
==
'sgd'
:
optimizer
=
fluid
.
optimizer
.
SGD
(
optimizer
=
fluid
.
optimizer
.
SGD
(
learning_rate
=
args
.
learning_rate
,
learning_rate
=
args
.
learning_rate
)
regularization
=
fluid
.
regularizer
.
L2DecayRegularizer
(
regularization_coeff
=
args
.
weight_decay
))
elif
args
.
optim
==
'adam'
:
elif
args
.
optim
==
'adam'
:
optimizer
=
fluid
.
optimizer
.
Adam
(
optimizer
=
fluid
.
optimizer
.
Adam
(
learning_rate
=
args
.
learning_rate
,
learning_rate
=
args
.
learning_rate
)
regularization
=
fluid
.
regularizer
.
L2DecayRegularizer
(
regularization_coeff
=
args
.
weight_decay
))
elif
args
.
optim
==
'rprop'
:
elif
args
.
optim
==
'rprop'
:
optimizer
=
fluid
.
optimizer
.
RMSPropOptimizer
(
optimizer
=
fluid
.
optimizer
.
RMSPropOptimizer
(
learning_rate
=
args
.
learning_rate
,
learning_rate
=
args
.
learning_rate
)
regularization
=
fluid
.
regularizer
.
L2DecayRegularizer
(
regularization_coeff
=
args
.
weight_decay
))
else
:
else
:
logger
.
error
(
'Unsupported optimizer: {}'
.
format
(
args
.
optim
))
logger
.
error
(
'Unsupported optimizer: {}'
.
format
(
args
.
optim
))
exit
(
-
1
)
exit
(
-
1
)
optimizer
.
minimize
(
avg_cost
)
if
args
.
weight_decay
>
0.0
:
avg_cost_wd
=
avg_cost
+
args
.
weight_decay
*
l2_loss
(
main_program
)
optimizer
.
minimize
(
avg_cost_wd
)
# initialize parameters
# initialize parameters
place
=
core
.
CUDAPlace
(
0
)
if
args
.
use_gpu
else
core
.
CPUPlace
()
place
=
core
.
CUDAPlace
(
0
)
if
args
.
use_gpu
else
core
.
CPUPlace
()
...
@@ -406,7 +411,7 @@ def train(logger, args):
...
@@ -406,7 +411,7 @@ def train(logger, args):
feed_data
=
batch_reader
(
batch_list
,
args
)
feed_data
=
batch_reader
(
batch_list
,
args
)
fetch_outs
=
parallel_executor
.
run
(
fetch_outs
=
parallel_executor
.
run
(
feed
=
list
(
feeder
.
feed_parallel
(
feed_data
,
dev_count
)),
feed
=
list
(
feeder
.
feed_parallel
(
feed_data
,
dev_count
)),
fetch_list
=
[
avg_cost
.
name
],
fetch_list
=
[
avg_cost
_wd
.
name
],
return_numpy
=
False
)
return_numpy
=
False
)
cost_train
=
np
.
array
(
fetch_outs
[
0
]).
mean
()
cost_train
=
np
.
array
(
fetch_outs
[
0
]).
mean
()
total_num
+=
args
.
batch_size
*
dev_count
total_num
+=
args
.
batch_size
*
dev_count
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录