📄 enhanced-mert
字号:
#! /bin/shPrintUsageAndDie(){echo "USAGE: enhanced-cmert.sh -d size [-active] [-help]"echo " perform cmert on a subset of the feature scores"echo " the ratios among not activated weights are not modified"echo " Parameters (*=optional):"echo " -d: the number of original features"echo " -activate (*): comma-separated (or blank-separated) list of the indexes of active features"echo " if not set, all features are optimized"echo " -debug(*): debug information"echo " -help(*): print his help"echoecho "Example: see examples in the directory example which are created with the script readme.txt"exit}normalize_weights(){perl -ne '{$tot=0;chomp;split;grep($tot+=($_>0)?$_:-$_,@_); grep($_/=$tot,@_); for ($i=0;$i<scalar(@_);$i++){printf STDOUT "%.6f ",$_[$i];};printf STDOUT "\n";}'}activeflag=0;help=0debug=""if [ $# -lt 1 ] ; then PrintUsageAndDie ; fiwhile [ $# -gt 0 ]do case $1 in -help) help=1 ; shift 1 ; ;; -d) size=$2 ; shift 2 ; ;; -debug) debug="-debug"; shift 1 ; ;; -activate) activeflag=1 ; activefields=$2 ; shift 2 ; ;; *) shift $# ; ;; esacdoneif [ $help == 1 ] ; then PrintUsageAndDie ; fi# call the basic mert commandif [ $activeflag == 0 ] ; then$SCRIPTS_ROOTDIR/training/cmert-0.5/mert -d $sizeexitfi# else if [ $debug ] ; then echo "names of active fields: $activefields" ; fi#get indexes of active fields from file "names.txtoldname="__FALSE_NAME__"name="__FALSE_NAME__"separator="_"i=1 lastj=1for name in `cat names.txt` ; doif [ $name == $oldname ] ; then i=$(( i + 1 )) ; else i=1 ; fiarrayname[$lastj]=$namearrayname2[$lastj]=$name$separator$ilastj=$(( lastj + 1 ))oldname=$namedone#map feature names into feature indexesout=""for name in `echo $activefields | tr ',' ' ' ` ; domatch=0; j=1while [ $j -lt $lastj ] ; doif [ ${arrayname[$j]} == $name -o ${arrayname2[$j]} == "$name" ] ; thenmatch=$jif [ $out ] ; then out="$out,$j" ; else out="$j" ; fifij=$(( j + 1 ))doneif [ $match -eq 0 ] ; then echo "feature $name you are asking for is not present" ; fidoneactivefields=`echo $out | tr ',' '\012' | sort -nu | tr '\012' ',' | perl -pe 's/\,$//' `if [ $debug ] ; then echo "indexes of active fields: $activefields" ; fi#filter active fields, perform cmert and ...tmpdir=tmp$$mkdir -p $tmpdirfor file in feats.opt init.opt ; domv $file $tmpdirdonecat $tmpdir/init.opt | tail -1 > $tmpdir/weight.optcat $tmpdir/init.opt | perl $SCRIPTS_ROOTDIR/training/cmert-0.5/reduce-field.pl $debug -weight $tmpdir/weight.opt -d $size -activate $activefields | perl -pe 's/^\S+ /1 /' > init.optcat $tmpdir/feats.opt | perl $SCRIPTS_ROOTDIR/training/cmert-0.5/reduce-field.pl $debug -weight $tmpdir/weight.opt -d $size -activate $activefields > feats.optactive=`cat init.opt | head -1 | awk '{print NF}'` $SCRIPTS_ROOTDIR/training/cmert-0.5/mert -d $active 2> reduced_cmert.log for file in feats.opt init.opt; domv $file reduced_$filemv $tmpdir/$file $filedonemv weights.txt reduced_weights.txtcat reduced_weights.txt | perl $SCRIPTS_ROOTDIR/training/cmert-0.5/extend-field.pl $debug -weight $tmpdir/weight.opt -d $size -activate $activefields | normalize_weights > weights.txtrm -r $tmpdirbestpointline=`echo "Best point:"`bestpointline="$bestpointline "`cat weights.txt`bestpointline="$bestpointline => "`cat reduced_cmert.log | grep -i "Best point:" | awk '{print $NF}'`echo $bestpointline > /dev/stderrexit
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -