30     using namespace kaldi;
    34         "Determinize lattices, keeping only the best path (sequence of\n"    35         "acoustic states) for each input-symbol sequence. This version does\n"    36         "phone inertion when doing a first pass determinization, it then\n"    37         "removes the inserted symbols and does a second pass determinization.\n"    38         "It also does pruning as part of the determinization algorithm, which\n"    39         "is more efficient and prevents blowup.\n"    41         "Usage: lattice-determinize-phone-pruned [options] <model> \\\n"    42         "                  <lattice-rspecifier> <lattice-wspecifier>\n"    43         " e.g.: lattice-determinize-phone-pruned --acoustic-scale=0.1 \\\n"    44         "                            final.mdl ark:in.lats ark:det.lats\n";
    47     bool write_compact = 
true;
    53     po.Register(
"write-compact", &write_compact, 
    54                 "If true, write in normal (compact) form. "    55                 "--write-compact=false allows you to retain frame-level "    56                 "acoustic score information, but this requires the input "    57                 "to be in non-compact form e.g. undeterminized lattice "    58                 "straight from decoding.");
    59     po.Register(
"acoustic-scale", &acoustic_scale, 
"Scaling factor for acoustic"    61     po.Register(
"beam", &beam, 
"Pruning beam [applied after acoustic scaling].");
    65     if (po.NumArgs() != 3) {
    70     std::string model_rxfilename = po.GetArg(1),
    71         lats_rspecifier = po.GetArg(2),
    72         lats_wspecifier = po.GetArg(3);
    85       compact_lat_writer.
Open(lats_wspecifier);
    87       lat_writer.
Open(lats_wspecifier);
    89     int32 n_done = 0, n_warn = 0;
    92     double sum_depth_in = 0.0,
    93           sum_depth_out = 0.0, sum_t = 0.0;
    95     if (acoustic_scale == 0.0)
    96       KALDI_ERR << 
"Do not use a zero acoustic scale (cannot be inverted)";
    98     for (; !lat_reader.Done(); lat_reader.Next()) {
    99       std::string key = lat_reader.Key();
   100       Lattice lat = lat_reader.Value();
   101       lat_reader.FreeCurrent();
   103       KALDI_VLOG(2) << 
"Processing lattice " << key;
   106       unordered_map<std::pair<int32,int32>, std::pair<BaseFloat, int32>,
   115               trans_model, &lat, beam, &det_clat, opts)) {
   116         KALDI_WARN << 
"For key " << key << 
", determinization did not succeed"   117             "(partial output will be pruned tighter than the specified beam.)";
   124       sum_depth_in += lat.NumStates();
   125       sum_depth_out += depth * t;
   130         compact_lat_writer.
Write(key, det_clat);
   138         lat_writer.
Write(key, out_lat);
   145       KALDI_LOG << 
"Average input-lattice depth (measured at at state level) is "   146                 << (sum_depth_in / sum_t) << 
", output depth is "   147                 << (sum_depth_out / sum_t) << 
", over " << sum_t << 
" frames "   148                 << 
" (average num-frames = " << (sum_t / n_done) << 
").";
   150     KALDI_LOG << 
"Done " << n_done << 
" lattices, determinization finished "   151               << 
"earlier than specified by the beam on " << n_warn << 
" of "   153     return (n_done != 0 ? 0 : 1);
   154   } 
catch(
const std::exception &e) {
   155     std::cerr << e.what();
 This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
 
void Register(kaldi::OptionsItf *opts)
 
bool Open(const std::string &wspecifier)
 
void ReplaceAcousticScoresFromMap(const unordered_map< std::pair< int32, int32 >, std::pair< BaseFloat, int32 >, PairHasher< int32 > > &acoustic_scores, Lattice *lat)
This function restores acoustic scores computed using the function ComputeAcousticScoresMap into the ...
 
A templated class for writing objects to an archive or script file; see The Table concept...
 
void Write(const std::string &key, const T &value) const
 
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
 
std::vector< std::vector< double > > AcousticLatticeScale(double acwt)
 
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
 
BaseFloat CompactLatticeDepth(const CompactLattice &clat, int32 *num_frames)
Returns the depth of the lattice, defined as the average number of arcs crossing any given frame...
 
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 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...
 
fst::VectorFst< LatticeArc > Lattice
 
fst::VectorFst< CompactLatticeArc > CompactLattice
 
void ComputeAcousticScoresMap(const Lattice &lat, unordered_map< std::pair< int32, int32 >, std::pair< BaseFloat, int32 >, PairHasher< int32 > > *acoustic_scores)
This function computes the mapping from the pair (frame-index, transition-id) to the pair (sum-of-aco...
 
void TopSortCompactLatticeIfNeeded(CompactLattice *clat)
Topologically sort the compact lattice if not already topologically sorted. 
 
bool DeterminizeLatticePhonePrunedWrapper(const kaldi::TransitionModel &trans_model, MutableFst< kaldi::LatticeArc > *ifst, double beam, MutableFst< kaldi::CompactLatticeArc > *ofst, DeterminizeLatticePhonePrunedOptions opts)
This function is a wrapper of DeterminizeLatticePhonePruned() that works for Lattice type FSTs...
 
A hashing function-object for pairs of ints.