-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_wild2max_dev.sh
executable file
·142 lines (111 loc) · 4.01 KB
/
run_wild2max_dev.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
#!/bin/bash
# Get the parent directory of this script
SCRIPT_DIR="$(dirname $(realpath "$0"))"
# List of genres to be evaluated
GENRES=(
"chatgpt"
"children"
"news"
"novels"
"poetry"
"un"
)
DATA_DIR="${SCRIPT_DIR}/data/wild2max/dev"
PRED_DIR="${SCRIPT_DIR}/output/predictions/wild2max/dev"
EVAL_DIR="${SCRIPT_DIR}/output/eval/wild2max"
DB_ORIG_PATH="${SCRIPT_DIR}/databases/calima-msa-s31.db"
DB_EXT_PATH="${SCRIPT_DIR}/databases/calima-msa-s31-extended.db"
# Function that generates diacritization predictions using original CAMeL Tools
# for a given genre.
function gen_predictions_original () {
GENRE="$1"
INPUT_PATH="${DATA_DIR}/${GENRE}.tsv"
OUTPUT_PATH="${PRED_DIR}/${GENRE}.original.tsv"
printf ">>> Generating diac predictions for dev/${GENRE} using original CAMeL Tools...\n"
python3 "${SCRIPT_DIR}/gen_predictions_word.py" "${INPUT_PATH}" \
--db "${DB_ORIG_PATH}" \
--ct-noctx --oracle-noctx \
--output "${OUTPUT_PATH}"
if [ $? -ne 0 ]; then
exit 1
fi
}
# Function that generates diacritization predictions using modified CAMeL Tools
# with extentions for a given genre.
function gen_predictions_extended () {
GENRE="$1"
INPUT_PATH="${DATA_DIR}/${GENRE}.tsv"
OUTPUT_PATH="${PRED_DIR}/${GENRE}.extended.tsv"
printf ">>> Generating diac predictions for dev/${GENRE} using extended CAMeL Tools...\n"
python3 "${SCRIPT_DIR}/gen_predictions_word.py" "${INPUT_PATH}" \
--db "${DB_EXT_PATH}" \
--ct-soloctx --ct-fullctx --ctpp-soloctx --ctpp-fullctx \
--oracle-soloctx --oracle-fullctx \
--output ${OUTPUT_PATH}
if [ $? -ne 0 ]; then
exit 1
fi
}
# Function that evaluates predictions generated using original CAMeL Tools for
# a given list of genres.
function evaluate_original () {
GENRES="$1"
OUTPUT_PATH="${EVAL_DIR}/wild2max-dev.original.tsv"
GENRE_PATH_ARGS=()
for GENRE in ${GENRES[@]}; do
GENRE_PATH_ARGS+=("${GENRE}:${PRED_DIR}/${GENRE}.original.tsv")
done
printf ">>> Evaluating predictions for dev/* using original CAMeL Tools...\n"
python3 "${SCRIPT_DIR}/evaluate.py" --output "${OUTPUT_PATH}" \
--ct-noctx --oracle-noctx --oov \
--norm-diac --norm-consonants \
${GENRE_PATH_ARGS[@]}
if [ $? -ne 0 ]; then
exit 1
fi
}
# Function that evaluates predictions generated using modified CAMeL Tools with
# extentions for a given list of genres.
function evaluate_extended () {
GENRES="$1"
OUTPUT_PATH="${EVAL_DIR}/wild2max-dev.extended.tsv"
GENRE_PATH_ARGS=()
for GENRE in ${GENRES[@]}; do
GENRE_PATH_ARGS+=("${GENRE}:${PRED_DIR}/${GENRE}.extended.tsv")
done
printf ">>> Evaluating predictions for dev/* using extended CAMeL Tools...\n"
python3 "${SCRIPT_DIR}/evaluate.py" --output "${OUTPUT_PATH}" \
--ct-soloctx --ct-fullctx --ctpp-soloctx --ctpp-fullctx \
--oracle-soloctx --oracle-fullctx --oov \
--norm-diac --norm-consonants \
${GENRE_PATH_ARGS[@]}
if [ $? -ne 0 ]; then
exit 1
fi
}
# Use custom CAMeL Tools data directory.
export CAMELTOOLS_DATA="${SCRIPT_DIR}/envs/ct_data"
# Create output directories if they don't already exist.
mkdir -p "${PRED_DIR}"
mkdir -p "${EVAL_DIR}"
# Deactivate the current environment (if any).
deactivate &> /dev/null
# Activate the modified CAMeL Tools environment.
source "${SCRIPT_DIR}/envs/modified/bin/activate"
# Generate predictions using modified CAMeL Tools with extentions.
for GENRE in ${GENRES[@]}; do
gen_predictions_extended ${GENRE}
done
# Deactivate the modified CAMeL Tools environment.
deactivate
# Activate the original CAMeL Tools environment.
source "${SCRIPT_DIR}/envs/original/bin/activate"
# Generate predictions using original CAMeL Tools.
for GENRE in ${GENRES[@]}; do
gen_predictions_original ${GENRE}
done
# Evaluate original and extended predictions seperately.
evaluate_original ${GENRES}
evaluate_extended ${GENRES}
# Deactivate the original CAMeL Tools environment.
deactivate