33 int main(
int argc,
char *argv[]) {
35 using namespace kaldi;
38 using fst::SymbolTable;
43 "Generate lattices using neural net model.\n" 44 "Usage: nnet-latgen-faster-parallel [options] <nnet-in> <fst-in|fsts-rspecifier> <features-rspecifier>" 45 " <lattice-wspecifier> [ <words-wspecifier> [<alignments-wspecifier>] ]\n";
48 bool allow_partial =
false;
53 std::string word_syms_filename;
56 po.
Register(
"acoustic-scale", &acoustic_scale,
"Scaling factor for acoustic likelihoods");
57 po.
Register(
"word-symbol-table", &word_syms_filename,
"Symbol table for words [for debug output]");
58 po.
Register(
"allow-partial", &allow_partial,
"If true, produce output even if end state was not reached.");
67 std::string model_in_filename = po.
GetArg(1),
69 feature_rspecifier = po.
GetArg(3),
70 lattice_wspecifier = po.
GetArg(4),
78 Input ki(model_in_filename, &binary);
86 if (! (determinize ? compact_lattice_writer.
Open(lattice_wspecifier)
87 : lattice_writer.
Open(lattice_wspecifier)))
88 KALDI_ERR <<
"Could not open table for writing lattices: " 89 << lattice_wspecifier;
97 fst::SymbolTable *word_syms = NULL;
98 if (word_syms_filename !=
"")
99 if (!(word_syms = fst::SymbolTable::ReadText(word_syms_filename)))
100 KALDI_ERR <<
"Could not read symbol table from file " 101 << word_syms_filename;
106 double tot_like = 0.0;
107 kaldi::int64 frame_count = 0;
108 int num_done = 0, num_err = 0;
109 Fst<StdArc> *decode_fst = NULL;
118 for (; !feature_reader.
Done(); feature_reader.
Next()) {
119 std::string utt = feature_reader.
Key();
121 if (features.NumRows() == 0) {
122 KALDI_WARN <<
"Zero-length utterance: " << utt;
126 bool pad_input =
true;
128 trans_model, am_nnet,
130 pad_input, acoustic_scale);
137 decoder, nnet_decodable,
138 trans_model, word_syms, utt, acoustic_scale, determinize,
139 allow_partial, &alignment_writer, &words_writer,
140 &compact_lattice_writer, &lattice_writer,
141 &tot_like, &frame_count, &num_done, &num_err, NULL);
150 for (; !fst_reader.
Done(); fst_reader.
Next()) {
151 std::string utt = fst_reader.
Key();
152 if (!feature_reader.
HasKey(utt)) {
153 KALDI_WARN <<
"Not decoding utterance " << utt
154 <<
" because no features available.";
160 KALDI_WARN <<
"Zero-length utterance: " << utt;
169 bool pad_input =
true;
171 trans_model, am_nnet,
173 pad_input, acoustic_scale);
177 decoder, nnet_decodable,
178 trans_model, word_syms, utt, acoustic_scale, determinize,
179 allow_partial, &alignment_writer, &words_writer,
180 &compact_lattice_writer, &lattice_writer,
181 &tot_like, &frame_count, &num_done, &num_err, NULL);
190 double elapsed = timer.
Elapsed();
192 <<
"s: real-time factor per thread assuming 100 frames/sec is " 193 << (sequencer_config.
num_threads * elapsed * 100.0 / frame_count);
194 KALDI_LOG <<
"Done " << num_done <<
" utterances, failed for " 196 KALDI_LOG <<
"Overall log-likelihood per frame is " 197 << (tot_like / frame_count) <<
" over " << frame_count
201 if (num_done != 0)
return 0;
203 }
catch(
const std::exception &e) {
204 std::cerr << e.what();
This version of DecodableAmNnet is intended for a version of the decoder that processes different utt...
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
bool Open(const std::string &wspecifier)
Fst< StdArc > * ReadFstKaldiGeneric(std::string rxfilename, bool throw_on_err)
void Run(C *c)
This function takes ownership of the pointer "c", and will delete it in the same sequence as Run was ...
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
void Read(std::istream &is, bool binary)
A templated class for writing objects to an archive or script file; see The Table concept...
This class represents a matrix that's stored on the GPU if we have one, and in memory if not...
void Register(const std::string &name, bool *ptr, const std::string &doc)
RspecifierType ClassifyRspecifier(const std::string &rspecifier, std::string *rxfilename, RspecifierOptions *opts)
Allows random access to a collection of objects in an archive or script file; see The Table concept...
This class basically does the same job as the function DecodeUtteranceLatticeFaster, but in a way that allows us to build a multi-threaded command line program more easily.
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
int main(int argc, char *argv[])
const T & Value(const std::string &key)
void Read(std::istream &is, bool binary)
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.
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
bool HasKey(const std::string &key)
This is the "normal" lattice-generating decoder.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
LatticeFasterDecoderTpl< fst::StdFst, decoder::StdToken > LatticeFasterDecoder
void Register(OptionsItf *opts)
double Elapsed() const
Returns time in seconds.
std::string GetOptArg(int param) const
void Register(OptionsItf *opts)