26 using namespace kaldi;
30 "Do Minimum Bayes Risk decoding (decoding that aims to minimize the \n" 31 "expected word error rate). Possible outputs include the 1-best path\n" 32 "(i.e. the word-sequence, as a sequence of ints per utterance), the\n" 33 "computed Bayes Risk for each utterance, and the sausage stats as\n" 34 "(for each utterance) std::vector<std::vector<std::pair<int32, float> > >\n" 35 "for which we use the same I/O routines as for posteriors (type Posterior).\n" 36 "times-wspecifier writes pairs of (start-time, end-time) in frames, for\n" 37 "each sausage position, or for each one-best entry if --one-best-times=true.\n" 38 "Note: use ark:/dev/null or the empty string for unwanted outputs.\n" 39 "Note: times will only be very meaningful if you first use lattice-word-align.\n" 40 "If you need ctm-format output, don't use this program but use lattice-to-ctm-conf\n" 41 "with --decode-mbr=true.\n" 43 "Usage: lattice-mbr-decode [options] lattice-rspecifier " 44 "transcriptions-wspecifier [ bayes-risk-wspecifier " 45 "[ sausage-stats-wspecifier [ times-wspecifier] ] ] \n" 46 " e.g.: lattice-mbr-decode --acoustic-scale=0.1 ark:1.lats " 47 "'ark,t:|int2sym.pl -f 2- words.txt > text' ark:/dev/null ark:1.sau\n";
52 bool one_best_times =
false;
54 std::string word_syms_filename;
55 po.Register(
"acoustic-scale", &acoustic_scale,
"Scaling factor for " 56 "acoustic likelihoods");
57 po.Register(
"lm-scale", &lm_scale,
"Scaling factor for language model " 59 po.Register(
"word-symbol-table", &word_syms_filename,
"Symbol table for " 60 "words [for debug output]");
61 po.Register(
"one-best-times", &one_best_times,
"If true, output times " 62 "corresponding to one-best, not whole sausage.");
66 if (po.NumArgs() < 2 || po.NumArgs() > 5) {
71 std::string lats_rspecifier = po.GetArg(1),
72 trans_wspecifier = po.GetArg(2),
73 bayes_risk_wspecifier = po.GetOptArg(3),
74 sausage_stats_wspecifier = po.GetOptArg(4),
75 times_wspecifier = po.GetOptArg(5);
88 fst::SymbolTable *word_syms = NULL;
89 if (word_syms_filename !=
"")
90 if (!(word_syms = fst::SymbolTable::ReadText(word_syms_filename)))
91 KALDI_ERR <<
"Could not read symbol table from file " 92 << word_syms_filename;
94 int32 n_done = 0, n_words = 0;
97 for (; !clat_reader.Done(); clat_reader.Next()) {
98 std::string key = clat_reader.Key();
100 clat_reader.FreeCurrent();
105 if (trans_wspecifier !=
"")
106 trans_writer.Write(key, mbr.GetOneBest());
107 if (bayes_risk_wspecifier !=
"")
108 bayes_risk_writer.Write(key, mbr.GetBayesRisk());
109 if (sausage_stats_wspecifier !=
"")
110 sausage_stats_writer.Write(key, mbr.GetSausageStats());
111 if (times_wspecifier !=
"")
112 times_writer.Write(key, one_best_times ? mbr.GetOneBestTimes() :
113 mbr.GetSausageTimes());
116 n_words += mbr.GetOneBest().size();
117 tot_bayes_risk += mbr.GetBayesRisk();
120 KALDI_LOG <<
"Done " << n_done <<
" lattices.";
121 KALDI_LOG <<
"Average Bayes Risk per sentence is " 122 << (tot_bayes_risk / n_done) <<
" and per word, " 123 << (tot_bayes_risk / n_words);
126 return (n_done != 0 ? 0 : 1);
127 }
catch(
const std::exception &e) {
128 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
A templated class for writing objects to an archive or script file; see The Table concept...
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
void ScaleLattice(const std::vector< std::vector< ScaleFloat > > &scale, MutableFst< ArcTpl< Weight > > *fst)
Scales the pairs of weights in LatticeWeight or CompactLatticeWeight by viewing the pair (a...
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
std::vector< std::vector< double > > LatticeScale(double lmwt, double acwt)
This class does the word-level Minimum Bayes Risk computation, and gives you either the 1-best MBR ou...
fst::VectorFst< CompactLatticeArc > CompactLattice