-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_wikinewsmax.sh
executable file
·138 lines (107 loc) · 4.2 KB
/
run_wikinewsmax.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
#!/bin/bash
# Get the parent directory of this script
SCRIPT_DIR="$(dirname $(realpath "$0"))"
# List of genres to be evaluated
DATASETS=(
"dediac_max_gold"
"dediac_orig_gold"
)
DATA_DIR="${SCRIPT_DIR}/data/wikinewsmax"
PRED_DIR="${SCRIPT_DIR}/output/predictions/wikinewsmax"
EVAL_DIR="${SCRIPT_DIR}/output/eval/wikinewsmax"
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 dataset
function gen_predictions_original () {
DATASET="$1"
INPUT_PATH="${DATA_DIR}/${DATASET}.tsv"
OUTPUT_PATH="${PRED_DIR}/${DATASET}.original.tsv"
DB_PATH="${SCRIPT_DIR}/databases/calima-msa-s31.db"
printf ">>> Generating diac predictions for ${DATASET} using original CAMeL Tools...\n"
python3 "${SCRIPT_DIR}/gen_predictions_sent.py" "${INPUT_PATH}" \
--db "${DB_ORIG_PATH}" \
--ct-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 dataset
function gen_predictions_extended () {
DATASET="$1"
INPUT_PATH="${SCRIPT_DIR}/data/wikinewsmax/${DATASET}.tsv"
OUTPUT_PATH="${SCRIPT_DIR}/output/predictions/wikinewsmax/${DATASET}.extended.tsv"
DB_PATH="${SCRIPT_DIR}/databases/calima-msa-s31-extended.db"
printf ">>> Generating diac predictions for ${DATASET} using extended CAMeL Tools...\n"
python3 "${SCRIPT_DIR}/gen_predictions_sent.py" "${INPUT_PATH}" \
--db "${DB_EXT_PATH}" \
--ctpp-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 () {
DATASETS="$1"
INPUT_DIR="${SCRIPT_DIR}/data/wikinewsmax"
for DATASET in ${DATASETS[@]}; do
OUTPUT_PATH="${EVAL_DIR}/${DATASET}.original.tsv"
DATASET_PATH_ARG="${DATASET}:${PRED_DIR}/${DATASET}.original.tsv"
printf ">>> Evaluating predictions for ${DATASET} using original CAMeL Tools...\n"
python3 "${SCRIPT_DIR}/evaluate.py" --output "${OUTPUT_PATH}" \
--ct-noctx --oov \
--norm-diac --norm-consonants --use-gold-alt \
"${DATASET_PATH_ARG}"
if [ $? -ne 0 ]; then
exit 1
fi
done
}
# Function that evaluates predictions generated using modified CAMeL Tools with
# extentions for a given list of genres
function evaluate_extended () {
DATASETS="$1"
INPUT_DIR="${SCRIPT_DIR}/data/wikinewsmax"
for DATASET in ${DATASETS[@]}; do
OUTPUT_PATH="${EVAL_DIR}/${DATASET}.extended.tsv"
DATASET_PATH_ARG="${DATASET}:${PRED_DIR}/${DATASET}.extended.tsv"
printf ">>> Evaluating predictions for ${DATASET} using extended CAMeL Tools...\n"
python3 "${SCRIPT_DIR}/evaluate.py" --output "${OUTPUT_PATH}" \
--ctpp-fullctx --oov \
--norm-diac --norm-consonants --use-gold-alt \
"${DATASET_PATH_ARG}"
if [ $? -ne 0 ]; then
exit 1
fi
done
}
# 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 "${SCRIPT_DIR}/output/predictions/wikinewsmax"
mkdir -p "${SCRIPT_DIR}/output/eval/wikinewsmax"
# 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 DATASET in ${DATASETS[@]}; do
gen_predictions_extended ${DATASET}
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 DATASET in ${DATASETS[@]}; do
gen_predictions_original ${DATASET}
done
# Evaluate original and extended predictions seperately
evaluate_original ${DATASETS}
evaluate_extended ${DATASETS}
# Deactivate the original CAMeL Tools environment
deactivate