Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
623698ef
M
models
项目概览
PaddlePaddle
/
models
大约 2 年 前同步成功
通知
232
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看板
提交
623698ef
编写于
6月 06, 2019
作者:
Z
zhengya01
提交者:
kolinwei
6月 06, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add ce for emotion_detection (#2364)
上级
e0e198ed
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
133 addition
and
0 deletion
+133
-0
PaddleNLP/emotion_detection/.run_ce.sh
PaddleNLP/emotion_detection/.run_ce.sh
+35
-0
PaddleNLP/emotion_detection/__init__.py
PaddleNLP/emotion_detection/__init__.py
+0
-0
PaddleNLP/emotion_detection/_ce.py
PaddleNLP/emotion_detection/_ce.py
+65
-0
PaddleNLP/emotion_detection/run_classifier.py
PaddleNLP/emotion_detection/run_classifier.py
+33
-0
未找到文件。
PaddleNLP/emotion_detection/.run_ce.sh
0 → 100644
浏览文件 @
623698ef
#!/bin/bash
export
FLAGS_enable_parallel_graph
=
1
export
FLAGS_sync_nccl_allreduce
=
1
export
FLAGS_fraction_of_gpu_memory_to_use
=
0.95
TASK_NAME
=
'emotion_detection'
DATA_PATH
=
./data/
VOCAB_PATH
=
./data/vocab.txt
CKPT_PATH
=
./save_models/textcnn
MODEL_PATH
=
./models/textcnn
# run_train on train.tsv and do_val on dev.tsv
train
()
{
python run_classifier.py
\
--task_name
${
TASK_NAME
}
\
--use_cuda
true
\
--do_train
true
\
--do_val
true
\
--batch_size
64
\
--data_dir
${
DATA_PATH
}
\
--vocab_path
${
VOCAB_PATH
}
\
--output_dir
${
CKPT_PATH
}
\
--save_steps
200
\
--validation_steps
200
\
--epoch
10
\
--lr
0.002
\
--config_path
./config.json
\
--skip_steps
100
\
--enable_ce
}
export
CUDA_VISIBLE_DEVICES
=
0
train | python _ce.py
sleep
20
export
CUDA_VISIBLE_DEVICES
=
0,1,2,3
train | python _ce.py
PaddleNLP/emotion_detection/__init__.py
0 → 100644
浏览文件 @
623698ef
PaddleNLP/emotion_detection/_ce.py
0 → 100644
浏览文件 @
623698ef
# this file is only used for continuous evaluation test!
import
os
import
sys
sys
.
path
.
append
(
os
.
environ
[
'ceroot'
])
from
kpi
import
CostKpi
from
kpi
import
DurationKpi
from
kpi
import
AccKpi
each_step_duration_emotion_detection_card1
=
DurationKpi
(
'each_step_duration_emotion_detection_card1'
,
0.08
,
0
,
actived
=
True
)
train_loss_emotion_detection_card1
=
CostKpi
(
'train_loss_emotion_detection_card1'
,
0.05
,
0
,
actived
=
False
)
train_acc_emotion_detection_card1
=
CostKpi
(
'train_acc_emotion_detection_card1'
,
0.05
,
0
,
actived
=
True
)
each_step_duration_emotion_detection_card4
=
DurationKpi
(
'each_step_duration_emotion_detection_card4'
,
0.08
,
0
,
actived
=
True
)
train_loss_emotion_detection_card4
=
CostKpi
(
'train_loss_emotion_detection_card4'
,
0.05
,
0
,
actived
=
False
)
train_acc_emotion_detection_card4
=
CostKpi
(
'train_acc_emotion_detection_card4'
,
0.05
,
0
,
actived
=
True
)
tracking_kpis
=
[
each_step_duration_emotion_detection_card1
,
train_loss_emotion_detection_card1
,
train_acc_emotion_detection_card1
,
each_step_duration_emotion_detection_card4
,
train_loss_emotion_detection_card4
,
train_acc_emotion_detection_card4
,
]
def
parse_log
(
log
):
'''
This method should be implemented by model developers.
The suggestion:
each line in the log should be key, value, for example:
"
train_cost
\t
1.0
test_cost
\t
1.0
train_cost
\t
1.0
train_cost
\t
1.0
train_acc
\t
1.2
"
'''
for
line
in
log
.
split
(
'
\n
'
):
fs
=
line
.
strip
().
split
(
'
\t
'
)
print
(
fs
)
if
len
(
fs
)
==
3
and
fs
[
0
]
==
'kpis'
:
kpi_name
=
fs
[
1
]
kpi_value
=
float
(
fs
[
2
])
yield
kpi_name
,
kpi_value
def
log_to_ce
(
log
):
kpi_tracker
=
{}
for
kpi
in
tracking_kpis
:
kpi_tracker
[
kpi
.
name
]
=
kpi
for
(
kpi_name
,
kpi_value
)
in
parse_log
(
log
):
print
(
kpi_name
,
kpi_value
)
kpi_tracker
[
kpi_name
].
add_record
(
kpi_value
)
kpi_tracker
[
kpi_name
].
persist
()
if
__name__
==
'__main__'
:
log
=
sys
.
stdin
.
read
()
log_to_ce
(
log
)
PaddleNLP/emotion_detection/run_classifier.py
浏览文件 @
623698ef
...
@@ -51,6 +51,8 @@ run_type_g.add_arg("do_train", bool, False, "Whether to perform training.")
...
@@ -51,6 +51,8 @@ run_type_g.add_arg("do_train", bool, False, "Whether to perform training.")
run_type_g
.
add_arg
(
"do_val"
,
bool
,
False
,
"Whether to perform evaluation."
)
run_type_g
.
add_arg
(
"do_val"
,
bool
,
False
,
"Whether to perform evaluation."
)
run_type_g
.
add_arg
(
"do_infer"
,
bool
,
False
,
"Whether to perform inference."
)
run_type_g
.
add_arg
(
"do_infer"
,
bool
,
False
,
"Whether to perform inference."
)
parser
.
add_argument
(
'--enable_ce'
,
action
=
'store_true'
,
help
=
'If set, run the task with continuous evaluation logs.'
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
def
create_model
(
args
,
def
create_model
(
args
,
...
@@ -188,6 +190,8 @@ def main(args):
...
@@ -188,6 +190,8 @@ def main(args):
print
(
"Max train steps: %d"
%
max_train_steps
)
print
(
"Max train steps: %d"
%
max_train_steps
)
train_program
=
fluid
.
Program
()
train_program
=
fluid
.
Program
()
if
args
.
random_seed
is
not
None
:
train_program
.
random_seed
=
args
.
random_seed
with
fluid
.
program_guard
(
train_program
,
startup_prog
):
with
fluid
.
program_guard
(
train_program
,
startup_prog
):
with
fluid
.
unique_name
.
guard
():
with
fluid
.
unique_name
.
guard
():
...
@@ -261,6 +265,7 @@ def main(args):
...
@@ -261,6 +265,7 @@ def main(args):
steps
=
0
steps
=
0
total_cost
,
total_acc
,
total_num_seqs
=
[],
[],
[]
total_cost
,
total_acc
,
total_num_seqs
=
[],
[],
[]
time_begin
=
time
.
time
()
time_begin
=
time
.
time
()
ce_info
=
[]
while
True
:
while
True
:
try
:
try
:
steps
+=
1
steps
+=
1
...
@@ -292,6 +297,7 @@ def main(args):
...
@@ -292,6 +297,7 @@ def main(args):
(
steps
,
np
.
sum
(
total_cost
)
/
np
.
sum
(
total_num_seqs
),
(
steps
,
np
.
sum
(
total_cost
)
/
np
.
sum
(
total_num_seqs
),
np
.
sum
(
total_acc
)
/
np
.
sum
(
total_num_seqs
),
np
.
sum
(
total_acc
)
/
np
.
sum
(
total_num_seqs
),
args
.
skip_steps
/
used_time
))
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
),
used_time
])
total_cost
,
total_acc
,
total_num_seqs
=
[],
[],
[]
total_cost
,
total_acc
,
total_num_seqs
=
[],
[],
[]
time_begin
=
time
.
time
()
time_begin
=
time
.
time
()
...
@@ -317,6 +323,24 @@ def main(args):
...
@@ -317,6 +323,24 @@ def main(args):
train_pyreader
.
reset
()
train_pyreader
.
reset
()
break
break
if
args
.
do_train
and
args
.
enable_ce
:
card_num
=
get_cards
()
ce_loss
=
0
ce_acc
=
0
ce_time
=
0
try
:
ce_loss
=
ce_info
[
-
2
][
0
]
ce_acc
=
ce_info
[
-
2
][
1
]
ce_time
=
ce_info
[
-
2
][
2
]
except
:
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
))
# evaluate on test set
# evaluate on test set
if
not
args
.
do_train
and
args
.
do_val
:
if
not
args
.
do_train
and
args
.
do_val
:
test_pyreader
.
decorate_paddle_reader
(
test_pyreader
.
decorate_paddle_reader
(
...
@@ -339,6 +363,15 @@ def main(args):
...
@@ -339,6 +363,15 @@ def main(args):
infer
(
test_exe
,
test_prog
,
infer_pyreader
,
infer
(
test_exe
,
test_prog
,
infer_pyreader
,
[
probs
.
name
],
"infer"
)
[
probs
.
name
],
"infer"
)
def
get_cards
():
num
=
0
cards
=
os
.
environ
.
get
(
'CUDA_VISIBLE_DEVICES'
,
''
)
if
cards
!=
''
:
num
=
len
(
cards
.
split
(
","
))
return
num
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
utils
.
print_arguments
(
args
)
utils
.
print_arguments
(
args
)
main
(
args
)
main
(
args
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录