34 using namespace kaldi;
36 using fst::SymbolTable;
41 "Decode, reading log-likelihoods (of transition-ids or whatever symbol is on the graph)\n" 42 "as matrices. Note: you'll usually want decode-faster-mapped rather than this program.\n" 44 "Usage: decode-faster [options] <fst-in> <loglikes-rspecifier> <words-wspecifier> [<alignments-wspecifier>]\n";
48 bool allow_partial =
true;
49 std::string word_syms_filename;
52 po.Register(
"binary", &binary,
"Write output in binary mode");
53 po.Register(
"allow-partial", &allow_partial,
"Produce output even when final state was not reached");
54 po.Register(
"acoustic-scale", &acoustic_scale,
"Scaling factor for acoustic likelihoods");
55 po.Register(
"word-symbol-table", &word_syms_filename,
"Symbol table for words [for debug output]");
59 if (po.NumArgs() < 3 || po.NumArgs() > 4) {
64 std::string fst_in_filename = po.GetArg(1),
65 loglikes_rspecifier = po.GetArg(2),
66 words_wspecifier = po.GetArg(3),
67 alignment_wspecifier = po.GetOptArg(4);
73 fst::SymbolTable *word_syms = NULL;
74 if (word_syms_filename !=
"") {
75 word_syms = fst::SymbolTable::ReadText(word_syms_filename);
77 KALDI_ERR <<
"Could not read symbol table from file "<<word_syms_filename;
90 kaldi::int64 frame_count = 0;
91 int num_success = 0, num_fail = 0;
96 for (; !loglikes_reader.Done(); loglikes_reader.Next()) {
97 std::string key = loglikes_reader.Key();
100 if (loglikes.NumRows() == 0) {
101 KALDI_WARN <<
"Zero-length utterance: " << key;
107 decoder.Decode(&decodable);
109 VectorFst<LatticeArc> decoded;
111 if ( (allow_partial || decoder.ReachedFinal())
112 && decoder.GetBestPath(&decoded) ) {
114 if (!decoder.ReachedFinal())
115 KALDI_WARN <<
"Decoder did not reach end-state, outputting partial traceback.";
117 std::vector<int32> alignment;
118 std::vector<int32>
words;
120 frame_count += loglikes.NumRows();
124 words_writer.Write(key, words);
125 if (alignment_writer.IsOpen())
126 alignment_writer.Write(key, alignment);
127 if (word_syms != NULL) {
128 std::cerr << key <<
' ';
129 for (
size_t i = 0;
i < words.size();
i++) {
130 std::string s = word_syms->Find(words[
i]);
132 KALDI_ERR <<
"Word-id " << words[
i] <<
" not in symbol table.";
133 std::cerr << s <<
' ';
139 KALDI_LOG <<
"Log-like per frame for utterance " << key <<
" is " 140 << (like / loglikes.NumRows()) <<
" over " 141 << loglikes.NumRows() <<
" frames.";
145 KALDI_WARN <<
"Did not successfully decode utterance " << key
146 <<
", len = " << loglikes.NumRows();
150 double elapsed = timer.
Elapsed();
151 KALDI_LOG <<
"Time taken [excluding initialization] "<< elapsed
152 <<
"s: real-time factor assuming 100 frames/sec is " 153 << (elapsed*100.0/frame_count);
154 KALDI_LOG <<
"Done " << num_success <<
" utterances, failed for " 156 KALDI_LOG <<
"Overall log-likelihood per frame is " << (tot_like/frame_count)
157 <<
" over " << frame_count <<
" frames.";
161 if (num_success != 0)
return 0;
163 }
catch(
const std::exception &e) {
164 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...
bool GetLinearSymbolSequence(const Fst< Arc > &fst, std::vector< I > *isymbols_out, std::vector< I > *osymbols_out, typename Arc::Weight *tot_weight_out)
GetLinearSymbolSequence gets the symbol sequence from a linear FST.
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
void Register(OptionsItf *opts, bool full)
void ReadFstKaldi(std::istream &is, bool binary, VectorFst< Arc > *fst)
double Elapsed() const
Returns time in seconds.