-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_semeval2022_task2b.sh
159 lines (137 loc) · 5.34 KB
/
run_semeval2022_task2b.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
#!/bin/bash
WORK_DIR=$(dirname $(readlink -f $0))
DATA_DIR=$1
PRETRAINED_MODEL_PATH=$2
OUTPUT_DIR=$DATA_DIR/output
SUBMISSION_DIR=$DATA_DIR/submissions
ANNOTATION_DIR=$DATA_DIR/annotations/semeval-2022_task02_idiomacity/subtask_b
CONFIGURATION_DIR=experiments/semeval-2022_task02_idiomacity/subtask_b
declare -a models=(bert-base-multilingual-cased xlm-roberta-base xlm-roberta-large)
#declare -a models=(bert-base-multilingual-cased)
#declare -a models=(xlm-roberta-large)
declare -a seq2vec_encoder_types=("boe" "cls_pooler")
declare -a splits=(finetune_train finetune_validation test)
declare -a finetune_model_types=("sentence_embedder" "span_embedder" "sentence_span_embedder_mean" "sentence_span_embedder_concat")
declare -a span_extractor_types=("endpoint" "self_attentive" "max_pooling")
#declare -a span_extractor_types=("max_pooling")
declare -a combinations=("x,y" "x,y,xy" "x,y,x-y" "x,y,xy,x-y")
cd "$WORK_DIR" || exit
function inference() {
FINETUNE_PREDICT_OUTPUT="${FINETUNE_MODEL_PATH}"/test_predict.csv
if [ ! -f "$FINETUNE_PREDICT_OUTPUT" ]; then
allennlp predict \
"${FINETUNE_MODEL_PATH}"/model.tar.gz \
"${ANNOTATION_DIR}"/finetune/test.jsonl \
--predictor semeval-2022_task02_idiomacity_subtask_b \
--output-file "${FINETUNE_PREDICT_OUTPUT}" \
--include-package ciyi --cuda-device 0
fi
}
function submission() {
setting="${SUBMISSION_DIR}/$1"
mkdir -p "$setting"
echo "ID,Language,Setting,Sim" >"$setting"/task2_subtaskb.csv
cat "${PRETRAIN_MODEL_PATH}"/test_predict.csv >>"$setting"/task2_subtaskb.csv
cat "${FINETUNE_MODEL_PATH}"/test_predict.csv >>"$setting"/task2_subtaskb.csv
}
function train_endpoint() {
for com in "${combinations[@]}"; do
finetune_setting="$1/$com"
echo "$finetune_setting"
FINETUNE_MODEL_PATH="${OUTPUT_DIR}"/semeval-2022_task02_idiomacity/SubTaskB/finetune/"$finetune_setting"
if [ -z "$PRETRAINED_MODEL_PATH" ]; then
mp=$m
else
mp=$PRETRAINED_MODEL_PATH/$m
fi
if [ ! -f "$FINETUNE_MODEL_PATH"/model.tar.gz ]; then
rm -r "$FINETUNE_MODEL_PATH"
TOKENIZERS_PARALLELISM=false TRANSFORMER_LAYER=$l ANNOTATION_DIR=${ANNOTATION_DIR}/finetune \
MODEL_NAME=$mp MODEL_TYPE=$f SEQ2VEC_ENCODER_TYPE=$enc \
SPAN_EXTRACTOR_TYPE=endpoint ENDPOINT_SPAN_EXTRACTOR_COMBINATION=$com \
allennlp train ${CONFIGURATION_DIR}/finetune.jsonnet \
-s "${FINETUNE_MODEL_PATH}" \
--include-package ciyi
fi
FINETUNE_PREDICT_OUTPUT="${FINETUNE_MODEL_PATH}"/test_predict.csv
if [ ! -f "$FINETUNE_PREDICT_OUTPUT" ]; then
allennlp predict \
"${FINETUNE_MODEL_PATH}"/model.tar.gz \
"${ANNOTATION_DIR}"/finetune/test.jsonl \
--predictor semeval-2022_task02_idiomacity_subtask_b \
--output-file "${FINETUNE_PREDICT_OUTPUT}" \
--include-package ciyi --cuda-device 0
fi
inference "$finetune_setting"
submission "$finetune_setting"
done
}
function train_others() {
finetune_setting="$1/$com"
echo "$finetune_setting"
FINETUNE_MODEL_PATH="${OUTPUT_DIR}"/semeval-2022_task02_idiomacity/SubTaskB/finetune/"$finetune_setting"
if [ -z "$PRETRAINED_MODEL_PATH" ]; then
mp=$m
else
mp=$PRETRAINED_MODEL_PATH/$m
fi
if [ ! -f "$FINETUNE_MODEL_PATH"/model.tar.gz ]; then
rm -r "$FINETUNE_MODEL_PATH"
TOKENIZERS_PARALLELISM=false TRANSFORMER_LAYER=$l ANNOTATION_DIR=${ANNOTATION_DIR}/finetune \
MODEL_NAME=$mp MODEL_TYPE=$f SEQ2VEC_ENCODER_TYPE=$enc \
SPAN_EXTRACTOR_TYPE=$s \
allennlp train ${CONFIGURATION_DIR}/finetune.jsonnet \
-s "${FINETUNE_MODEL_PATH}" \
--include-package ciyi
fi
inference "$finetune_setting"
submission "$finetune_setting"
}
for m in "${models[@]}"; do
if [ "$m" == 'xlm-roberta-large' ]; then
l=24
else
l=12
fi
for enc in "${seq2vec_encoder_types[@]}"; do
pretrain_setting="$m"/"$l"/"$enc"
echo "$pretrain_setting"
if [ -z "$PRETRAINED_MODEL_PATH" ]; then
mp=$m
else
mp=$PRETRAINED_MODEL_PATH/$m
fi
PRETRAIN_MODEL_PATH="${OUTPUT_DIR}"/semeval-2022_task02_idiomacity/SubTaskB/pretrain/"$pretrain_setting"
if [ ! -f "$PRETRAIN_MODEL_PATH"/model.tar.gz ]; then
rm -r "$PRETRAIN_MODEL_PATH"
TOKENIZERS_PARALLELISM=false TRANSFORMER_LAYER=$l ANNOTATION_DIR=${ANNOTATION_DIR}/pretrain \
MODEL_NAME=$mp SEQ2VEC_ENCODER_TYPE=$enc \
allennlp train ${CONFIGURATION_DIR}/pretrain.jsonnet \
-s "${PRETRAIN_MODEL_PATH}" \
--include-package ciyi
fi
for s in "${splits[@]}"; do
PREDICT_OUTPUT="${PRETRAIN_MODEL_PATH}"/"$s"_predict.csv
if [ ! -f "$PREDICT_OUTPUT" ]; then
allennlp predict \
"${PRETRAIN_MODEL_PATH}"/model.tar.gz \
"${ANNOTATION_DIR}"/predict/"$s".jsonl \
--predictor semeval-2022_task02_idiomacity_subtask_b \
--output-file "${PREDICT_OUTPUT}" \
--include-package ciyi --cuda-device 0
fi
done
python3 ${CONFIGURATION_DIR}/update_data.py \
--annotation_location "${ANNOTATION_DIR}"/finetune \
--prediction_location "${PRETRAIN_MODEL_PATH}"
for f in "${finetune_model_types[@]}"; do
for s in "${span_extractor_types[@]}"; do
if [ "$s" == "endpoint" ]; then
train_endpoint "$pretrain_setting/$f/$s"
else
train_others "$pretrain_setting/$f/$s"
fi
done
done
done
done