Blame view

Scripts/steps/decode_fmmi.sh 4.86 KB
ec85f8892   bigot benjamin   first commit
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
  #!/bin/bash
  
  # Copyright 2012  Johns Hopkins University (Author: Daniel Povey)
  # Apache 2.0
  # Decoding of fMMI or fMPE models (feature-space discriminative training).
  # If transform-dir supplied, expects e.g. fMLLR transforms in that dir.
  
  # Begin configuration section.  
  stage=1
  iter=final
  nj=4
  cmd=run.pl
  maxactive=7000
  beam=13.0
  latbeam=6.0
  acwt=0.083333 # note: only really affects pruning (scoring is on lattices).
  ngselect=2; # Just use the 2 top Gaussians for fMMI/fMPE.  Should match train.
  transform_dir=
  num_threads=1 # if >1, will use gmm-latgen-faster-parallel
  parallel_opts=  # If you supply num-threads, you should supply this too.
  scoring_opts=
  # End configuration section.
  
  echo "$0 $@"  # Print the command line for logging
  
  [ -f ./path.sh ] && . ./path.sh; # source the path.
  . parse_options.sh || exit 1;
  
  if [ $# != 3 ]; then
     echo "Usage: steps/decode_fmmi.sh [options] <graph-dir> <data-dir> <decode-dir>"
     echo "... where <decode-dir> is assumed to be a sub-directory of the directory"
     echo " where the model is."
     echo "e.g.: steps/decode_fmmi.sh exp/mono/graph_tgpr data/test_dev93 exp/mono/decode_dev93_tgpr"
     echo ""
     echo "This script works on CMN + (delta+delta-delta | LDA+MLLT) features; it works out"
     echo "what type of features you used (assuming it's one of these two)"
     echo "You can also use fMLLR features-- you have to supply --transform-dir option."
     echo ""
     echo "main options (for others, see top of script file)"
     echo "  --config <config-file>                           # config containing options"
     echo "  --nj <nj>                                        # number of parallel jobs"
     echo "  --iter <iter>                                    # Iteration of model to test."
     echo "  --cmd (utils/run.pl|utils/queue.pl <queue opts>) # how to run jobs."
     echo "  --acwt <float>                                   # acoustic scale used for lattice generation "
     echo "  --transform-dir <transform-dir>                  # where to find fMLLR transforms."
     echo "  --scoring-opts <string>                          # options to local/score.sh"
     echo "                                                   # speaker-adapted decoding"
     echo "  --num-threads <n>                                # number of threads to use, default 1."
     echo "  --parallel-opts <opts>                           # e.g. '-pe smp 4' if you supply --num-threads 4"
     exit 1;
  fi
  
  
  graphdir=$1
  data=$2
  dir=$3
  srcdir=`dirname $dir`; # The model directory is one level up from decoding directory.
  sdata=$data/split$nj;
  splice_opts=`cat $srcdir/splice_opts 2>/dev/null`
  thread_string=
  [ $num_threads -gt 1 ] && thread_string="-parallel --num-threads=$num_threads" 
  
  mkdir -p $dir/log
  [[ -d $sdata && $data/feats.scp -ot $sdata ]] || split_data.sh $data $nj || exit 1;
  echo $nj > $dir/num_jobs
  
  model=$srcdir/$iter.mdl
  
  for f in $sdata/1/feats.scp $sdata/1/cmvn.scp $model $graphdir/HCLG.fst; do
    [ ! -f $f ] && echo "decode_fmmi.sh: no such file $f" && exit 1;
  done
  
  if [ -f $srcdir/final.mat ]; then feat_type=lda; else feat_type=delta; fi
  echo "decode_fmmi.sh: feature type is $feat_type";
  
  case $feat_type in
    delta) feats="ark,s,cs:apply-cmvn --norm-vars=false --utt2spk=ark:$sdata/JOB/utt2spk scp:$sdata/JOB/cmvn.scp scp:$sdata/JOB/feats.scp ark:- | add-deltas ark:- ark:- |";;
    lda) feats="ark,s,cs:apply-cmvn --norm-vars=false --utt2spk=ark:$sdata/JOB/utt2spk scp:$sdata/JOB/cmvn.scp scp:$sdata/JOB/feats.scp ark:- | splice-feats $splice_opts ark:- ark:- | transform-feats $srcdir/final.mat ark:- ark:- |";;
    *) echo "Invalid feature type $feat_type" && exit 1;
  esac
  
  if [ ! -z "$transform_dir" ]; then # add transforms to features...
    echo "Using fMLLR transforms from $transform_dir"
    [ ! -f $transform_dir/trans.1 ] && echo "Expected $transform_dir/trans.1 to exist."
    [ "`cat $transform_dir/num_jobs`" -ne $nj ] && \
       echo "Mismatch in number of jobs with $transform_dir";
    feats="$feats transform-feats --utt2spk=ark:$sdata/JOB/utt2spk ark:$transform_dir/trans.JOB ark:- ark:- |"
  fi
  
  fmpefeats="$feats fmpe-apply-transform $srcdir/$iter.fmpe ark:- 'ark,s,cs:gunzip -c $dir/gselect.JOB.gz|' ark:- |" 
  
  if [ $stage -le 1 ]; then
    # Get Gaussian selection info.
    $cmd JOB=1:$nj $dir/log/gselect.JOB.log \
      gmm-gselect --n=$ngselect $srcdir/$iter.fmpe "$feats" \
      "ark:|gzip -c >$dir/gselect.JOB.gz" || exit 1;
  fi
    
  if [ $stage -le 2 ]; then
    $cmd $parallel_opts JOB=1:$nj $dir/log/decode.JOB.log \
      gmm-latgen-faster$thread_string --max-active=$maxactive --beam=$beam --lattice-beam=$latbeam \
      --acoustic-scale=$acwt --allow-partial=true --word-symbol-table=$graphdir/words.txt \
      $model $graphdir/HCLG.fst "$fmpefeats" "ark:|gzip -c > $dir/lat.JOB.gz" || exit 1;
  fi
  
  if [ $stage -le 3 ]; then
    [ ! -x local/score.sh ] && \
      echo "Not scoring because local/score.sh does not exist or not executable." && exit 1;
    local/score.sh $scoring_opts --cmd "$cmd" $data $graphdir $dir
  fi
  exit 0;