lattice-determinize-phone-pruned-parallel.cc File Reference
Include dependency graph for lattice-determinize-phone-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 89 of file lattice-determinize-phone-pruned-parallel.cc.

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

89  {
90  try {
91  using namespace kaldi;
92  typedef kaldi::int32 int32;
93 
94  const char *usage =
95  "Determinize lattices, keeping only the best path (sequence of\n"
96  "acoustic states) for each input-symbol sequence. This is a version\n"
97  "of lattice-determinize-phone-pruned that accepts the --num-threads\n"
98  "option. The program does phone insertion when doing a first pass\n"
99  "determinization, it then removes the inserted symbols and does a\n"
100  "second pass determinization. It also does pruning as part of the\n"
101  "determinization algorithm, which is more efficient and prevents\n"
102  "blowup.\n"
103  "\n"
104  "Usage: lattice-determinize-phone-pruned-parallel [options] \\\n"
105  " <model> <lattice-rspecifier> <lattice-wspecifier>\n"
106  " e.g.: lattice-determinize-phone-pruned-parallel \\\n"
107  " --acoustic-scale=0.1 final.mdl ark:in.lats ark:det.lats\n";
108 
109  ParseOptions po(usage);
110  BaseFloat acoustic_scale = 1.0;
111  BaseFloat beam = 10.0;
112 
113  TaskSequencerConfig sequencer_opts;
115  determinize_opts.max_mem = 50000000;
116 
117  po.Register("acoustic-scale", &acoustic_scale, "Scaling factor for acoustic"
118  " likelihoods.");
119  po.Register("beam", &beam, "Pruning beam [applied after acoustic scaling].");
120  determinize_opts.Register(&po);
121  sequencer_opts.Register(&po);
122  po.Read(argc, argv);
123 
124  if (po.NumArgs() != 3) {
125  po.PrintUsage();
126  exit(1);
127  }
128 
129  std::string model_rxfilename = po.GetArg(1),
130  lats_rspecifier = po.GetArg(2),
131  lats_wspecifier = po.GetArg(3);
132 
133  TransitionModel trans_model;
134  ReadKaldiObject(model_rxfilename, &trans_model);
135 
136  // Reads as regular lattice-- this is the form the determinization code
137  // accepts.
138  SequentialLatticeReader lat_reader(lats_rspecifier);
139 
140  // Writes as compact lattice.
141  CompactLatticeWriter compact_lat_writer(lats_wspecifier);
142 
143  TaskSequencer<DeterminizeLatticeTask> sequencer(sequencer_opts);
144 
145  int32 n_done = 0, n_warn = 0;
146 
147  if (acoustic_scale == 0.0)
148  KALDI_ERR << "Do not use a zero acoustic scale (cannot be inverted)";
149 
150  for (; !lat_reader.Done(); lat_reader.Next()) {
151  std::string key = lat_reader.Key();
152 
153  // Will give ownership to "task" below.
154  Lattice *lat = lat_reader.Value().Copy();
155 
156  KALDI_VLOG(2) << "Processing lattice " << key;
157 
159  trans_model, determinize_opts, key, acoustic_scale, beam,
160  lat, &compact_lat_writer, &n_warn);
161  sequencer.Run(task);
162 
163  n_done++;
164  }
165  sequencer.Wait();
166  KALDI_LOG << "Done " << n_done << " lattices, determinization finished "
167  << "earlier than specified by the beam on " << n_warn << " of "
168  << "these.";
169  return (n_done != 0 ? 0 : 1);
170  } catch(const std::exception &e) {
171  std::cerr << e.what();
172  return -1;
173  }
174 }
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
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
Definition: kaldi-io.cc:832
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