38     using namespace kaldi;
    41     using fst::SymbolTable;
    46         "Generate lattices using nnet3 neural net model, and GrammarFst-based graph\n"    47         "see kaldi-asr.org/doc/grammar.html for more context.\n"    49         "Usage: nnet3-latgen-grammar [options] <nnet-in> <grammar-fst-in> <features-rspecifier>"    50         " <lattice-wspecifier> [ <words-wspecifier> [<alignments-wspecifier>] ]\n";
    54     bool allow_partial = 
false;
    58     std::string word_syms_filename;
    59     std::string ivector_rspecifier,
    60         online_ivector_rspecifier,
    62     int32 online_ivector_period = 0;
    65     po.Register(
"word-symbol-table", &word_syms_filename,
    66                 "Symbol table for words [for debug output]");
    67     po.Register(
"allow-partial", &allow_partial,
    68                 "If true, produce output even if end state was not reached.");
    69     po.Register(
"ivectors", &ivector_rspecifier, 
"Rspecifier for "    70                 "iVectors as vectors (i.e. not estimated online); per utterance "    71                 "by default, or per speaker if you provide the --utt2spk option.");
    72     po.Register(
"utt2spk", &utt2spk_rspecifier, 
"Rspecifier for "    73                 "utt2spk option used to get ivectors per speaker");
    74     po.Register(
"online-ivectors", &online_ivector_rspecifier, 
"Rspecifier for "    75                 "iVectors estimated online, as matrices.  If you supply this,"    76                 " you must set the --online-ivector-period option.");
    77     po.Register(
"online-ivector-period", &online_ivector_period, 
"Number of frames "    78                 "between iVectors in matrices supplied to the --online-ivectors "    83     if (po.NumArgs() < 4 || po.NumArgs() > 6) {
    88     std::string model_rxfilename = po.GetArg(1),
    89         grammar_fst_rxfilename = po.GetArg(2),
    90         feature_rspecifier = po.GetArg(3),
    91         lattice_wspecifier = po.GetArg(4),
    92         words_wspecifier = po.GetOptArg(5),
    93         alignment_wspecifier = po.GetOptArg(6);
    99       Input ki(model_rxfilename, &binary);
   100       trans_model.
Read(ki.Stream(), binary);
   101       am_nnet.
Read(ki.Stream(), binary);
   110     if (! (determinize ? compact_lattice_writer.
Open(lattice_wspecifier)
   111            : lattice_writer.
Open(lattice_wspecifier)))
   112       KALDI_ERR << 
"Could not open table for writing lattices: "   113                  << lattice_wspecifier;
   116         online_ivector_rspecifier);
   118         ivector_rspecifier, utt2spk_rspecifier);
   123     fst::SymbolTable *word_syms = NULL;
   124     if (word_syms_filename != 
"")
   125       if (!(word_syms = fst::SymbolTable::ReadText(word_syms_filename)))
   126         KALDI_ERR << 
"Could not read symbol table from file "   127                    << word_syms_filename;
   129     double tot_like = 0.0;
   130     kaldi::int64 frame_count = 0;
   131     int num_success = 0, num_fail = 0;
   146       for (; !feature_reader.Done(); feature_reader.Next()) {
   147         std::string utt = feature_reader.Key();
   149         if (features.NumRows() == 0) {
   150           KALDI_WARN << 
"Zero-length utterance: " << utt;
   156         if (!ivector_rspecifier.empty()) {
   157           if (!ivector_reader.HasKey(utt)) {
   158             KALDI_WARN << 
"No iVector available for utterance " << utt;
   162             ivector = &ivector_reader.Value(utt);
   165         if (!online_ivector_rspecifier.empty()) {
   166           if (!online_ivector_reader.HasKey(utt)) {
   167             KALDI_WARN << 
"No online iVector available for utterance " << utt;
   171             online_ivectors = &online_ivector_reader.Value(utt);
   176             decodable_opts, trans_model, am_nnet,
   177             features, ivector, online_ivectors,
   178             online_ivector_period, &compiler);
   182                 decoder, nnet_decodable, trans_model, word_syms, utt,
   184                 &alignment_writer, &words_writer, &compact_lattice_writer,
   188           frame_count += nnet_decodable.NumFramesReady();
   194     kaldi::int64 input_frame_count =
   197     double elapsed = timer.
Elapsed();
   199               << 
"s: real-time factor assuming 100 frames/sec is "   200               << (elapsed * 100.0 / input_frame_count);
   201     KALDI_LOG << 
"Done " << num_success << 
" utterances, failed for "   203     KALDI_LOG << 
"Overall log-likelihood per frame is "   204               << (tot_like / frame_count) << 
" over "   205               << frame_count << 
" frames.";
   208     if (num_success != 0) 
return 0;
   210   } 
catch(
const std::exception &e) {
   211     std::cerr << e.what();
 This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
 
void CollapseModel(const CollapseModelConfig &config, Nnet *nnet)
This function modifies the neural net for efficiency, in a way that suitable to be done in test time...
 
bool Open(const std::string &wspecifier)
 
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
 
This class is for when you are reading something in random access, but it may actually be stored per-...
 
This class enables you to do the compilation and optimization in one call, and also ensures that if t...
 
void SetBatchnormTestMode(bool test_mode, Nnet *nnet)
This function affects only components of type BatchNormComponent. 
 
A templated class for writing objects to an archive or script file; see The Table concept...
 
bool DecodeUtteranceLatticeFaster(LatticeFasterDecoderTpl< FST > &decoder, DecodableInterface &decodable, const TransitionModel &trans_model, const fst::SymbolTable *word_syms, std::string utt, double acoustic_scale, bool determinize, bool allow_partial, Int32VectorWriter *alignment_writer, Int32VectorWriter *words_writer, CompactLatticeWriter *compact_lattice_writer, LatticeWriter *lattice_writer, double *like_ptr)
This function DecodeUtteranceLatticeFaster is used in several decoders, and we have moved it here...
 
const Nnet & GetNnet() const
 
void Read(std::istream &is, bool binary)
 
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
 
Allows random access to a collection of objects in an archive or script file; see The Table concept...
 
void SetDropoutTestMode(bool test_mode, Nnet *nnet)
This function affects components of child-classes of RandomComponent. 
 
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
 
void Read(std::istream &is, bool binary)
 
void Register(OptionsItf *opts)
 
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
 
GrammarFst is an FST that is 'stitched together' from multiple FSTs, that can recursively incorporate...
 
This is the "normal" lattice-generating decoder. 
 
A class representing a vector. 
 
NnetOptimizeOptions optimize_config
 
void Register(OptionsItf *opts)
 
double Elapsed() const
Returns time in seconds. 
 
int32 frame_subsampling_factor
 
Config class for the CollapseModel function.