forked from facebookresearch/flores
-
Notifications
You must be signed in to change notification settings - Fork 0
/
score.sh
executable file
·88 lines (75 loc) · 1.39 KB
/
score.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
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
usage(){
cat >&2 <<EOF
Description: Score a lanauage pair
Usage: $(basename "${0}") [options] [--]
Options:
-f
Set FP16 for running the model
-s
Source language code
-g
Set GPU indices to use ('0' or '0,1,2', etc)
-d
Set script debug mode
-h
Show usage and exit
EOF
}
CUDA_VISIBLE_DEVICES=0
TARGET_LANG=en
EXTRA_ARGS=()
while getopts ":dfg:s:h" opt; do
case "$opt" in
f)
EXTRA_ARGS+=(--fp16)
;;
g)
CUDA_VISIBLE_DEVICES="${OPTARG}"
;;
s)
SOURCE_LANG="${OPTARG}"
;;
d)
DEBUG=1
set -x
;;
h)
usage
exit 0
;;
*)
echo -e "\nOption does not exist: $OPTARG\n" >&2
usage
exit 1
;;
esac
done
shift "$((OPTIND-1))"
export CUDA_VISIBLE_DEVICES
export CUDA_DEVICE_ORDER="PCI_BUS_ID"
if [[ -z ${SOURCE_LANG-} ]]; then
echo -e >&2 "SOURCE_LANG is required!\n"
usage
exit 1
fi
DATA_DIR="data-bin/wiki_${SOURCE_LANG}_en_bpe5000"
if [[ ! -d "$DATA_DIR" ]]; then
echo >&2 "DATA_DIR $DATA_DIR is missing!"
usage
exit 1
fi
MODEL_DIR="models/$SOURCE_LANG"
fairseq-generate \
"$DATA_DIR" \
--source-lang "$SOURCE_LANG" \
--target-lang en \
--path "$MODEL_DIR/checkpoint_best.pt" \
--beam 5 \
--lenpen 1.2 \
--gen-subset valid \
--remove-bpe=sentencepiece \
--scoring sacrebleu \
"${EXTRA_ARGS[@]}"