33 const std::string &key,
45 lat_opts.
delta = delta;
47 for (
int32 i = 0;
i < num_loops;) {
49 if (lat.Start() == fst::kNoStateId) {
50 KALDI_WARN <<
"Detected empty lattice, skipping " << key;
59 KALDI_WARN <<
"Failed to determinize lattice (presumably max-states " 60 <<
"reached), reducing lattice-beam to " 61 << (cur_beam*beam_ratio) <<
" and re-trying.";
62 for (;
i < num_loops;
i++) {
63 cur_beam *= beam_ratio;
67 cur_beam *= beam_ratio;
68 KALDI_WARN <<
"Pruning did not have an effect on the original " 69 <<
"lattice size; reducing beam to " 70 << cur_beam <<
" and re-trying.";
75 KALDI_WARN <<
"Determinization failed again; reducing beam again to " 76 << (cur_beam*beam_ratio) <<
" and re-trying.";
81 KALDI_WARN <<
"Decreased pruning beam --num-loops=" << num_loops
82 <<
" times and was not able to determinize: failed for " 89 int main(
int argc,
char *argv[]) {
91 using namespace kaldi;
93 typedef kaldi::int64 int64;
94 using fst::SymbolTable;
99 "This program is deprecated, please used lattice-determinize-pruned.\n" 100 "lattice-determinize lattices (and apply a pruning beam)\n" 101 " (see http://kaldi-asr.org/doc/lattices.html for more explanation)\n" 102 " note: this program is tyically only useful if you generated state-level\n" 103 " lattices, e.g. called gmm-latgen-simple with --determinize=false\n" 105 "Usage: lattice-determinize [options] lattice-rspecifier lattice-wspecifier\n" 106 " e.g.: lattice-determinize --acoustic-scale=0.1 --beam=15.0 ark:1.lats ark:det.lats\n";
112 int32 num_loops = 20;
113 int32 max_mem = 50000000;
114 int32 max_loop = 500000;
117 bool minimize =
false;
119 po.
Register(
"acoustic-scale", &acoustic_scale,
120 "Scaling factor for acoustic likelihoods");
122 "Pruning beam [applied after acoustic scaling]-- also used " 123 "to handle determinization failures, set --prune=false to " 124 "disable routine pruning");
125 po.
Register(
"delta", &delta,
"Tolerance used in determinization");
126 po.
Register(
"prune", &prune,
"If true, prune determinized lattices " 127 "with the --beam option.");
128 po.
Register(
"max-mem", &max_mem,
"Maximum approximate memory usage in " 129 "determinization (real usage might be many times this)");
130 po.
Register(
"max-loop", &max_loop,
"Option to detect a certain " 131 "type of failure in lattice determinization (not critical)");
132 po.
Register(
"beam-ratio", &beam_ratio,
"Ratio by which to " 133 "decrease beam if we reach the max-arcs.");
134 po.
Register(
"num-loops", &num_loops,
"Number of times to " 135 "decrease beam by beam-ratio if determinization fails.");
137 "If true, push and minimize after determinization");
146 std::string lats_rspecifier = po.
GetArg(1),
147 lats_wspecifier = po.
GetArg(2);
157 int32 n_done = 0, n_error = 0;
160 double sum_depth_in = 0.0,
161 sum_depth_out = 0.0, sum_t = 0.0;
163 if (acoustic_scale == 0.0)
164 KALDI_ERR <<
"Do not use a zero acoustic scale (cannot be inverted)";
165 LatticeWeight beam_weight(beam, static_cast<BaseFloat>(0.0));
167 for (; !lattice_reader.
Done(); lattice_reader.
Next()) {
168 std::string key = lattice_reader.
Key();
177 beam, beam_ratio, max_mem, max_loop,
178 delta, num_loops, &clat)) {
188 sum_depth_in += lat.NumStates();
189 sum_depth_out += depth * t;
193 compact_lattice_writer.
Write(key, clat);
201 KALDI_LOG <<
"Average input-lattice depth (measured at at state level) is " 202 << (sum_depth_in / sum_t) <<
", output depth is " 203 << (sum_depth_out / sum_t) <<
", over " << sum_t <<
" frames " 204 <<
" (average num-frames = " << (sum_t / n_done) <<
").";
206 KALDI_LOG <<
"Done " << n_done <<
" lattices, errors on " << n_error;
207 return (n_done != 0 ? 0 : 1);
208 }
catch(
const std::exception &e) {
209 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
int main(int argc, char *argv[])
bool DeterminizeLatticeWrapper(const Lattice &lat, const std::string &key, bool prune, BaseFloat beam, BaseFloat beam_ratio, int32 max_mem, int32 max_loop, BaseFloat delta, int32 num_loops, CompactLattice *clat)
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
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...
void Write(const std::string &key, const T &value) const
void Register(const std::string &name, bool *ptr, const std::string &doc)
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...
std::vector< std::vector< double > > AcousticLatticeScale(double acwt)
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
bool MinimizeCompactLattice(MutableFst< ArcTpl< CompactLatticeWeightTpl< Weight, IntType > > > *clat, float delta)
This function minimizes the compact lattice.
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...
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
fst::VectorFst< LatticeArc > Lattice
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
fst::VectorFst< CompactLatticeArc > CompactLattice
int NumArgs() const
Number of positional parameters (c.f. argc-1).
bool PruneLattice(BaseFloat beam, LatType *lat)
bool DeterminizeLattice(const Fst< ArcTpl< Weight > > &ifst, MutableFst< ArcTpl< Weight > > *ofst, DeterminizeLatticeOptions opts, bool *debug_ptr)
This function implements the normal version of DeterminizeLattice, in which the output strings are re...
void TopSortCompactLatticeIfNeeded(CompactLattice *clat)
Topologically sort the compact lattice if not already topologically sorted.
Arc::StateId NumArcs(const ExpandedFst< Arc > &fst)
Returns the total number of arcs in an FST.