#! /bin/bash -e # Copyright (c) 2009 Takahiro Shinozaki # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # cvadapt.bash [-debug] [-config config] [-tmpdtop tmpdtop] [-workd workd] [-scpcva scpcva] [-doneflg doneflg] # cv adaptation ## This script uses cd inside assuming absolute pass is given for files # Thu Jun 4 19:06:07 JST 2009 # Takahiro Shinozaki [ -n "$debug" ] && set -x scriptp=$0 script=`basename $0` # initialize local variables if [ -z "$doneflg" ]; then doneflg=done; fi if [ -z "$envlog" ]; then envlog=env.log; fi if [ -z "$id" ]; then id=out; fi function usage { echo "Usage: $script [-debug]" echo " [-config conf : CONFIGURATION]" echo " [-tmpdtop tmpdtop : tmp dir]" echo " [-workd workd : work directory]" echo " [-scpcva scpcva : feature list file for decoder 1]" echo " [-doneflg DONE_FLAG]" exit 1 } while [ -n "$1" ]; do case "$1" in -debug) shift; export debug=1; set -x;; -config) shift; export config=$1; shift; . $config;; -tmpdtop) shift; export tmpdtop="$1"; shift;; -workd) shift; workd="$1"; shift;; -scpcva) shift; export scpcva="$1"; shift;; -doneflg) shift; doneflg="$1"; shift;; *) echo "Unknown option : $1"; usage; esac done if [ -n "$workd" ]; then cd $workd fi pwd=`pwd` if [ -f "$doneflg" ]; then echo "Nothing to do ($script)." exit 0 fi if [ -n "$tmpdtop" ]; then if [ ! -e "$tmpdtop" ]; then mkdir -p $tmpdtop fi files=`ls $tmpdtop | wc -l ` if [ "$files" != 0 ]; then echo "Error: tmpdir is not empty $tmpdtop" exit 1 fi tmpd=$tmpdtop else tmpd=$pwd fi # dump environmental variables env > $envlog # print process info echo "" echo "*** $script START ***" date hostname pwd if [ ! -e "$script" ]; then cp -p $scriptp . fi # print settings echo debug=$debug echo config=$config echo decoder=$decoder echo scpcva=$scpcva echo id=$id echo hmm0cva=$hmm0cva echo adphlistcv=$adphlistcv echo adpclscva=$adpclscva echo adptconfcva=$adptconfcva echo niter=$niter echo herest=$herest echo ncv=$ncv echo tmpdtop=$tmpdtop # check requirments if [ "$decoder" = "" ]; then echo decoder is not defined; exit 1; fi if [ "$scpcva" = "" ]; then echo scpcva is not defined; exit 1; fi if [ "$hmm0cva" = "" ]; then echo hmm0cva is not defined; exit 1; fi if [ "$adphlistcv" = "" ]; then echo adphlistcv is not defined; exit 1; fi if [ "$adpclscva" = "" ]; then echo adpclscva is not defined; exit 1; fi if [ "$adptconfcva" = "" ]; then echo adptconfcva is not defined; exit 1; fi if [ "$niter" = "" ]; then echo niter is not defined; exit 1; fi if [ "$ncv" = "" ]; then echo ncv is not defined; exit 1; fi ## subdivide mkdir -p sdscpd randl.pl -s 1 $scpcva | subdivide.pl - $ncv sdscpd scp ## make complement mkdir -p sdscpdc for i in `seq 1 $ncv`; do ls sdscpd/* | grep -v "scp.$i$" | xargs cat > sdscpdc/scp.$i done if [ -z "$herest" ]; then herest=HERest fi sdscpd=$pwd/sdscpd sdscpdc=$pwd/sdscpdc hmmcvafname=`basename $hmm0cva` hmmcva=$hmm0cva for iter in `seq 0 $niter`; do cd $pwd stepd="iter-$iter" if [ -f "$stepd/done" ]; then echo "skip step $iter." continue fi mkdir -p $stepd mkdir -p $tmpd/$stepd dcdcv=$stepd/decode # decoding mkdir -p $dcdcv mkdir -p $tmpd/$dcdcv for i in `seq 1 $ncv`; do dcdlog=dcd.$i.log mkdir -p $dcdcv/cv$i mkdir -p $tmpd/$dcdcv/cv$i cd $pwd/$dcdcv/cv$i export scrhlist=$adphlistcv if [ -e $hmmcva.$i ]; then hmm=$hmmcva.$i else hmm=$hmmcva fi $decoder -tmpdtop $tmpd/$dcdcv/cv$i -hmm $hmm -scp $sdscpd/scp.$i -id $id >& $dcdlog rmdir $tmpd/$dcdcv cd $pwd done # gather MLF echo '#!MLF!#' > $dcdcv/$id.score.mlf echo '#!MLF!#' > $dcdcv/$id.tri.mlf cat $dcdcv/cv*/$id.score.mlf | grep -v '#!MLF!#' >> $dcdcv/$id.score.mlf cat $dcdcv/cv*/$id.tri.mlf | grep -v '#!MLF!#' >> $dcdcv/$id.tri.mlf # adaptation adptd=$stepd/adapt mlfhyp=$pwd/$dcdcv/$id.tri.mlf mkdir -p $adptd mkdir -p $tmpd/$adptd cd $pwd/$adptd for i in `seq 0 $ncv`; do if [ "$i" = 0 ]; then scp=$scpcva hmm=$hmmcva else scp=$sdscpdc/scp.$i if [ -e $hmmcva.$i ]; then hmm=$hmmcva.$i else hmm=$hmmcva fi fi cmd="$herest -T 1 -C $adptconfcva \ -S $scp -I $mlfhyp -H $hmm -K $tmpd/$adptd adapted -J $adpclscva -u a $adphlistcv" echo $cmd $cmd nhmm=`ls $tmpd/$adptd/$hmmcvafname.*.adapted | wc -l` if [ "$nhmm" -ne 1 ]; then echo "Error: expects a single HMM is produced" exit 1 fi if [ "$i" = 0 ]; then mv $tmpd/$adptd/$hmmcvafname.*.adapted $tmpd/$adptd/$hmmcvafname mv $tmpd/$adptd/*.adapted transform else mv $tmpd/$adptd/$hmmcvafname.*.adapted $tmpd/$adptd/$hmmcvafname.$i mv $tmpd/$adptd/*.adapted transform.$i fi done cd $pwd pre=$(( $iter - 1 )) if [ "$pre" -ge 0 ]; then mv $tmpd/iter-$pre/adapt/$hmmcvafname iter-$pre/adapt rm $tmpd/iter-$pre/adapt/$hmmcvafname.* rmdir $tmpd/iter-$pre/adapt rmdir $tmpd/iter-$pre fi hmmcva=$tmpd/$adptd/$hmmcvafname touch $stepd/done done mv $tmpd/iter-$niter/adapt/$hmmcvafname iter-$niter/adapt rm $tmpd/iter-$niter/adapt/$hmmcvafname.* rmdir $tmpd/iter-$niter/adapt rmdir $tmpd/iter-$niter if [ -n "$tmpdtop" ]; then rmdir $tmpdtop fi touch $doneflg echo "*** $script END ***"