115 using fst::SymbolTable;
116 using fst::VectorFst;
120 "Print out information regarding posteriors of lattice arcs\n" 121 "This program computes posteriors from a lattice and prints out\n" 122 "information for each arc (the format is reminiscent of ctm, but\n" 123 "contains information from multiple paths). Each line is:\n" 124 " <utterance-id> <start-frame> <num-frames> <posterior> <word> [<ali>] [<phone1> <phone2>...]\n" 126 "2013a04-bk42\t104\t26\t0.95\t0\t11,242,242,242,71,894,894,62,63,63,63,63\t2 8 9\n" 127 "where the --print-alignment option determines whether the alignments (i.e. the\n" 128 "sequences of transition-ids) are printed, and the phones are printed only if the\n" 129 "<model> is supplied on the command line. Note, there are tabs between the major\n" 130 "fields, but the phones are separated by spaces.\n" 131 "Usage: lattice-arc-post [<model>] <lattices-rspecifier> <output-wxfilename>\n" 132 "e.g.: lattice-arc-post --acoustic-scale=0.1 final.mdl 'ark:gunzip -c lat.1.gz|' post.txt\n" 133 "You will probably want to word-align the lattices (e.g. lattice-align-words or\n" 134 "lattice-align-words-lexicon) before this program, apply an acoustic scale either\n" 135 "via the --acoustic-scale option or using lattice-scale.\n" 136 "See also: lattice-post, lattice-to-ctm-conf, nbest-to-ctm\n";
140 bool print_alignment =
false;
143 po.Register(
"acoustic-scale", &acoustic_scale,
144 "Scaling factor for acoustic likelihoods");
145 po.Register(
"lm-scale", &lm_scale,
146 "Scaling factor for \"graph costs\" (including LM costs)");
147 po.Register(
"print-alignment", &print_alignment,
148 "If true, print alignments (i.e. sequences of transition-ids) for each\n" 150 po.Register(
"min-post", &min_post,
151 "Arc posteriors below this value will be pruned away");
154 if (po.NumArgs() < 2 || po.NumArgs() > 3) {
159 if (acoustic_scale == 0.0)
160 KALDI_ERR <<
"Do not use a zero acoustic scale (cannot be inverted)";
164 std::string lats_rspecifier, output_wxfilename;
165 if (po.NumArgs() == 3) {
167 lats_rspecifier = po.GetArg(2);
168 output_wxfilename = po.GetArg(3);
170 lats_rspecifier = po.GetArg(1);
171 output_wxfilename = po.GetArg(2);
181 int32 num_lat_done = 0, num_lat_err = 0;
183 for (; !clat_reader.Done(); clat_reader.Next()) {
184 std::string key = clat_reader.Key();
188 clat_reader.FreeCurrent();
193 clat, min_post, print_alignment,
194 (po.NumArgs() == 3 ? &trans_model : NULL));
196 int32 num_post = computer.OutputPosteriors(key, output.Stream());
199 tot_post += num_post;
202 KALDI_WARN <<
"No posterior printed for " << key;
205 KALDI_LOG <<
"Printed posteriors for " << num_lat_done <<
" lattices (" 206 << num_lat_err <<
" with errors); on average printed " 207 << (tot_post / (num_lat_done == 0 ? 1 : num_lat_done))
208 <<
" posteriors per lattice.";
209 return (num_lat_done > 0 ? 0 : 1);
210 }
catch(
const std::exception &e) {
211 std::cerr << e.what();
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
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...
std::vector< std::vector< double > > LatticeScale(double lmwt, double acwt)
fst::VectorFst< CompactLatticeArc > CompactLattice
void TopSortCompactLatticeIfNeeded(CompactLattice *clat)
Topologically sort the compact lattice if not already topologically sorted.