Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
bb144d76
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看板
未验证
提交
bb144d76
编写于
7月 03, 2019
作者:
P
pkpk
提交者:
GitHub
7月 03, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add model check for DMTK (#2700)
* test=develop * test=develop * test=develop
上级
3cd5b2c9
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
199 addition
and
146 deletion
+199
-146
PaddleNLP/dialogue_model_toolkit/auto_dialogue_evaluation/main.py
...P/dialogue_model_toolkit/auto_dialogue_evaluation/main.py
+15
-8
PaddleNLP/dialogue_model_toolkit/deep_attention_matching/evaluation.py
...logue_model_toolkit/deep_attention_matching/evaluation.py
+12
-10
PaddleNLP/dialogue_model_toolkit/deep_attention_matching/main.py
...LP/dialogue_model_toolkit/deep_attention_matching/main.py
+12
-2
PaddleNLP/dialogue_model_toolkit/dialogue_general_understanding/predict.py
...e_model_toolkit/dialogue_general_understanding/predict.py
+24
-20
PaddleNLP/dialogue_model_toolkit/dialogue_general_understanding/train.py
...gue_model_toolkit/dialogue_general_understanding/train.py
+136
-106
未找到文件。
PaddleNLP/dialogue_model_toolkit/auto_dialogue_evaluation/main.py
浏览文件 @
bb144d76
...
...
@@ -20,9 +20,12 @@ except ImportError as e:
import
pickle
#python 3
sys
.
path
.
append
(
'../../models/dialogue_model_toolkit/auto_dialogue_evaluation/'
)
sys
.
path
.
append
(
'../../models/'
)
from
net
import
Network
import
config
from
model_check
import
check_cuda
def
train
(
args
):
"""Train
...
...
@@ -73,7 +76,8 @@ def train(args):
print
(
"device count %d"
%
dev_count
)
print
(
"theoretical memory usage: "
)
print
(
fluid
.
contrib
.
memory_usage
(
print
(
fluid
.
contrib
.
memory_usage
(
program
=
train_program
,
batch_size
=
args
.
batch_size
))
exe
=
fluid
.
Executor
(
place
)
...
...
@@ -155,8 +159,8 @@ def train(args):
main_program
=
train_program
)
print
(
"Save model at step %d ... "
%
step
)
print
(
time
.
strftime
(
'%Y-%m-%d %H:%M:%S'
,
time
.
localtime
(
time
.
time
())))
print
(
time
.
strftime
(
'%Y-%m-%d %H:%M:%S'
,
time
.
localtime
(
time
.
time
())))
best_recall
=
recall_dict
[
'1_in_10'
]
return
best_recall
...
...
@@ -252,7 +256,8 @@ def finetune(args):
print
(
"device count %d"
%
dev_count
)
print
(
"theoretical memory usage: "
)
print
(
fluid
.
contrib
.
memory_usage
(
print
(
fluid
.
contrib
.
memory_usage
(
program
=
train_program
,
batch_size
=
args
.
batch_size
))
exe
=
fluid
.
Executor
(
place
)
...
...
@@ -321,8 +326,8 @@ def finetune(args):
exe
,
main_program
=
train_program
)
print
(
"Save model at step %d ... "
%
step
)
print
(
time
.
strftime
(
'%Y-%m-%d %H:%M:%S'
,
time
.
localtime
(
time
.
time
())))
print
(
time
.
strftime
(
'%Y-%m-%d %H:%M:%S'
,
time
.
localtime
(
time
.
time
())))
best_cor
=
cor
return
best_cor
...
...
@@ -466,6 +471,8 @@ def main():
args
=
config
.
parse_args
()
config
.
print_arguments
(
args
)
check_cuda
(
args
.
use_cuda
)
if
args
.
do_train
==
True
:
if
args
.
loss_type
==
'CLS'
:
train
(
args
)
...
...
PaddleNLP/dialogue_model_toolkit/deep_attention_matching/evaluation.py
浏览文件 @
bb144d76
...
...
@@ -5,12 +5,13 @@ Evaluation
import
sys
import
six
import
numpy
as
np
from
sklearn.metrics
import
average_precision_score
def
evaluate_ubuntu
(
file_path
):
"""
Evaluate on ubuntu data
"""
def
get_p_at_n_in_m
(
data
,
n
,
m
,
ind
):
"""
Recall n at m
...
...
@@ -56,7 +57,8 @@ def evaluate_ubuntu(file_path):
"1_in_2"
:
p_at_1_in_2
/
length
,
"1_in_10"
:
p_at_1_in_10
/
length
,
"2_in_10"
:
p_at_2_in_10
/
length
,
"5_in_10"
:
p_at_5_in_10
/
length
}
"5_in_10"
:
p_at_5_in_10
/
length
}
return
result_dict
...
...
@@ -65,6 +67,7 @@ def evaluate_douban(file_path):
"""
Evaluate douban data
"""
def
mean_average_precision
(
sort_data
):
"""
Evaluate mean average precision
...
...
@@ -147,7 +150,6 @@ def evaluate_douban(file_path):
"P_1"
:
1.0
*
sum_p_1
/
total_num
,
"1_in_10"
:
1.0
*
sum_r_1
/
total_num
,
"2_in_10"
:
1.0
*
sum_r_2
/
total_num
,
"5_in_10"
:
1.0
*
sum_r_5
/
total_num
}
"5_in_10"
:
1.0
*
sum_r_5
/
total_num
}
return
result_dict
PaddleNLP/dialogue_model_toolkit/deep_attention_matching/main.py
浏览文件 @
bb144d76
...
...
@@ -20,9 +20,12 @@ except ImportError as e:
import
pickle
#python 3
sys
.
path
.
append
(
'../../models/dialogue_model_toolkit/deep_attention_matching/'
)
sys
.
path
.
append
(
'../../models/'
)
from
model_check
import
check_cuda
from
net
import
Net
def
evaluate
(
score_path
,
result_file_path
):
"""
Evaluate both douban and ubuntu dataset
...
...
@@ -70,6 +73,7 @@ def test_with_pyreader(exe, program, pyreader, fetch_list, score_path, batches,
"""
Test with pyreader
"""
def
data_provider
():
"""
Data reader
...
...
@@ -145,10 +149,12 @@ def train(args):
staircase
=
True
))
optimizer
.
minimize
(
loss
)
print
(
"begin memory optimization ..."
)
print
(
time
.
strftime
(
'%Y-%m-%d %H:%M:%S'
,
time
.
localtime
(
time
.
time
())))
print
(
time
.
strftime
(
'%Y-%m-%d %H:%M:%S'
,
time
.
localtime
(
time
.
time
())))
fluid
.
memory_optimize
(
train_program
)
print
(
"end memory optimization ..."
)
print
(
time
.
strftime
(
'%Y-%m-%d %H:%M:%S'
,
time
.
localtime
(
time
.
time
())))
print
(
time
.
strftime
(
'%Y-%m-%d %H:%M:%S'
,
time
.
localtime
(
time
.
time
())))
test_program
=
fluid
.
Program
()
test_startup
=
fluid
.
Program
()
...
...
@@ -270,6 +276,7 @@ def train(args):
"""
Train on one epoch with pyreader
"""
def
data_provider
():
"""
Data reader
...
...
@@ -467,6 +474,9 @@ def get_cards():
if
__name__
==
'__main__'
:
args
=
config
.
parse_args
()
config
.
print_arguments
(
args
)
check_cuda
(
args
.
use_cuda
)
if
args
.
do_train
:
train
(
args
)
...
...
PaddleNLP/dialogue_model_toolkit/dialogue_general_understanding/predict.py
浏览文件 @
bb144d76
...
...
@@ -34,12 +34,16 @@ import define_predict_pack
import
reader.data_reader
as
reader
_WORK_DIR
=
os
.
path
.
split
(
os
.
path
.
realpath
(
__file__
))[
0
]
sys
.
path
.
append
(
'../../models/dialogue_model_toolkit/dialogue_general_understanding'
)
sys
.
path
.
append
(
'../../models/dialogue_model_toolkit/dialogue_general_understanding'
)
sys
.
path
.
append
(
'../../models/'
)
from
bert
import
BertConfig
,
BertModel
from
create_model
import
create_model
import
define_paradigm
from
model_check
import
check_cuda
def
main
(
args
):
"""main function"""
...
...
@@ -117,10 +121,7 @@ def main(args):
use_cuda
=
args
.
use_cuda
,
main_program
=
predict_prog
)
test_data_generator
=
processor
.
data_generator
(
batch_size
=
args
.
batch_size
,
phase
=
'test'
,
epoch
=
1
,
shuffle
=
False
)
batch_size
=
args
.
batch_size
,
phase
=
'test'
,
epoch
=
1
,
shuffle
=
False
)
predict_pyreader
.
decorate_tensor_provider
(
test_data_generator
)
predict_pyreader
.
start
()
...
...
@@ -161,4 +162,7 @@ def main(args):
if
__name__
==
'__main__'
:
args
=
parser
.
parse_args
()
print_arguments
(
args
)
check_cuda
(
args
.
use_cuda
)
main
(
args
)
PaddleNLP/dialogue_model_toolkit/dialogue_general_understanding/train.py
浏览文件 @
bb144d76
...
...
@@ -33,7 +33,11 @@ from utils.args import print_arguments
from
utils.init
import
init_checkpoint
,
init_pretraining_params
_WORK_DIR
=
os
.
path
.
split
(
os
.
path
.
realpath
(
__file__
))[
0
]
sys
.
path
.
append
(
'../../models/dialogue_model_toolkit/dialogue_general_understanding'
)
sys
.
path
.
append
(
'../../models/dialogue_model_toolkit/dialogue_general_understanding'
)
sys
.
path
.
append
(
'../../models/'
)
from
model_check
import
check_cuda
from
bert
import
BertConfig
,
BertModel
from
create_model
import
create_model
...
...
@@ -48,7 +52,8 @@ def evaluate(test_exe, test_program, test_pyreader, fetch_list, eval_phase):
while
True
:
try
:
if
len
(
fetch_list
)
>
2
:
np_loss
,
np_acc
,
np_num_seqs
=
test_exe
.
run
(
fetch_list
=
fetch_list
)
np_loss
,
np_acc
,
np_num_seqs
=
test_exe
.
run
(
fetch_list
=
fetch_list
)
total_acc
.
extend
(
np_acc
*
np_num_seqs
)
else
:
np_loss
,
np_num_seqs
=
test_exe
.
run
(
fetch_list
=
fetch_list
)
...
...
@@ -58,15 +63,17 @@ def evaluate(test_exe, test_program, test_pyreader, fetch_list, eval_phase):
test_pyreader
.
reset
()
break
time_end
=
time
.
time
()
current_time
=
time
.
strftime
(
'%Y-%m-%d %H:%M:%S'
,
time
.
localtime
(
time
.
time
()))
current_time
=
time
.
strftime
(
'%Y-%m-%d %H:%M:%S'
,
time
.
localtime
(
time
.
time
()))
if
len
(
fetch_list
)
>
2
:
print
(
"[%s evaluation] %s ave loss: %f, ave acc: %f, elapsed time: %f s"
%
(
eval_phase
,
current_time
,
np
.
sum
(
total_cost
)
/
np
.
sum
(
total_num_seqs
),
np
.
sum
(
total_acc
)
/
np
.
sum
(
total_num_seqs
),
time_end
-
time_begin
))
print
(
"[%s evaluation] %s ave loss: %f, ave acc: %f, elapsed time: %f s"
%
(
eval_phase
,
current_time
,
np
.
sum
(
total_cost
)
/
np
.
sum
(
total_num_seqs
),
np
.
sum
(
total_acc
)
/
np
.
sum
(
total_num_seqs
),
time_end
-
time_begin
))
else
:
print
(
"[%s evaluation] %s ave loss: %f, elapsed time: %f s"
%
(
eval_phase
,
current_time
,
np
.
sum
(
total_cost
)
/
np
.
sum
(
total_num_seqs
),
time_end
-
time_begin
))
(
eval_phase
,
current_time
,
np
.
sum
(
total_cost
)
/
np
.
sum
(
total_num_seqs
),
time_end
-
time_begin
))
def
main
(
args
):
...
...
@@ -169,12 +176,13 @@ def main(args):
loss_scaling
=
args
.
loss_scaling
)
if
accuracy
is
not
None
:
skip_opt_set
=
[
loss
.
name
,
probs
.
name
,
accuracy
.
name
,
num_seqs
.
name
]
skip_opt_set
=
[
loss
.
name
,
probs
.
name
,
accuracy
.
name
,
num_seqs
.
name
]
else
:
skip_opt_set
=
[
loss
.
name
,
probs
.
name
,
num_seqs
.
name
]
fluid
.
memory_optimize
(
input_program
=
train_program
,
skip_opt_set
=
skip_opt_set
)
input_program
=
train_program
,
skip_opt_set
=
skip_opt_set
)
if
args
.
verbose
:
if
in_tokens
[
task_name
]:
...
...
@@ -266,7 +274,9 @@ def main(args):
if
steps
%
args
.
skip_steps
==
0
:
if
warmup_steps
<=
0
:
if
accuracy
is
not
None
:
fetch_list
=
[
loss
.
name
,
accuracy
.
name
,
num_seqs
.
name
]
fetch_list
=
[
loss
.
name
,
accuracy
.
name
,
num_seqs
.
name
]
else
:
fetch_list
=
[
loss
.
name
,
num_seqs
.
name
]
else
:
...
...
@@ -276,7 +286,9 @@ def main(args):
num_seqs
.
name
]
else
:
fetch_list
=
[
loss
.
name
,
scheduled_lr
.
name
,
num_seqs
.
name
]
fetch_list
=
[
loss
.
name
,
scheduled_lr
.
name
,
num_seqs
.
name
]
else
:
fetch_list
=
[]
if
accuracy
is
not
None
:
...
...
@@ -304,36 +316,51 @@ def main(args):
total_acc
.
extend
(
np_acc
*
np_num_seqs
)
if
args
.
verbose
:
verbose
=
"train pyreader queue size: %d, "
%
train_pyreader
.
queue
.
size
()
verbose
=
"train pyreader queue size: %d, "
%
train_pyreader
.
queue
.
size
(
)
verbose
+=
"learning rate: %f"
%
(
np_lr
[
0
]
if
warmup_steps
>
0
else
args
.
learning_rate
)
print
(
verbose
)
current_example
,
current_epoch
=
processor
.
get_train_progress
()
current_example
,
current_epoch
=
processor
.
get_train_progress
(
)
time_end
=
time
.
time
()
used_time
=
time_end
-
time_begin
current_time
=
time
.
strftime
(
'%Y-%m-%d %H:%M:%S'
,
time
.
localtime
(
time
.
time
()))
current_time
=
time
.
strftime
(
'%Y-%m-%d %H:%M:%S'
,
time
.
localtime
(
time
.
time
()))
if
accuracy
is
not
None
:
print
(
"%s epoch: %d, progress: %d/%d, step: %d, ave loss: %f, "
print
(
"%s epoch: %d, progress: %d/%d, step: %d, ave loss: %f, "
"ave acc: %f, speed: %f steps/s"
%
(
current_time
,
current_epoch
,
current_example
,
num_train_examples
,
steps
,
np
.
sum
(
total_cost
)
/
np
.
sum
(
total_num_seqs
),
(
current_time
,
current_epoch
,
current_example
,
num_train_examples
,
steps
,
np
.
sum
(
total_cost
)
/
np
.
sum
(
total_num_seqs
),
np
.
sum
(
total_acc
)
/
np
.
sum
(
total_num_seqs
),
args
.
skip_steps
/
used_time
))
ce_info
.
append
([
np
.
sum
(
total_cost
)
/
np
.
sum
(
total_num_seqs
),
np
.
sum
(
total_acc
)
/
np
.
sum
(
total_num_seqs
),
args
.
skip_steps
/
used_time
])
ce_info
.
append
([
np
.
sum
(
total_cost
)
/
np
.
sum
(
total_num_seqs
),
np
.
sum
(
total_acc
)
/
np
.
sum
(
total_num_seqs
),
args
.
skip_steps
/
used_time
])
else
:
print
(
"%s epoch: %d, progress: %d/%d, step: %d, ave loss: %f, "
print
(
"%s epoch: %d, progress: %d/%d, step: %d, ave loss: %f, "
"speed: %f steps/s"
%
(
current_time
,
current_epoch
,
current_example
,
num_train_examples
,
steps
,
np
.
sum
(
total_cost
)
/
np
.
sum
(
total_num_seqs
),
(
current_time
,
current_epoch
,
current_example
,
num_train_examples
,
steps
,
np
.
sum
(
total_cost
)
/
np
.
sum
(
total_num_seqs
),
args
.
skip_steps
/
used_time
))
ce_info
.
append
([
np
.
sum
(
total_cost
)
/
np
.
sum
(
total_num_seqs
),
args
.
skip_steps
/
used_time
])
ce_info
.
append
([
np
.
sum
(
total_cost
)
/
np
.
sum
(
total_num_seqs
),
args
.
skip_steps
/
used_time
])
total_cost
,
total_acc
,
total_num_seqs
=
[],
[],
[]
time_begin
=
time
.
time
()
if
steps
%
args
.
save_steps
==
0
:
save_path
=
os
.
path
.
join
(
args
.
checkpoints
,
"step_"
+
str
(
steps
))
save_path
=
os
.
path
.
join
(
args
.
checkpoints
,
"step_"
+
str
(
steps
))
fluid
.
io
.
save_persistables
(
exe
,
save_path
,
train_program
)
if
steps
%
args
.
validation_steps
==
0
:
#evaluate dev set
...
...
@@ -344,7 +371,8 @@ def main(args):
phase
=
'dev'
,
epoch
=
1
,
shuffle
=
False
))
evaluate
(
test_exe
,
test_prog
,
test_pyreader
,
fetch_test_list
,
"dev"
)
evaluate
(
test_exe
,
test_prog
,
test_pyreader
,
fetch_test_list
,
"dev"
)
#evaluate test set
if
args
.
do_test
:
test_pyreader
.
decorate_tensor_provider
(
...
...
@@ -353,7 +381,8 @@ def main(args):
phase
=
'test'
,
epoch
=
1
,
shuffle
=
False
))
evaluate
(
test_exe
,
test_prog
,
test_pyreader
,
fetch_test_list
,
"test"
)
evaluate
(
test_exe
,
test_prog
,
test_pyreader
,
fetch_test_list
,
"test"
)
except
fluid
.
core
.
EOFException
:
save_path
=
os
.
path
.
join
(
args
.
checkpoints
,
"step_"
+
str
(
steps
))
fluid
.
io
.
save_persistables
(
exe
,
save_path
,
train_program
)
...
...
@@ -373,10 +402,8 @@ def main(args):
print
(
"ce info error"
)
print
(
"kpis
\t
each_step_duration_%s_card%s
\t
%s"
%
(
task_name
,
card_num
,
ce_time
))
print
(
"kpis
\t
train_loss_%s_card%s
\t
%f"
%
(
task_name
,
card_num
,
ce_loss
))
print
(
"kpis
\t
train_acc_%s_card%s
\t
%f"
%
(
task_name
,
card_num
,
ce_acc
))
print
(
"kpis
\t
train_loss_%s_card%s
\t
%f"
%
(
task_name
,
card_num
,
ce_loss
))
print
(
"kpis
\t
train_acc_%s_card%s
\t
%f"
%
(
task_name
,
card_num
,
ce_acc
))
#final eval on dev set
if
args
.
do_val
:
...
...
@@ -411,4 +438,7 @@ def get_cards():
if
__name__
==
'__main__'
:
args
=
parser
.
parse_args
()
print_arguments
(
args
)
check_cuda
(
args
.
use_cuda
)
main
(
args
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录