提交 3c303e97 编写于 作者: Z zhengya01 提交者: LiuHao

Ce sentiment classification (#2389)

* add ce for models_ce

* add ce for sentiment_classification
上级 550947a7
#! /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
# 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\t1.0
test_cost\t1.0
train_cost\t1.0
train_cost\t1.0
train_acc\t1.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)
......@@ -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.
先完成此消息的编辑!
想要评论请 注册