-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·67 lines (55 loc) · 1.99 KB
/
run.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
#!/bin/bash
DATA_PATH=crossre_data
EXP_PATH=<PATH TO EXPERIMENT FOLDER>
DOMAIN="ai"
# domains: news politics science music literature ai
LM='bert-base-cased'
SEEDS=( 4012 5096 8878 8857 9908 )
#iterate over seeds
for rs in "${!SEEDS[@]}"; do
echo "Experiment on random seed ${SEEDS[$rs]}."
exp_dir=$EXP_PATH/rs${SEEDS[$rs]}
# check if experiment already exists
if [ -f "$exp_dir/best.pt" ]; then
echo "[Warning] Experiment '$exp_dir' already exists. Not retraining."
# if experiment is new, train classifier
else
echo "Training model on random seed ${SEEDS[$rs]}."
# train
python3 main.py \
--train_path $DATA_PATH/${DOMAIN}-train.json \
--dev_path $DATA_PATH/${DOMAIN}-dev.json \
--exp_path ${exp_dir} \
--language_model ${LM} \
--seed ${SEEDS[$rs]}
# save experiment info
echo "Model with RS: ${SEEDS[$rs]}" > $exp_dir/experiment-info.txt
fi
# check if prediction already exists
if [ -f "$exp_dir/${DOMAIN}-test-pred.csv" ]; then
echo "[Warning] Prediction '$exp_dir/${DOMAIN}-test-pred.csv' already exists. Not re-predicting."
# if no prediction is available, run inference
else
# prediction
python3 main.py \
--train_path $DATA_PATH/${DOMAIN}-train.json \
--test_path $DATA_PATH/${DOMAIN}-test.json \
--exp_path ${exp_dir} \
--language_model ${LM} \
--seed ${SEEDS[$rs]} \
--prediction_only
fi
# check if summary metric scores file already exists
if [ -f "$EXP_PATH/summary-exps.txt" ]; then
echo "RS: ${SEEDS[$rs]}" >> $EXP_PATH/summary-exps.txt
else
echo "Domain ${DOMAIN}" > $EXP_PATH/summary-exps.txt
echo "RS: ${SEEDS[$rs]}" >> $EXP_PATH/summary-exps.txt
fi
# run evaluation
python3 evaluate.py \
--gold_path ${DATA_PATH}/${DOMAIN}-test.json \
--pred_path ${exp_dir}/${DOMAIN}-test-pred.csv \
--out_path ${exp_dir} \
--summary_exps $EXP_PATH/summary-exps.txt
done