-
Notifications
You must be signed in to change notification settings - Fork 100
/
run_uie_finetune_shot.bash
97 lines (83 loc) · 3.38 KB
/
run_uie_finetune_shot.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env bash
# -*- coding:utf-8 -*-
export batch_size="16"
export model_name=uie-base-en
export data_name==absa/14lap
export task_name="meta"
export decoding_format='spotasoc'
source scripts/function_code.bash
for index in $(seq 1 ${run_time}); do
output_dir=${model_folder}_run${index}
if [[ ${verbose} == true ]]
then
stdout_file=/dev/stdout
stderr_file=/dev/stderr
disable_tqdm=False
else
stdout_file=${output_dir}.log
stderr_file=${output_dir}.err
disable_tqdm=True
fi
shot_data_folder=${data_folder}_shot/seed${index}
for shot in $(ls ${shot_data_folder})
do
run_data_folder=${shot_data_folder}/${shot}
run_output_folder=${output_dir}_${shot}
if [[ ${max_prefix_length} == 0 ]]
then
run_output_folder=${run_output_folder}_noprefix
fi
echo ${run_data_folder}
eval_steps=$(python scripts/get_eval_batch_num.py ${run_data_folder}/train.json ${batch_size} 20)
echo Eval each ${eval_steps} batch
CUDA_VISIBLE_DEVICES=${CUDA_VISIBLE_DEVICES} ${run_command} run_uie_finetune.py \
--do_train --do_eval --do_predict ${constraint_decoding} ${fp16} \
--use_fast_tokenizer=True \
--ddp_find_unused_parameters=False \
--predict_with_generate \
--evaluation_strategy=steps \
--save_strategy=steps \
--load_best_model_at_end \
--metric_for_best_model eval_overall-F1 \
--save_total_limit 1 \
--max_source_length=${max_source_length:-"256"} \
--max_prefix_length=${max_prefix_length:-"-1"} \
--max_target_length=${max_target_length:-"192"} \
--num_train_epochs=${epoch} \
--task=${task_name} \
--train_file=${run_data_folder}/train.json \
--validation_file=${run_data_folder}/val.json \
--test_file=${run_data_folder}/test.json \
--record_schema=${run_data_folder}/record.schema \
--per_device_train_batch_size=${batch_size} \
--per_device_eval_batch_size=$((batch_size * 4)) \
--output_dir=${run_output_folder} \
--logging_dir=${run_output_folder}_log \
--model_name_or_path=${model_name} \
--learning_rate=${lr} \
--source_prefix="${task_name}: " \
--lr_scheduler_type=${lr_scheduler} \
--label_smoothing_factor=${label_smoothing} \
--eval_steps ${eval_steps} \
--decoding_format ${decoding_format} \
--warmup_ratio ${warmup_ratio} \
--preprocessing_num_workers=4 \
--dataloader_num_workers=0 \
--meta_negative=${negative} \
--meta_positive_rate=${positive} \
--skip_memory_metrics \
--no_remove_unused_columns \
--ordered_prompt=${ordered_prompt} \
--save_better_checkpoint=True \
--spot_noise=${spot_noise} \
--asoc_noise=${asoc_noise} \
--seed=${seed} --disable_tqdm=${disable_tqdm} >${stdout_file} 2>${stderr_file}
echo "Map Config" ${map_config}
python3 scripts/sel2record.py -p ${run_output_folder} -g ${run_data_folder} -v -d ${decoding_format} -c ${map_config}
python3 scripts/eval_extraction.py -p ${run_output_folder} -g ${run_data_folder} -w -m ${eval_match_mode:-"normal"}
# delete all pytorch_model.bin of checkpoints in low-resource exps for saving disk
find ${run_output_folder}/ | grep -P "checkpoint-\d+/pytorch_model.bin" | xargs rm -rf
# delete all optimizer.pt in low-resource exps for saving disk
find ${run_output_folder}/ | grep -P "optimizer.pt" | xargs rm -rf
done
done