Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
3c303e97
M
models
项目概览
PaddlePaddle
/
models
接近 2 年 前同步成功
通知
230
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看板
提交
3c303e97
编写于
6月 13, 2019
作者:
Z
zhengya01
提交者:
LiuHao
6月 13, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Ce sentiment classification (#2389)
* add ce for models_ce * add ce for sentiment_classification
上级
550947a7
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
104 addition
and
0 deletion
+104
-0
PaddleNLP/sentiment_classification/.run_ce.sh
PaddleNLP/sentiment_classification/.run_ce.sh
+35
-0
PaddleNLP/sentiment_classification/__init__.py
PaddleNLP/sentiment_classification/__init__.py
+0
-0
PaddleNLP/sentiment_classification/_ce.py
PaddleNLP/sentiment_classification/_ce.py
+65
-0
PaddleNLP/sentiment_classification/run_classifier.py
PaddleNLP/sentiment_classification/run_classifier.py
+4
-0
未找到文件。
PaddleNLP/sentiment_classification/.run_ce.sh
0 → 100644
浏览文件 @
3c303e97
#! /bin/bash
export
FLAGS_enable_parallel_graph
=
1
export
FLAGS_sync_nccl_allreduce
=
1
export
FLAGS_fraction_of_gpu_memory_to_use
=
0.95
export
CPU_NUM
=
1
# run_train on train.tsv and do_val on test.tsv
train
()
{
python
-u
run_classifier.py
\
--task_name
'senta'
\
--use_cuda
true
\
--do_train
true
\
--do_val
true
\
--do_infer
false
\
--batch_size
16
\
--data_dir
./senta_data/
\
--vocab_path
./senta_data/word_dict.txt
\
--checkpoints
./save_models
\
--save_steps
500
\
--validation_steps
50
\
--epoch
2
\
--senta_config_path
./senta_config.json
\
--skip_steps
10
\
--random_seed
0
\
--enable_ce
}
export
CUDA_VISIBLE_DEVICES
=
0
train |
grep
"dev evaluation"
|
grep
"ave loss"
|
tail
-1
|
awk
'{print "kpis\ttrain_loss_senta_card1\t"$5"\nkpis\ttrain_acc_senta_card1\t"$8"\nkpis\teach_step_duration_senta_card1\t"$11}'
|
tr
-d
","
| python _ce.py
sleep
20
export
CUDA_VISIBLE_DEVICES
=
0,1,2,3
train |
grep
"dev evaluation"
|
grep
"ave loss"
|
tail
-1
|
awk
'{print "kpis\ttrain_loss_senta_card4\t"$5"\nkpis\ttrain_acc_senta_card4\t"$8"\nkpis\teach_step_duration_senta_card4\t"$11}'
|
tr
-d
","
| python _ce.py
PaddleNLP/sentiment_classification/__init__.py
0 → 100644
浏览文件 @
3c303e97
PaddleNLP/sentiment_classification/_ce.py
0 → 100644
浏览文件 @
3c303e97
# 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_senta_card1
=
DurationKpi
(
'each_step_duration_senta_card1'
,
0.01
,
0
,
actived
=
False
)
train_loss_senta_card1
=
CostKpi
(
'train_loss_senta_card1'
,
0.05
,
0
,
actived
=
True
)
train_acc_senta_card1
=
AccKpi
(
'train_acc_senta_card1'
,
0.02
,
0
,
actived
=
True
)
each_step_duration_senta_card4
=
DurationKpi
(
'each_step_duration_senta_card4'
,
0.01
,
0
,
actived
=
False
)
train_loss_senta_card4
=
CostKpi
(
'train_loss_senta_card4'
,
0.05
,
0
,
actived
=
True
)
train_acc_senta_card4
=
AccKpi
(
'train_acc_senta_card4'
,
0.02
,
0
,
actived
=
True
)
tracking_kpis
=
[
each_step_duration_senta_card1
,
train_loss_senta_card1
,
train_acc_senta_card1
,
each_step_duration_senta_card4
,
train_loss_senta_card4
,
train_acc_senta_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/sentiment_classification/run_classifier.py
浏览文件 @
3c303e97
...
...
@@ -58,6 +58,7 @@ run_type_g.add_arg("task_name", str, None,
run_type_g
.
add_arg
(
"do_train"
,
bool
,
True
,
"Whether to perform training."
)
run_type_g
.
add_arg
(
"do_val"
,
bool
,
True
,
"Whether to perform evaluation."
)
run_type_g
.
add_arg
(
"do_infer"
,
bool
,
True
,
"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
()
# yapf: enable.
...
...
@@ -199,6 +200,8 @@ def main(args):
print
(
"Max train steps: %d"
%
max_train_steps
)
train_program
=
fluid
.
Program
()
if
args
.
enable_ce
and
args
.
random_seed
is
not
None
:
train_program
.
random_seed
=
args
.
random_seed
with
fluid
.
program_guard
(
train_program
,
startup_prog
):
with
fluid
.
unique_name
.
guard
():
...
...
@@ -364,6 +367,7 @@ def main(args):
inference
(
exe
,
infer_prog
,
infer_pyreader
,
[
prop
.
name
],
"infer"
)
if
__name__
==
"__main__"
:
print_arguments
(
args
)
main
(
args
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录