|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Copyright 2012 Johns Hopkins University (Author: Daniel Povey) |
| 4 | +# Apache 2.0 |
| 5 | + |
| 6 | +# Begin configuration. |
| 7 | +nj=4 |
| 8 | +cmd=run.pl |
| 9 | +maxactive=7000 |
| 10 | +beam=15.0 |
| 11 | +lattice_beam=8.0 |
| 12 | +expand_beam=30.0 |
| 13 | +acwt=1.0 |
| 14 | +skip_scoring=false |
| 15 | +combine_version=false |
| 16 | + |
| 17 | +stage=0 |
| 18 | +online_ivector_dir= |
| 19 | +post_decode_acwt=10.0 |
| 20 | +extra_left_context=0 |
| 21 | +extra_right_context=0 |
| 22 | +extra_left_context_initial=0 |
| 23 | +extra_right_context_final=0 |
| 24 | +chunk_width=140,100,160 |
| 25 | +use_gpu=no |
| 26 | +# End configuration. |
| 27 | + |
| 28 | +echo "$0 $@" # Print the command line for logging |
| 29 | + |
| 30 | +[ -f ./path.sh ] && . ./path.sh; # source the path. |
| 31 | +. parse_options.sh || exit 1; |
| 32 | + |
| 33 | +if [ $# != 5 ]; then |
| 34 | + echo "Usage: steps/decode_combine_test.sh [options] <graph-dir> <data-dir> <decode-dir>" |
| 35 | + echo "... where <decode-dir> is assumed to be a sub-directory of the directory" |
| 36 | + echo " where the model is." |
| 37 | + echo "e.g.: steps/decode_combine_test.sh exp/mono/graph_tgpar data/test_dev93 exp/mono/decode_dev93_tgpr" |
| 38 | + echo "" |
| 39 | + echo "This script works on CMN + (delta+delta-delta | LDA+MLLT) features; it works out" |
| 40 | + echo "what type of features you used (assuming it's one of these two)" |
| 41 | + echo "" |
| 42 | + echo "main options (for others, see top of script file)" |
| 43 | + echo " --config <config-file> # config containing options" |
| 44 | + echo " --nj <nj> # number of parallel jobs" |
| 45 | + echo " --cmd (utils/run.pl|utils/queue.pl <queue opts>) # how to run jobs." |
| 46 | + exit 1; |
| 47 | +fi |
| 48 | + |
| 49 | + |
| 50 | +graphdir=$1 |
| 51 | +data=$2 |
| 52 | +dir=$3 |
| 53 | + |
| 54 | +srcdir=`dirname $dir`; # The model directory is one level up from decoding directory. |
| 55 | +sdata=$data/split$nj; |
| 56 | +splice_opts=`cat $srcdir/splice_opts 2>/dev/null` |
| 57 | +cmvn_opts=`cat $srcdir/cmvn_opts 2>/dev/null` |
| 58 | +delta_opts=`cat $srcdir/delta_opts 2>/dev/null` |
| 59 | + |
| 60 | +mkdir -p $dir/log |
| 61 | +[[ -d $sdata && $data/feats.scp -ot $sdata ]] || split_data.sh $data $nj || exit 1; |
| 62 | +echo $nj > $dir/num_jobs |
| 63 | + |
| 64 | + |
| 65 | +for f in $sdata/1/feats.scp $sdata/1/cmvn.scp $srcdir/final.mdl $graphdir/HCLG.fst $oldlm_fst $newlm_fst; do |
| 66 | + [ ! -f $f ] && echo "decode_si.sh: no such file $f" && exit 1; |
| 67 | +done |
| 68 | + |
| 69 | + |
| 70 | +if [ -f $srcdir/final.mat ]; then feat_type=lda; else feat_type=delta; fi |
| 71 | +echo "decode_combine_test.sh: feature type is $feat_type" |
| 72 | + |
| 73 | +feats="ark,s,cs:apply-cmvn $cmvn_opts --utt2spk=ark:$sdata/JOB/utt2spk scp:$sdata/JOB/cmvn.scp scp:$sdata/JOB/feats.scp ark:- |" |
| 74 | + |
| 75 | +posteriors="ark,scp:$sdata/JOB/posterior.ark,$sdata/JOB/posterior.scp" |
| 76 | +posteriors_scp="scp:$sdata/JOB/posterior.scp" |
| 77 | + |
| 78 | +if [ ! -z "$online_ivector_dir" ]; then |
| 79 | + ivector_period=$(cat $online_ivector_dir/ivector_period) || exit 1; |
| 80 | + ivector_opts="--online-ivectors=scp:$online_ivector_dir/ivector_online.scp --online-ivector-period=$ivector_period" |
| 81 | +fi |
| 82 | + |
| 83 | +if [ "$post_decode_acwt" == 1.0 ]; then |
| 84 | + lat_wspecifier="ark:|gzip -c >$dir/lat.JOB.gz" |
| 85 | +else |
| 86 | + lat_wspecifier="ark:|lattice-scale --acoustic-scale=$post_decode_acwt ark:- ark:- | gzip -c >$dir/lat.JOB.gz" |
| 87 | +fi |
| 88 | + |
| 89 | +frame_subsampling_opt= |
| 90 | +if [ -f $srcdir/frame_subsampling_factor ]; then |
| 91 | + # e.g. for 'chain' systems |
| 92 | + frame_subsampling_opt="--frame-subsampling-factor=$(cat $srcdir/frame_subsampling_factor)" |
| 93 | +fi |
| 94 | + |
| 95 | +frames_per_chunk=$(echo $chunk_width | cut -d, -f1) |
| 96 | +# generate log-likelihood |
| 97 | +if [ $stage -le 1 ]; then |
| 98 | + $cmd JOB=1:$nj $dir/log/nnet_compute.JOB.log \ |
| 99 | + nnet3-compute $ivector_opts $frame_subsampling_opt \ |
| 100 | + --acoustic-scale=$acwt \ |
| 101 | + --extra-left-context=$extra_left_context \ |
| 102 | + --extra-right-context=$extra_right_context \ |
| 103 | + --extra-left-context-initial=$extra_left_context_initial \ |
| 104 | + --extra-right-context-final=$extra_right_context_final \ |
| 105 | + --frames-per-chunk=$frames_per_chunk \ |
| 106 | + --use-gpu=$use_gpu --use-priors=true \ |
| 107 | + $srcdir/final.mdl "$feats" "$posteriors" |
| 108 | +fi |
| 109 | + |
| 110 | +if [ $stage -le 2 ]; then |
| 111 | + suffix= |
| 112 | + if $combine_version ; then |
| 113 | + suffix="-combine" |
| 114 | + fi |
| 115 | + $cmd JOB=1:$nj $dir/log/decode.JOB.log \ |
| 116 | + latgen-faster-mapped$suffix --max-active=$maxactive --beam=$beam --lattice-beam=$lattice_beam |
| 117 | + --acoustic-scale=$acwt --allow-partial=true --word-symbol-table=$graphdir/words.txt \ |
| 118 | + $srcdir/final.mdl $graphdir/HCLG.fst "$posteriors_scp" "$lat_wspecifier" || exit 1; |
| 119 | +fi |
| 120 | + |
| 121 | +if ! $skip_scoring ; then |
| 122 | + [ ! -x local/score.sh ] && \ |
| 123 | + echo "Not scoring because local/score.sh does not exist or not executable." && exit 1; |
| 124 | + local/score.sh --cmd "$cmd" $data $graphdir $dir || |
| 125 | + { echo "$0: Scoring failed. (ignore by '--skip-scoring true')"; exit 1; } |
| 126 | +fi |
| 127 | + |
| 128 | +exit 0; |
0 commit comments