35 if (!ki.
Stream().good())
KALDI_ERR <<
"Could not open decoding-graph FST " 39 if (!hdr.Read(ki.
Stream(),
"<unknown>")) {
40 KALDI_ERR <<
"Reading FST: error reading FST header.";
42 if (hdr.ArcType() != fst::StdArc::Type()) {
43 KALDI_ERR <<
"FST with arc type " << hdr.ArcType() <<
" not supported.";
45 fst::FstReadOptions ropts(
"<unspecified>", &hdr);
47 fst::Fst<fst::StdArc> *decode_fst = NULL;
49 if (hdr.FstType() ==
"vector") {
50 decode_fst = fst::VectorFst<fst::StdArc>::Read(ki.
Stream(), ropts);
51 }
else if (hdr.FstType() ==
"const") {
52 decode_fst = fst::ConstFst<fst::StdArc>::Read(ki.
Stream(), ropts);
54 KALDI_ERR <<
"Reading FST: unsupported FST type: " << hdr.FstType();
56 if (decode_fst == NULL) {
57 KALDI_ERR <<
"Error reading FST (after reading header).";
68 int main(
int argc,
char *argv[])
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");
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),
118 Input ki(model_rxfilename, &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();
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;
186 KALDI_WARN <<
"Decoder did not reach end-state, " 187 <<
"outputting partial traceback since --allow-partial=true";
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)
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...
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.
void Write(const std::string &key, const T &value) const
void Register(const std::string &name, bool *ptr, const std::string &doc)
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)
int main(int argc, char *argv[])
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...
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
bool GetBestPath(fst::MutableFst< LatticeArc > *fst_out, bool use_final_probs=true)
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
void Register(OptionsItf *opts, bool full)
void ApplyProbabilityScale(float scale, MutableFst< Arc > *fst)
ApplyProbabilityScale is applicable to FSTs in the log or tropical semiring.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
void ReadFstKaldi(std::istream &is, bool binary, VectorFst< Arc > *fst)
void Decode(DecodableInterface *decodable)
double Elapsed() const
Returns time in seconds.
void Read(std::istream &in_stream, bool binary)
std::string GetOptArg(int param) const