24 int main(
int argc,
char *argv[]) {
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.");
71 std::string lats_rspecifier = po.
GetArg(1),
72 trans_wspecifier = po.
GetArg(2),
74 sausage_stats_wspecifier = po.
GetOptArg(4),
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();
105 if (trans_wspecifier !=
"")
107 if (bayes_risk_wspecifier !=
"")
109 if (sausage_stats_wspecifier !=
"")
111 if (times_wspecifier !=
"")
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...
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
A templated class for writing objects to an archive or script file; see The Table concept...
void Write(const std::string &key, const T &value) const
void Register(const std::string &name, bool *ptr, const std::string &doc)
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...
const std::vector< std::pair< BaseFloat, BaseFloat > > GetSausageTimes() const
const std::vector< std::pair< BaseFloat, BaseFloat > > & GetOneBestTimes() const
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
const std::vector< int32 > & GetOneBest() const
std::vector< std::vector< double > > LatticeScale(double lmwt, double acwt)
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
This class does the word-level Minimum Bayes Risk computation, and gives you either the 1-best MBR ou...
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
const std::vector< std::vector< std::pair< int32, BaseFloat > > > & GetSausageStats() const
int main(int argc, char *argv[])
fst::VectorFst< CompactLatticeArc > CompactLattice
int NumArgs() const
Number of positional parameters (c.f. argc-1).
BaseFloat GetBayesRisk() const
Returns the expected WER over this sentence (assuming model correctness).
std::string GetOptArg(int param) const