71 using namespace kaldi;
73 using fst::SymbolTable;
80 "Decode features using GMM-based model.\n" 81 "User supplies LM used to generate decoding graph, and desired LM;\n" 82 "this decoder applies the difference during decoding\n" 83 "Usage: gmm-decode-biglm-faster [options] model-in fst-in oldlm-fst-in newlm-fst-in features-rspecifier words-wspecifier [alignments-wspecifier [lattice-wspecifier]]\n";
85 bool allow_partial =
true;
88 std::string word_syms_filename;
91 po.Register(
"acoustic-scale", &acoustic_scale,
92 "Scaling factor for acoustic likelihoods");
93 po.Register(
"word-symbol-table", &word_syms_filename,
94 "Symbol table for words [for debug output]");
95 po.Register(
"allow-partial", &allow_partial,
96 "Produce output even when final state was not reached");
100 if (po.NumArgs() < 6 || po.NumArgs() > 8) {
105 std::string model_rxfilename = po.GetArg(1),
106 fst_rxfilename = po.GetArg(2),
107 old_lm_fst_rxfilename = po.GetArg(3),
108 new_lm_fst_rxfilename = po.GetArg(4),
109 feature_rspecifier = po.GetArg(5),
110 words_wspecifier = po.GetArg(6),
111 alignment_wspecifier = po.GetOptArg(7),
112 lattice_wspecifier = po.GetOptArg(8);
118 Input ki(model_rxfilename, &binary);
119 trans_model.
Read(ki.Stream(), binary);
120 am_gmm.
Read(ki.Stream(), binary);
129 fst::SymbolTable *word_syms = NULL;
130 if (word_syms_filename !=
"") {
131 word_syms = fst::SymbolTable::ReadText(word_syms_filename);
133 KALDI_ERR <<
"Could not read symbol table from file "<<word_syms_filename;
144 Fst<StdArc> *decode_fst =
ReadNetwork(fst_rxfilename);
146 VectorFst<StdArc> *old_lm_fst =
ReadFstKaldi(old_lm_fst_rxfilename);
149 VectorFst<StdArc> *new_lm_fst =
ReadFstKaldi(new_lm_fst_rxfilename);
153 kaldi::int64 frame_count = 0;
154 int num_success = 0, num_fail = 0;
158 for (; !feature_reader.Done(); feature_reader.Next()) {
159 std::string key = feature_reader.Key();
161 feature_reader.FreeCurrent();
162 if (features.NumRows() == 0) {
163 KALDI_WARN <<
"Zero-length utterance: " << key;
177 decoder.Decode(&gmm_decodable);
179 std::cerr <<
"Length of file is "<<features.NumRows()<<
'\n';
181 fst::VectorFst<LatticeArc> decoded;
183 if ( (allow_partial || decoder.ReachedFinal())
184 && decoder.GetBestPath(&decoded) ) {
185 if (!decoder.ReachedFinal())
186 KALDI_WARN <<
"Decoder did not reach end-state, " 187 <<
"outputting partial traceback since --allow-partial=true";
189 if (!decoder.ReachedFinal())
190 KALDI_WARN <<
"Decoder did not reach end-state, outputting partial traceback.";
191 std::vector<int32> alignment;
192 std::vector<int32>
words;
194 frame_count += features.NumRows();
198 words_writer.Write(key, words);
199 if (alignment_writer.IsOpen())
200 alignment_writer.Write(key, alignment);
202 if (lattice_wspecifier !=
"") {
203 if (acoustic_scale != 0.0)
205 fst::VectorFst<CompactLatticeArc> clat;
207 clat_writer.Write(key, clat);
210 if (word_syms != NULL) {
211 std::cerr << key <<
' ';
212 for (
size_t i = 0;
i < words.size();
i++) {
213 std::string s = word_syms->Find(words[
i]);
215 KALDI_ERR <<
"Word-id " << words[
i] <<
" not in symbol table.";
216 std::cerr << s <<
' ';
222 KALDI_LOG <<
"Log-like per frame for utterance " << key <<
" is " 223 << (like / features.NumRows()) <<
" over " 224 << features.NumRows() <<
" frames.";
225 KALDI_VLOG(2) <<
"Cost for utterance " << key <<
" is " 229 KALDI_WARN <<
"Did not successfully decode utterance " << key
230 <<
", len = " << features.NumRows();
234 double elapsed = timer.
Elapsed();
235 KALDI_LOG <<
"Time taken [excluding initialization] "<< elapsed
236 <<
"s: real-time factor assuming 100 frames/sec is " 237 << (elapsed*100.0/frame_count);
238 KALDI_LOG <<
"Done " << num_success <<
" utterances, failed for " 240 KALDI_LOG <<
"Overall log-likelihood per frame is " << (tot_like/frame_count) <<
" over " 241 << frame_count<<
" frames.";
247 return (num_success != 0 ? 0 : 1);
248 }
catch(
const std::exception &e) {
249 std::cerr << e.what();
This class wraps an Fst, representing a language model, using the interface for "BackoffDeterministic...
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
fst::Fst< fst::StdArc > * ReadNetwork(std::string filename)
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.
std::vector< std::vector< double > > AcousticLatticeScale(double acwt)
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
This is as FasterDecoder, but does online composition between HCLG and the "difference language model...
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...
void Read(std::istream &is, bool binary)
void ConvertLattice(const ExpandedFst< ArcTpl< Weight > > &ifst, MutableFst< ArcTpl< CompactLatticeWeightTpl< Weight, Int > > > *ofst, bool invert)
Convert lattice from a normal FST to a CompactLattice FST.
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
void Register(OptionsItf *opts, bool full)
void ApplyProbabilityScale(float scale, MutableFst< Arc > *fst)
ApplyProbabilityScale is applicable to FSTs in the log or tropical semiring.
void ReadFstKaldi(std::istream &is, bool binary, VectorFst< Arc > *fst)
double Elapsed() const
Returns time in seconds.
void Read(std::istream &in_stream, bool binary)