lattice-determinize-pruned-parallel.cc File Reference
Include dependency graph for lattice-determinize-pruned-parallel.cc:

Go to the source code of this file.

Classes

class  DeterminizeLatticeTask
 

Namespaces

 kaldi
 This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for mispronunciations detection tasks, the reference:
 

Functions

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

Function Documentation

◆ main()

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

Definition at line 97 of file lattice-determinize-pruned-parallel.cc.

References DeterminizeLatticeTask::DeterminizeLatticeTask(), SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), KALDI_ERR, KALDI_LOG, KALDI_VLOG, SequentialTableReader< Holder >::Key(), DeterminizeLatticePrunedOptions::max_loop, DeterminizeLatticePrunedOptions::max_mem, SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), ParseOptions::Register(), DeterminizeLatticePrunedOptions::Register(), TaskSequencerConfig::Register(), TaskSequencer< C >::Run(), SequentialTableReader< Holder >::Value(), and TaskSequencer< C >::Wait().

97  {
98  try {
99  using namespace kaldi;
100  typedef kaldi::int32 int32;
101 
102  const char *usage =
103  "Determinize lattices, keeping only the best path (sequence of acoustic states)\n"
104  "for each input-symbol sequence. This is a version of lattice-determnize-pruned\n"
105  "that accepts the --num-threads option. These programs do pruning as part of the\n"
106  "determinization algorithm, which is more efficient and prevents blowup.\n"
107  "See http://kaldi-asr.org/doc/lattices.html for more information on lattices.\n"
108  "\n"
109  "Usage: lattice-determinize-pruned-parallel [options] lattice-rspecifier lattice-wspecifier\n"
110  " e.g.: lattice-determinize-pruned-parallel --acoustic-scale=0.1 --beam=6.0 ark:in.lats ark:det.lats\n";
111 
112  ParseOptions po(usage);
113  BaseFloat acoustic_scale = 1.0;
114  BaseFloat beam = 10.0;
115  bool minimize = false;
116  TaskSequencerConfig sequencer_config; // has --num-threads option
117  fst::DeterminizeLatticePrunedOptions determinize_config; // Options used in DeterminizeLatticePruned--
118  // this options class does not have its own Register function as it's viewed as
119  // being more part of "fst world", so we register its elements independently.
120  determinize_config.max_mem = 50000000;
121  determinize_config.max_loop = 0; // was 500000;
122 
123  po.Register("acoustic-scale", &acoustic_scale,
124  "Scaling factor for acoustic likelihoods");
125  po.Register("beam", &beam, "Pruning beam [applied after acoustic scaling].");
126  po.Register("minimize", &minimize,
127  "If true, push and minimize after determinization");
128  determinize_config.Register(&po);
129  sequencer_config.Register(&po);
130  po.Read(argc, argv);
131 
132  if (po.NumArgs() != 2) {
133  po.PrintUsage();
134  exit(1);
135  }
136 
137  std::string lats_rspecifier = po.GetArg(1),
138  lats_wspecifier = po.GetArg(2);
139 
140 
141  // Read as regular lattice-- this is the form the determinization code
142  // accepts.
143  SequentialLatticeReader lat_reader(lats_rspecifier);
144 
145  // Write as compact lattice.
146  CompactLatticeWriter compact_lat_writer(lats_wspecifier);
147  TaskSequencer<DeterminizeLatticeTask> sequencer(sequencer_config);
148 
149  int32 n_done = 0, n_warn = 0;
150 
151  if (acoustic_scale == 0.0)
152  KALDI_ERR << "Do not use a zero acoustic scale (cannot be inverted)";
153 
154  for (; !lat_reader.Done(); lat_reader.Next()) {
155  std::string key = lat_reader.Key();
156 
157  Lattice *lat = lat_reader.Value().Copy(); // will give ownership to "task"
158  // below
159 
160  KALDI_VLOG(2) << "Processing lattice " << key;
161 
162  DeterminizeLatticeTask *task = new DeterminizeLatticeTask(
163  determinize_config, key, acoustic_scale, beam, minimize,
164  lat, &compact_lat_writer, &n_warn);
165  sequencer.Run(task);
166  n_done++;
167  }
168  sequencer.Wait();
169  KALDI_LOG << "Done " << n_done << " lattices, had warnings on " << n_warn
170  << " of these.";
171  return (n_done != 0 ? 0 : 1);
172  } catch(const std::exception &e) {
173  std::cerr << e.what();
174  return -1;
175  }
176 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
A templated class for writing objects to an archive or script file; see The Table concept...
Definition: kaldi-table.h:368
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Definition: kaldi-table.h:287
fst::VectorFst< LatticeArc > Lattice
Definition: kaldi-lattice.h:44
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_VLOG(v)
Definition: kaldi-error.h:156
#define KALDI_LOG
Definition: kaldi-error.h:153
void Register(OptionsItf *opts)
Definition: kaldi-thread.h:160