Blame view

egs/aspire/s5/local/score.sh 2.35 KB
8dcb6dfcb   Yannick Estève   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
  #!/bin/bash
  # Copyright Johns Hopkins University (Author: Daniel Povey) 2012.  Apache 2.0.
  
  # begin configuration section.
  cmd=run.pl
  min_lmwt=5
  max_lmwt=17
  #end configuration section.
  
  [ -f ./path.sh ] && . ./path.sh
  . parse_options.sh || exit 1;
  if [ $# -ne 3 ]; then
    echo "Usage: $0 [--cmd (run.pl|queue.pl...)] <data-dir> <lang-dir|graph-dir> <decode-dir>"
    echo " Options:"
    echo "    --cmd (run.pl|queue.pl...)      # specify how to run the sub-processes."
    echo "    --min_lmwt <int>                # minumum LM-weight for lattice rescoring "
    echo "    --max_lmwt <int>                # maximum LM-weight for lattice rescoring "
    exit 1;
  fi
  
  data=$1
  lang=$2 # Note: may be graph directory not lang directory, but has the necessary stuff copied.
  dir=$3
  
  model=$dir/../final.mdl # assume model one level up from decoding dir.
  
  hubscr=$KALDI_ROOT/tools/sctk/bin/hubscr.pl
  [ ! -f $hubscr ] && echo "Cannot find scoring program at $hubscr" && exit 1;
  hubdir=`dirname $hubscr`
  
  for f in $data/text $lang/words.txt $dir/lat.1.gz; do
    [ ! -f $f ] && echo "$0: expecting file $f to exist" && exit 1;
  done
  
  name=`basename $data`; # e.g. eval2000
  
  mkdir -p $dir/scoring/log
  
  function filter_text {
    perl -e 'foreach $w (@ARGV) { $bad{$w} = 1; }
     while(<STDIN>) { @A  = split(" ", $_); $id = shift @A; print "$id ";
       foreach $a (@A) { if (!defined $bad{$a}) { print "$a "; }} print "
  "; }' \
     '[noise]' '[laughter]' '[vocalized-noise]' '<unk>' '%hesitation'
  }
  
  #function filter_text {
  #  perl -e 'foreach $w (@ARGV) { $bad{$w} = 1; }
  #   while(<STDIN>) { @A  = split(" ", $_); $id = shift @A; print "$id ";
  #     foreach $a (@A) { if (!defined $bad{$a}) { print "$a "; }} print "
  "; }' \
  #   '[NOISE]' '[LAUGHTER]' '[VOCALIZED-NOISE]' '<UNK>' '%HESITATION'
  #}
  
  $cmd LMWT=$min_lmwt:$max_lmwt $dir/scoring/log/best_path.LMWT.log \
    lattice-best-path --lm-scale=LMWT --word-symbol-table=$lang/words.txt \
      "ark:gunzip -c $dir/lat.*.gz|" ark,t:$dir/scoring/LMWT.tra || exit 1;
  
  for lmwt in `seq $min_lmwt $max_lmwt`; do
    utils/int2sym.pl -f 2- $lang/words.txt <$dir/scoring/$lmwt.tra | \
     filter_text > $dir/scoring/$lmwt.txt || exit 1;
  done
  
  filter_text <$data/text >$dir/scoring/text.filt
  
  $cmd LMWT=$min_lmwt:$max_lmwt $dir/scoring/log/score.LMWT.log \
    compute-wer --text --mode=present \
     ark:$dir/scoring/text.filt ark:$dir/scoring/LMWT.txt ">&" $dir/wer_LMWT || exit 1;
  
  exit 0