-
Notifications
You must be signed in to change notification settings - Fork 65
/
compute_metrics.sh
29 lines (22 loc) · 1.3 KB
/
compute_metrics.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
#!/bin/bash
# This script compute the evaluation metrics such as BLEU, chrF, chrF++ using the
# detokenized predictions of the translation systems using sacrebleu (version 2.3.1).
# If the target language is:
# English: directly use Moses tokenizer that is internally supported (`mteval-v13a`)
# Indic: use IndicNLP tokenizers and skip tokenization step in sacrebleu.
echo `date`
pred_fname=$1 # path to the predction file
ref_fname=$2 # path to the reference file
tgt_lang=$3 # target language
if [ $tgt_lang == 'eng_Latn' ]; then
# directly tokenize the prediction and reference files using sacrebleu and compute the metric
sacrebleu $ref_fname < $pred_fname -m bleu chrf
sacrebleu $ref_fname < $pred_fname -m chrf --chrf-word-order 2
else
# indicnlp tokenize prediction and reference files before evaluation
input_size=`python scripts/preprocess_translate.py $ref_fname $ref_fname.tok $tgt_lang false false`
input_size=`python scripts/preprocess_translate.py $pred_fname $pred_fname.tok $tgt_lang false false`
# since we are tokenizing with indicnlp separately, we are setting tokenize to none here
sacrebleu --tokenize none $ref_fname.tok < $pred_fname.tok -m bleu chrf
sacrebleu --tokenize none $ref_fname.tok < $pred_fname.tok -m chrf --chrf-word-order 2
fi