38     using namespace kaldi;
    41     using fst::SymbolTable;
    46         "Generate lattices using nnet3 neural net model.\n"    47         "[this version uses the 'looped' computation, which may be slightly faster for\n"    48         "many architectures, but should not be used for backwards-recurrent architectures\n"    50         "Usage: nnet3-latgen-faster-looped [options] <nnet-in> <fst-in|fsts-rspecifier> <features-rspecifier>"    51         " <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(
"online-ivectors", &online_ivector_rspecifier, 
"Rspecifier for "    73                 "iVectors estimated online, as matrices.  If you supply this,"    74                 " you must set the --online-ivector-period option.");
    75     po.Register(
"online-ivector-period", &online_ivector_period, 
"Number of frames "    76                 "between iVectors in matrices supplied to the --online-ivectors "    81     if (po.NumArgs() < 4 || po.NumArgs() > 6) {
    86     std::string model_in_filename = po.GetArg(1),
    87         fst_in_str = po.GetArg(2),
    88         feature_rspecifier = po.GetArg(3),
    89         lattice_wspecifier = po.GetArg(4),
    90         words_wspecifier = po.GetOptArg(5),
    91         alignment_wspecifier = po.GetOptArg(6);
    97       Input ki(model_in_filename, &binary);
    98       trans_model.
Read(ki.Stream(), binary);
    99       am_nnet.
Read(ki.Stream(), binary);
   108     if (! (determinize ? compact_lattice_writer.
Open(lattice_wspecifier)
   109            : lattice_writer.
Open(lattice_wspecifier)))
   110       KALDI_ERR << 
"Could not open table for writing lattices: "   111                  << lattice_wspecifier;
   114         online_ivector_rspecifier);
   116         ivector_rspecifier, utt2spk_rspecifier);
   121     fst::SymbolTable *word_syms = NULL;
   122     if (word_syms_filename != 
"")
   123       if (!(word_syms = fst::SymbolTable::ReadText(word_syms_filename)))
   124         KALDI_ERR << 
"Could not read symbol table from file "   125                    << word_syms_filename;
   127     double tot_like = 0.0;
   128     kaldi::int64 frame_count = 0;
   129     int num_success = 0, num_fail = 0;
   148         for (; !feature_reader.Done(); feature_reader.Next()) {
   149           std::string utt = feature_reader.Key();
   151           if (features.NumRows() == 0) {
   152             KALDI_WARN << 
"Zero-length utterance: " << utt;
   158           if (!ivector_rspecifier.empty()) {
   159             if (!ivector_reader.HasKey(utt)) {
   160               KALDI_WARN << 
"No iVector available for utterance " << utt;
   164               ivector = &ivector_reader.Value(utt);
   167           if (!online_ivector_rspecifier.empty()) {
   168             if (!online_ivector_reader.HasKey(utt)) {
   169               KALDI_WARN << 
"No online iVector available for utterance " << utt;
   173               online_ivectors = &online_ivector_reader.Value(utt);
   179               decodable_info, trans_model, features, ivector, online_ivectors,
   180               online_ivector_period);
   184                   decoder, nnet_decodable, trans_model, word_syms, utt,
   186                   &alignment_writer, &words_writer, &compact_lattice_writer,
   190             frame_count += nnet_decodable.NumFramesReady();
   199       for (; !fst_reader.Done(); fst_reader.Next()) {
   200         std::string utt = fst_reader.Key();
   201         if (!feature_reader.HasKey(utt)) {
   202           KALDI_WARN << 
"Not decoding utterance " << utt
   203                      << 
" because no features available.";
   209           KALDI_WARN << 
"Zero-length utterance: " << utt;
   218         if (!ivector_rspecifier.empty()) {
   219           if (!ivector_reader.HasKey(utt)) {
   220             KALDI_WARN << 
"No iVector available for utterance " << utt;
   224             ivector = &ivector_reader.Value(utt);
   227         if (!online_ivector_rspecifier.empty()) {
   228           if (!online_ivector_reader.HasKey(utt)) {
   229             KALDI_WARN << 
"No online iVector available for utterance " << utt;
   233             online_ivectors = &online_ivector_reader.Value(utt);
   238             decodable_info, trans_model, features, ivector, online_ivectors,
   239             online_ivector_period);
   243                 decoder, nnet_decodable, trans_model, word_syms, utt,
   245                 &alignment_writer, &words_writer, &compact_lattice_writer,
   246                 &lattice_writer, &like)) {
   248           frame_count += nnet_decodable.NumFramesReady();
   254     kaldi::int64 input_frame_count =
   257     double elapsed = timer.
Elapsed();
   259               << 
"s: real-time factor assuming 100 frames/sec is "   260               << (elapsed * 100.0 / input_frame_count);
   261     KALDI_LOG << 
"Done " << num_success << 
" utterances, failed for "   263     KALDI_LOG << 
"Overall log-likelihood per frame is "   264               << (tot_like / frame_count) << 
" over "   265               << frame_count <<
" frames.";
   268     if (num_success != 0) 
return 0;
   270   } 
catch(
const std::exception &e) {
   271     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)
 
int32 frame_subsampling_factor
 
Fst< StdArc > * ReadFstKaldiGeneric(std::string rxfilename, bool throw_on_err)
 
This class is for when you are reading something in random access, but it may actually be stored per-...
 
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)
 
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...
 
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)
 
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
 
This is the "normal" lattice-generating decoder. 
 
A class representing a vector. 
 
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix). 
 
void Register(OptionsItf *opts)
 
double Elapsed() const
Returns time in seconds. 
 
When you instantiate class DecodableNnetSimpleLooped, you should give it a const reference to this cl...
 
void Register(OptionsItf *opts)
 
Config class for the CollapseModel function.