lattice-minimize.cc File Reference
Include dependency graph for lattice-minimize.cc:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 30 of file lattice-minimize.cc.

References SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), KALDI_LOG, KALDI_VLOG, KALDI_WARN, SequentialTableReader< Holder >::Key(), fst::MinimizeCompactLattice(), SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), ParseOptions::PrintUsage(), fst::PushCompactLatticeStrings(), fst::PushCompactLatticeWeights(), ParseOptions::Read(), ParseOptions::Register(), SequentialTableReader< Holder >::Value(), and TableWriter< Holder >::Write().

30  {
31  try {
32  using namespace kaldi;
33  typedef kaldi::int32 int32;
34  typedef kaldi::int64 int64;
35  using fst::SymbolTable;
36  using fst::VectorFst;
37  using fst::StdArc;
38 
39  const char *usage =
40  "Minimize lattices, in CompactLattice format. Should be applied to\n"
41  "determinized lattices (e.g. produced with --determinize-lattice=true)\n"
42  "Note: by default this program\n"
43  "pushes the strings and weights prior to minimization."
44  "Usage: lattice-minimize [options] lattice-rspecifier lattice-wspecifier\n"
45  " e.g.: lattice-minimize ark:1.lats ark:2.lats\n";
46 
47  ParseOptions po(usage);
48 
49  bool push_strings = true;
50  bool push_weights = true;
51 
52  po.Register("push-strings", &push_strings, "If true, push the strings in the "
53  "lattice to the start.");
54  po.Register("push-weights", &push_weights, "If true, push the weights in the "
55  "lattice to the start.");
56 
57  po.Read(argc, argv);
58 
59  if (po.NumArgs() != 2) {
60  po.PrintUsage();
61  exit(1);
62  }
63 
64  std::string lats_rspecifier = po.GetArg(1),
65  lats_wspecifier = po.GetArg(2);
66 
67 
68  SequentialCompactLatticeReader clat_reader(lats_rspecifier);
69  CompactLatticeWriter clat_writer(lats_wspecifier);
70 
71  int32 n_done = 0, n_err = 0;
72 
73 
74  for (; !clat_reader.Done(); clat_reader.Next()) {
75  std::string key = clat_reader.Key();
76  CompactLattice clat = clat_reader.Value();
77  KALDI_VLOG(1) << "Processing lattice for utterance " << key;
78  if (push_strings && !PushCompactLatticeStrings(&clat)) {
79  KALDI_WARN << "Failure in pushing lattice strings (bad lattice?), "
80  << "for key " << key;
81  n_err++;
82  continue;
83  }
84  if (push_weights && !PushCompactLatticeWeights(&clat)) {
85  KALDI_WARN << "Failure in pushing lattice weights (bad lattice?),"
86  << "for key " << key ;
87  n_err++;
88  continue;
89  }
90  if (!MinimizeCompactLattice(&clat)) {
91  KALDI_WARN << "Failure in minimizing lattice (bad lattice?),"
92  << "for key " << key ;
93  n_err++;
94  continue;
95  }
96  if (clat.NumStates() == 0) {
97  KALDI_WARN << "Empty lattice for key " << key;
98  n_err++;
99  continue;
100  }
101  clat_writer.Write(key, clat);
102  n_done++;
103  }
104  KALDI_LOG << "Minimized " << n_done << " lattices, errors on " << n_err;
105  return (n_done != 0 ? 0 : 1);
106  } catch(const std::exception &e) {
107  std::cerr << e.what();
108  return -1;
109  }
110 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
fst::StdArc StdArc
bool PushCompactLatticeStrings(MutableFst< ArcTpl< CompactLatticeWeightTpl< Weight, IntType > > > *clat)
This function pushes the transition-ids as far towards the start as they will go. ...
A templated class for writing objects to an archive or script file; see The Table concept...
Definition: kaldi-table.h:368
kaldi::int32 int32
bool PushCompactLatticeWeights(MutableFst< ArcTpl< CompactLatticeWeightTpl< Weight, IntType > > > *clat)
This function pushes the weights in the CompactLattice so that all states except possibly the start s...
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
bool MinimizeCompactLattice(MutableFst< ArcTpl< CompactLatticeWeightTpl< Weight, IntType > > > *clat, float delta)
This function minimizes the compact lattice.
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Definition: kaldi-table.h:287
#define KALDI_WARN
Definition: kaldi-error.h:150
fst::VectorFst< CompactLatticeArc > CompactLattice
Definition: kaldi-lattice.h:46
#define KALDI_VLOG(v)
Definition: kaldi-error.h:156
#define KALDI_LOG
Definition: kaldi-error.h:153