Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
c2162f5c
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看板
未验证
提交
c2162f5c
编写于
11月 02, 2018
作者:
X
xuezhong
提交者:
GitHub
11月 02, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1417 from xuezhong/machine_reading_comprehesion
fix bug for L2DecayRegularizer
上级
5805cf16
655592ac
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
20 addition
and
15 deletion
+20
-15
fluid/PaddleNLP/Senta
fluid/PaddleNLP/Senta
+0
-1
fluid/PaddleNLP/SimNet
fluid/PaddleNLP/SimNet
+0
-1
fluid/PaddleNLP/machine_reading_comprehension/run.py
fluid/PaddleNLP/machine_reading_comprehension/run.py
+19
-12
fluid/PaddleNLP/machine_reading_comprehension/run.sh
fluid/PaddleNLP/machine_reading_comprehension/run.sh
+1
-1
未找到文件。
Senta
@
870651e2
比较
870651e2
...
870651e2
Subproject commit 870651e257750f2c237f0b0bc9a27e5d062d1909
SimNet
@
4dbe7f7b
比较
4dbe7f7b
...
4dbe7f7b
Subproject commit 4dbe7f7b0e76c188eb7f448d104f0165f0a12229
fluid/PaddleNLP/machine_reading_comprehension/run.py
浏览文件 @
c2162f5c
...
...
@@ -312,6 +312,15 @@ def validation(inference_program, avg_cost, s_probs, e_probs, match, feed_order,
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
):
logger
.
info
(
'Load data_set and vocab...'
)
with
open
(
os
.
path
.
join
(
args
.
vocab_dir
,
'vocab.data'
),
'rb'
)
as
fin
:
...
...
@@ -349,24 +358,22 @@ def train(logger, args):
# build optimizer
if
args
.
optim
==
'sgd'
:
optimizer
=
fluid
.
optimizer
.
SGD
(
learning_rate
=
args
.
learning_rate
,
regularization
=
fluid
.
regularizer
.
L2DecayRegularizer
(
regularization_coeff
=
args
.
weight_decay
))
learning_rate
=
args
.
learning_rate
)
elif
args
.
optim
==
'adam'
:
optimizer
=
fluid
.
optimizer
.
Adam
(
learning_rate
=
args
.
learning_rate
,
regularization
=
fluid
.
regularizer
.
L2DecayRegularizer
(
regularization_coeff
=
args
.
weight_decay
))
learning_rate
=
args
.
learning_rate
)
elif
args
.
optim
==
'rprop'
:
optimizer
=
fluid
.
optimizer
.
RMSPropOptimizer
(
learning_rate
=
args
.
learning_rate
,
regularization
=
fluid
.
regularizer
.
L2DecayRegularizer
(
regularization_coeff
=
args
.
weight_decay
))
learning_rate
=
args
.
learning_rate
)
else
:
logger
.
error
(
'Unsupported optimizer: {}'
.
format
(
args
.
optim
))
exit
(
-
1
)
optimizer
.
minimize
(
avg_cost
)
if
args
.
weight_decay
>
0.0
:
obj_func
=
avg_cost
+
args
.
weight_decay
*
l2_loss
(
main_program
)
optimizer
.
minimize
(
obj_func
)
else
:
obj_func
=
avg_cost
optimizer
.
minimize
(
obj_func
)
# initialize parameters
place
=
core
.
CUDAPlace
(
0
)
if
args
.
use_gpu
else
core
.
CPUPlace
()
...
...
@@ -406,7 +413,7 @@ def train(logger, args):
feed_data
=
batch_reader
(
batch_list
,
args
)
fetch_outs
=
parallel_executor
.
run
(
feed
=
list
(
feeder
.
feed_parallel
(
feed_data
,
dev_count
)),
fetch_list
=
[
avg_cost
.
name
],
fetch_list
=
[
obj_func
.
name
],
return_numpy
=
False
)
cost_train
=
np
.
array
(
fetch_outs
[
0
]).
mean
()
total_num
+=
args
.
batch_size
*
dev_count
...
...
fluid/PaddleNLP/machine_reading_comprehension/run.sh
浏览文件 @
c2162f5c
...
...
@@ -18,5 +18,5 @@ python run.py \
--max_p_len
500
\
--max_q_len
60
\
--max_a_len
200
\
--weight_decay
0.0
\
--weight_decay
0.0
001
\
--drop_rate
0.2
$@
\
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录