Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
24cb7dfe
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看板
提交
24cb7dfe
编写于
9月 29, 2018
作者:
X
xuezhong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add weight decay
上级
3e82ae13
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
22 addition
and
4 deletion
+22
-4
fluid/machine_reading_comprehesion/args.py
fluid/machine_reading_comprehesion/args.py
+5
-0
fluid/machine_reading_comprehesion/run.py
fluid/machine_reading_comprehesion/run.py
+17
-4
未找到文件。
fluid/machine_reading_comprehesion/args.py
浏览文件 @
24cb7dfe
...
@@ -58,6 +58,11 @@ def parse_args():
...
@@ -58,6 +58,11 @@ def parse_args():
type
=
float
,
type
=
float
,
default
=
0.001
,
default
=
0.001
,
help
=
"Learning rate used to train the model. (default: %(default)f)"
)
help
=
"Learning rate used to train the model. (default: %(default)f)"
)
parser
.
add_argument
(
"--weight_decay"
,
type
=
float
,
default
=
0.001
,
help
=
"Weight decay. (default: %(default)f)"
)
parser
.
add_argument
(
parser
.
add_argument
(
"--use_gpu"
,
"--use_gpu"
,
type
=
distutils
.
util
.
strtobool
,
type
=
distutils
.
util
.
strtobool
,
...
...
fluid/machine_reading_comprehesion/run.py
浏览文件 @
24cb7dfe
...
@@ -21,6 +21,7 @@ import time
...
@@ -21,6 +21,7 @@ import time
import
os
import
os
import
random
import
random
import
json
import
json
import
six
import
paddle
import
paddle
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
...
@@ -209,6 +210,8 @@ def validation(inference_program, avg_cost, s_probs, e_probs, feed_order, place,
...
@@ -209,6 +210,8 @@ def validation(inference_program, avg_cost, s_probs, e_probs, feed_order, place,
'yesno_answers'
:
[]
'yesno_answers'
:
[]
})
})
if
args
.
result_dir
is
not
None
and
args
.
result_name
is
not
None
:
if
args
.
result_dir
is
not
None
and
args
.
result_name
is
not
None
:
if
not
os
.
path
.
exists
(
args
.
result_dir
):
os
.
makedirs
(
args
.
result_dir
)
result_file
=
os
.
path
.
join
(
args
.
result_dir
,
args
.
result_name
+
'.json'
)
result_file
=
os
.
path
.
join
(
args
.
result_dir
,
args
.
result_name
+
'.json'
)
with
open
(
result_file
,
'w'
)
as
fout
:
with
open
(
result_file
,
'w'
)
as
fout
:
for
pred_answer
in
pred_answers
:
for
pred_answer
in
pred_answers
:
...
@@ -235,7 +238,10 @@ def validation(inference_program, avg_cost, s_probs, e_probs, feed_order, place,
...
@@ -235,7 +238,10 @@ def validation(inference_program, avg_cost, s_probs, e_probs, feed_order, place,
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
:
if
six
.
PY2
:
vocab
=
pickle
.
load
(
fin
)
vocab
=
pickle
.
load
(
fin
)
else
:
vocab
=
pickle
.
load
(
fin
,
encoding
=
'bytes'
)
logger
.
info
(
'vocab size is {} and embed dim is {}'
.
format
(
vocab
.
size
(
logger
.
info
(
'vocab size is {} and embed dim is {}'
.
format
(
vocab
.
size
(
),
vocab
.
embed_dim
))
),
vocab
.
embed_dim
))
brc_data
=
BRCDataset
(
args
.
max_p_num
,
args
.
max_p_len
,
args
.
max_q_len
,
brc_data
=
BRCDataset
(
args
.
max_p_num
,
args
.
max_p_len
,
args
.
max_q_len
,
...
@@ -259,13 +265,20 @@ def train(logger, args):
...
@@ -259,13 +265,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
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录