30     using namespace kaldi;
    32     typedef kaldi::int64 int64;
    33     using fst::SymbolTable;
    38         "Apply beam pruning to lattices\n"    39         "Usage: lattice-prune [options] lattice-rspecifier lattice-wspecifier\n"    40         " e.g.: lattice-prune --acoustic-scale=0.1 --beam=4.0 ark:1.lats ark:pruned.lats\n";
    47     po.Register(
"acoustic-scale", &acoustic_scale, 
"Scaling factor for acoustic likelihoods");
    48     po.Register(
"inv-acoustic-scale", &inv_acoustic_scale, 
"An alternative way of setting the "    49                 "acoustic scale: you can set its inverse.");
    50     po.Register(
"beam", &beam, 
"Pruning beam [applied after acoustic scaling]");
    54     if (po.NumArgs() != 2) {
    59     KALDI_ASSERT(acoustic_scale == 1.0 || inv_acoustic_scale == 1.0);
    60     if (inv_acoustic_scale != 1.0)
    61       acoustic_scale = 1.0 / inv_acoustic_scale;
    63     std::string lats_rspecifier = po.GetArg(1),
    64         lats_wspecifier = po.GetArg(2);
    71     int32 n_done = 0, n_err = 0;
    72     int64 n_arcs_in = 0, n_arcs_out = 0,
    73         n_states_in = 0, n_states_out = 0;
    75     if (acoustic_scale == 0.0)
    76       KALDI_ERR << 
"Do not use a zero acoustic scale (cannot be inverted)";
    78     for (; !compact_lattice_reader.Done(); compact_lattice_reader.Next()) {
    79       std::string key = compact_lattice_reader.Key();
    81       compact_lattice_reader.FreeCurrent();
    83       int64 narcs = 
NumArcs(clat), nstates = clat.NumStates();
    85       n_states_in += nstates;
    88         KALDI_WARN << 
"Error pruning lattice for utterance " << key;
    91       int64 pruned_narcs = 
NumArcs(pruned_clat),          
    92           pruned_nstates = pruned_clat.NumStates();
    93       n_arcs_out += pruned_narcs;
    94       n_states_out += pruned_nstates;
    95       KALDI_LOG << 
"For utterance " << key << 
", pruned #states from "    96                 << nstates << 
" to " << pruned_nstates << 
" and #arcs from "    97                 << narcs << 
" to " << pruned_narcs;
    99       compact_lattice_writer.Write(key, pruned_clat);
   104     KALDI_LOG << 
"Overall, pruned from on average " << (n_states_in/den) << 
" to "   105               << (n_states_out/den) << 
" states, and from " << (n_arcs_in/den)
   106               << 
" to " << (n_arcs_out/den) << 
" arcs, over " << n_done
   108     KALDI_LOG << 
"Done " << n_done << 
" lattices.";
   109     return (n_done != 0 ? 0 : 1);
   110   } 
catch(
const std::exception &e) {
   111     std::cerr << e.what();
 This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
 
A templated class for writing objects to an archive or script file; see The Table concept...
 
std::vector< std::vector< double > > AcousticLatticeScale(double acwt)
 
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
 
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...
 
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
 
fst::VectorFst< CompactLatticeArc > CompactLattice
 
bool PruneLattice(BaseFloat beam, LatType *lat)
 
#define KALDI_ASSERT(cond)
 
Arc::StateId NumArcs(const ExpandedFst< Arc > &fst)
Returns the total number of arcs in an FST.