-
Notifications
You must be signed in to change notification settings - Fork 7
/
finetuning.sh
168 lines (157 loc) · 9.58 KB
/
finetuning.sh
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# nohup bash finetuning.sh config=configs/conll05.crf.srl.bert.ini path=exp/conll05.crf.srl.bert bert=bert-large-cased train=data/srl/conll05/train.conllu dev=data/srl/conll05/dev.conllu test=data/srl/conll05/test.conllu ood=data/srl/conll05/brown.conllu devices=4,5,6,7 > log.conll05.crf.bert 2>&1 &
# nohup bash finetuning.sh config=configs/conll05.crf.srl.roberta.ini path=exp/conll05.crf.srl.roberta bert=roberta-large train=data/srl/conll05/train.conllu dev=data/srl/conll05/dev.conllu test=data/srl/conll05/test.conllu ood=data/srl/conll05/brown.conllu devices=4,5,6,7 > log.conll05.crf.roberta 2>&1 &
# nohup bash finetuning.sh config=configs/conll12.crf.srl.bert.ini path=exp/conll12.crf.srl.bert bert=bert-large-cased train=data/srl/conll12/train.conllu dev=data/srl/conll12/dev.conllu test=data/srl/conll12/test.conllu ood=data/srl/conll12/test.conllu devices=4,5,6,7 > log.conll12.crf.bert 2>&1 &
# nohup bash finetuning.sh config=configs/conll12.crf.srl.roberta.ini path=exp/conll12.crf.srl.roberta bert=roberta-large train=data/srl/conll12/train.conllu dev=data/srl/conll12/dev.conllu test=data/srl/conll12/test.conllu ood=data/srl/conll12/test.conllu devices=4,5,6,7 > log.conll12.crf.roberta 2>&1 &
args=$@
for arg in $args; do
eval "$arg"
done
DATA=~/.cache/supar/data
echo "config: ${config:=config.ini}"
echo "path: ${path:=exp/conll05.crf.srl.bert}"
echo "train: ${train:=$DATA/srl/conll05/train.conllu}"
echo "dev: ${dev:=$DATA/srl/conll05/dev.conllu}"
echo "test: ${test:=$DATA/srl/conll05/test.conllu}"
echo "ood: ${ood:=$DATA/srl/conll05/brown.conllu}"
echo "bert: ${config:=bert-large-cased}"
echo "batch: ${batch:=1000}"
echo "dropout: ${dropout:=0.1}"
echo "epochs: ${epochs:=20}"
echo "rate: ${rate:=20}"
echo "nu: ${nu:=0.9}"
echo "eps: ${eps:=1e-12}"
echo "devices: ${devices:=4,5,6,7}"
IFS=',' read -r -a device_arr <<< "$devices"
n_devices=${#device_arr[@]}
export TOKENIZERS_PARALLELISM=true
train() {
# run processes and store pids in array
for seed in {0..3}; do
device_id=$(($seed % $n_devices))
if [ ${#pids[@]} -gt $device_id ]; then
echo "wait ${pids[$device_id]} to be done"
wait ${pids[$device_id]}
fi
printf "nohup python -u crf.py train -b -c $config -s $seed -d ${device_arr[$device_id]} -p $path/model.batch$batch.dropout$dropout.epochs$epochs.rate$rate.$seed --batch-size=$batch --mlp-dropout=$dropout --epochs=$epochs --lr-rate=$rate --train $train --dev $dev --test $test --encoder bert --bert $bert 2>$path/model.batch$batch.dropout$dropout.epochs$epochs.rate$rate.$seed.train.log.verbose &\n\n"
nohup python -u crf.py train -b -c $config -s $seed -d ${device_arr[$device_id]} -p $path/model.batch$batch.dropout$dropout.epochs$epochs.rate$rate.$seed --batch-size=$batch --mlp-dropout=$dropout --epochs=$epochs --lr-rate=$rate --train $train --dev $dev --test $test --encoder bert --bert $bert 2>$path/model.batch$batch.dropout$dropout.epochs$epochs.rate$rate.$seed.train.log.verbose &
pids[${i}]=$!
done
# wait for all pids
for pid in ${pids[*]}; do
wait $pid
done
}
evaluate() {
# run processes and store pids in array
for dataset in dev test ood; do
for seed in {0..3}; do
echo $seed $dataset ${!dataset}
device_id=$(($seed % $n_devices))
if [ ${#pids[@]} -gt $device_id ]; then
echo "wait ${pids[$device_id]} to be done"
wait ${pids[$device_id]}
fi
printf "nohup python -u crf.py evaluate -c $config -d ${device_arr[$device_id]} -p $path/model.batch$batch.dropout$dropout.epochs$epochs.rate$rate.$seed --bert=$bert --data ${!dataset} 2>$path/model.batch$batch.dropout$dropout.epochs$epochs.rate$rate.$seed.$dataset.evaluate.log.verbose &\n\n"
nohup python -u crf.py evaluate -c $config -d ${device_arr[$device_id]} -p $path/model.batch$batch.dropout$dropout.epochs$epochs.rate$rate.$seed --bert=$bert --data ${!dataset} >$path/model.batch$batch.dropout$dropout.epochs$epochs.rate$rate.$seed.$dataset.evaluate.log.verbose &
pids[${i}]=$!
echo ${pids[*]}
done
done
# wait for all pids
for pid in ${pids[*]}; do
wait $pid
done
for dataset in dev test ood; do
for seed in {0..3}; do
device_id=$(($seed % $n_devices))
if [ ${#pids[@]} -gt $device_id ]; then
echo "wait ${pids[$device_id]} to be done"
wait ${pids[$device_id]}
fi
printf "nohup python -u crf.py evaluate -c $config -d ${device_arr[$device_id]} -p $path/model.batch$batch.dropout$dropout.epochs$epochs.rate$rate.$seed --bert=$bert --data ${!dataset} --prd 2>$path/model.batch$batch.dropout$dropout.epochs$epochs.rate$rate.$seed.$dataset.prd.evaluate.log.verbose &\n\n"
nohup python -u crf.py evaluate -c $config -d ${device_arr[$device_id]} -p $path/model.batch$batch.dropout$dropout.epochs$epochs.rate$rate.$seed --bert=$bert --data ${!dataset} --prd >$path/model.batch$batch.dropout$dropout.epochs$epochs.rate$rate.$seed.$dataset.prd.evaluate.log.verbose &
pids[${i}]=$!
echo ${pids[*]}
done
done
# wait for all pids
for pid in ${pids[*]}; do
wait $pid
done
}
predict() {
run processes and store pids in array
for dataset in dev test ood; do
for seed in {0..3}; do
echo $seed $dataset ${!dataset}
device_id=$(($seed % $n_devices))
if [ ${#pids[@]} -gt $device_id ]; then
echo "wait ${pids[$device_id]} to be done"
wait ${pids[$device_id]}
fi
printf "nohup python -u crf.py predict -c $config -d ${device_arr[$device_id]} -p $path/model.batch$batch.dropout$dropout.epochs$epochs.rate$rate.$seed --bert=$bert --data ${!dataset} --pred $path/$dataset.batch$batch.dropout$dropout.epochs$epochs.rate$rate.$seed.pred.conllu 2>$path/model.batch$batch.dropout$dropout.epochs$epochs.rate$rate.$seed.$dataset.predict.log.verbose &\n\n"
nohup python -u crf.py predict -c $config -d ${device_arr[$device_id]} -p $path/model.batch$batch.dropout$dropout.epochs$epochs.rate$rate.$seed --bert=$bert --data ${!dataset} --pred $path/$dataset.batch$batch.dropout$dropout.epochs$epochs.rate$rate.$seed.pred.conllu >$path/model.batch$batch.dropout$dropout.epochs$epochs.rate$rate.$seed.$dataset.predict.log.verbose &
pids[${i}]=$!
echo ${pids[*]}
done
done
for dataset in dev test ood; do
for seed in {0..3}; do
device_id=$(($seed % $n_devices))
if [ ${#pids[@]} -gt $device_id ]; then
echo "wait ${pids[$device_id]} to be done"
wait ${pids[$device_id]}
fi
printf "nohup python -u crf.py predict -c $config -d ${device_arr[$device_id]} -p $path/model.batch$batch.dropout$dropout.epochs$epochs.rate$rate.$seed --bert=$bert --data ${!dataset} --pred $path/$dataset.batch$batch.dropout$dropout.epochs$epochs.rate$rate.$seed.pred.gold.conllu --prd 2>$path/model.batch$batch.dropout$dropout.epochs$epochs.rate$rate.$seed.$dataset.prd.predict.log.verbose &\n\n"
nohup python -u crf.py predict -c $config -d ${device_arr[$device_id]} -p $path/model.batch$batch.dropout$dropout.epochs$epochs.rate$rate.$seed --bert=$bert --data ${!dataset} --pred $path/$dataset.batch$batch.dropout$dropout.epochs$epochs.rate$rate.$seed.pred.gold.conllu --prd >$path/model.batch$batch.dropout$dropout.epochs$epochs.rate$rate.$seed.$dataset.prd.predict.log.verbose &
pids[${i}]=$!
echo ${pids[*]}
done
done
# wait for all pids
for pid in ${pids[*]}; do
wait $pid
done
}
avg(){
printf "Current commits:\n$(git log -1 --oneline)\n3rd parties:\n"
cd 3rdparty/parser/ && printf "parser\n$(git log -1 --oneline)\n" && cd ../..
for seed in {0..3}; do
line=$(tail -n 2 $path/model.batch$batch.dropout$dropout.epochs$epochs.rate$rate.$seed.$dataset.evaluate.log.verbose | head -n 1)
echo $line
ps[$seed]=${line:0-26:5}
rs[$seed]=${line:0-16:5}
fs[$seed]=${line:0-6:5}
done
printf "Average P/R/F score:\n"
echo ${ps[@]} | awk '{sum = 0; for (i = 1; i <= NF; i++) sum += $i; sum /= NF; printf("%.2f ", sum)}'
echo ${rs[@]} | awk '{sum = 0; for (i = 1; i <= NF; i++) sum += $i; sum /= NF; printf("%.2f ", sum)}'
echo ${fs[@]} | awk '{sum = 0; for (i = 1; i <= NF; i++) sum += $i; sum /= NF; printf("%.2f ", sum)}'
printf "\n\n"
echo 'w/ gold predicate'
for seed in {0..3}; do
line=$(tail -n 2 $path/model.batch$batch.dropout$dropout.epochs$epochs.rate$rate.$seed.$dataset.prd.evaluate.log.verbose | head -n 1)
echo $line
ps[$seed]=${line:0-26:5}
rs[$seed]=${line:0-16:5}
fs[$seed]=${line:0-6:5}
done
printf "Average P/R/F score:\n"
echo ${ps[@]} | awk '{sum = 0; for (i = 1; i <= NF; i++) sum += $i; sum /= NF; printf("%.2f ", sum)}'
echo ${rs[@]} | awk '{sum = 0; for (i = 1; i <= NF; i++) sum += $i; sum /= NF; printf("%.2f ", sum)}'
echo ${fs[@]} | awk '{sum = 0; for (i = 1; i <= NF; i++) sum += $i; sum /= NF; printf("%.2f ", sum)}'
printf "\n\n"
}
collect() {
echo $path/model.batch$batch.dropout$dropout
for dataset in dev test ood; do
echo "All cmds for $dataset has been done!" | tee -a $path/model.batch$batch.dropout$dropout.epochs$epochs.rate$rate.$dataset.avg.log
avg $dataset | tee -a $path/model.batch$batch.dropout$dropout.epochs$epochs.rate$rate.$dataset.avg.log
done
printf "\n"
}
mkdir -p $path
train
evaluate
predict
collect