-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathvalidate.sh
executable file
·42 lines (30 loc) · 1.17 KB
/
validate.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
#!/bin/sh
# path to nematus ( https://www.github.com/rsennrich/nematus )
nematus=/path/to/nematus
# path to moses decoder: https://github.com/moses-smt/mosesdecoder
mosesdecoder=/path/to/mosesdecoder
# theano device, in case you do not want to compute on gpu, change it to cpu
device=gpu
#model prefix
prefix=model/model.npz
dev=data/newstest2013.factors.en
ref=data/newstest2013.tok.de
# decode
THEANO_FLAGS=mode=FAST_RUN,floatX=float32,device=$device,on_unused_input=warn python $nematus/nematus/translate.py \
-m $prefix.dev.npz \
-i $dev \
-o $dev.output.dev \
-k 12 -n -p 1
./postprocess-dev.sh < $dev.output.dev > $dev.output.postprocessed.dev
## get BLEU
BEST=`cat ${prefix}_best_bleu || echo 0`
$mosesdecoder/scripts/generic/multi-bleu.perl $ref < $dev.output.postprocessed.dev >> ${prefix}_bleu_scores
BLEU=`$mosesdecoder/scripts/generic/multi-bleu.perl $ref < $dev.output.postprocessed.dev | cut -f 3 -d ' ' | cut -f 1 -d ','`
BETTER=`echo "$BLEU > $BEST" | bc`
echo "BLEU = $BLEU"
# save model with highest BLEU
if [ "$BETTER" = "1" ]; then
echo "new best; saving"
echo $BLEU > ${prefix}_best_bleu
cp ${prefix}.dev.npz ${prefix}.npz.best_bleu
fi