mosesdecoder/scripts/training/cmert-0.5/mert-driver
nicolabertoldi 26aff6ead9 managing of pwd/pawd
git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@1101 1f5c12ca-751b-0410-a591-d2e778427230
2006-12-29 13:19:21 +00:00

89 lines
2.0 KiB
Bash
Executable File

#!/bin/sh
WORKDIR=$1
if [ ! -d $WORKDIR ]; then
mkdir -p $WORKDIR
fi
SRCFILE=$2
REFPREFIX=$3
REFFILES=$REFPREFIX[0-9]*
NBEST=$4
DECODER=$5
DECODEROPTS=$6
RANGES=$7
START=$8
#default pwdcmd is pwd
#pwdcmd is pawd if exists
PWDCMD="pwd"
___PWDCMD=`which pawd | head -1 | awk '{print $1}'`
if [ $___PWDCMD -a -e $___PWDCMD ] ; then PWDCMD=$___PWDCMD ; fi;
RUNDIR=`$PWDCMD`
makeinitopt "$RANGES" $WORKDIR/weights.txt $WORKDIR/ranges.txt
DIM=`cat $WORKDIR/weights.txt | awk '{print NF; exit}'`
echo $DIM dimensions
PATH=/group/project/statmt/pkoehn/user/abhishek:/group/project/statmt/pkoehn/user/abhishek/cmert-0.5:$PATH
export PATH
date
echo Reference sets: $REFFILES
if [ "x$START" == "x" ]; then
START=1
fi
I=$START
PREVLINECOUNT=0
#$DECODEROPTS =~ s / \-f / -config /;
#$DECODEROPTS =~ s/^\-f /-config /;
filename=$WORKDIR/run$I.best$NBEST.out
while true; do
echo Run decoder
WEIGHTS=`cat $WORKDIR/weights.txt`
###Changes - AA 29/11/05
#echo "$DECODER $NBEST \"$WEIGHTS\" $WORKDIR/run$I \"$DECODEROPTS\" < $SRCFILE > $WORKDIR/run$I.nbest"
#$DECODER $NBEST \"$WEIGHTS\" $WORKDIR/run$I \"$DECODEROPTS\" < $SRCFILE > $WORKDIR/run$I.nbest
echo "$DECODER $DECODEROPTS \"$WEIGHTS\" -n-best-list $filename $NBEST < $SRCFILE > $WORKDIR/run$I.nbest"
$DECODER $DECODEROPTS "$WEIGHTS" -n-best-list $filename $NBEST < $SRCFILE > $WORKDIR/run$I.nbest
echo Calculate BLEU component scores
sort -mn -t\| -k 1,1 $WORKDIR/run*.nbest | score-nbest.py $REFFILES $WORKDIR/
#LINECOUNT=`cat $WORKDIR/feats.opt | awk '{n++} END {print n}'`
LINECOUNT=`cat $WORKDIR/cands.opt | awk '{n += $2} END {print n}'`
echo $LINECOUNT accumulated translations
if [ $LINECOUNT -le $PREVLINECOUNT ]; then
echo "Training finished"
date
break
fi
echo Optimize feature weights
cd $WORKDIR
cat ranges.txt weights.txt > init.opt
rm -f weights.txt
mert -d$DIM
cd $RUNDIR
if [ "x`cat $WORKDIR/weights.txt`" == "x" ]; then
echo Optimization failed
break
fi
I=`expr $I + 1`
PREVLINECOUNT=$LINECOUNT
date
done