51 if (
clat_.Start() < 0)
56 for (
int32 state = 0; state < num_states; state++) {
57 for (fst::ArcIterator<CompactLattice> aiter(
clat_, state);
58 !aiter.Done(); aiter.Next()) {
63 "Bad arc posterior in forward-backward computation");
64 if (arc_loglike > 0.0) arc_loglike = 0.0;
65 int32 num_frames = arc.weight.String().size(),
69 os << utterance <<
'\t' <<
state_times_[state] <<
'\t' << num_frames
70 <<
'\t' << arc_post <<
'\t' << word;
73 const std::vector<int32> &ali = arc.weight.String();
74 for (
int32 frame = 0; frame < num_frames; frame++) {
76 if (frame + 1 < num_frames) os <<
',';
82 const std::vector<int32> &ali = arc.weight.String();
83 bool first_phone =
true;
84 for (
int32 frame = 0; frame < num_frames; frame++) {
86 if (first_phone) first_phone =
false;
112 int main(
int argc,
char *argv[]) {
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");
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" 151 "Arc posteriors below this value will be pruned away");
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;
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();
193 clat, min_post, print_alignment,
194 (po.
NumArgs() == 3 ? &trans_model : NULL));
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();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
std::vector< int32 > state_times_
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
std::vector< double > alpha_
ArcPosteriorComputer(const CompactLattice &clat, BaseFloat min_post, bool print_alignment, const TransitionModel *trans_model=NULL)
void Register(const std::string &name, bool *ptr, const std::string &doc)
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...
bool ComputeCompactLatticeBetas(const CompactLattice &clat, vector< double > *beta)
double ConvertToCost(const LatticeWeightTpl< Float > &w)
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)
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
int32 CompactLatticeStateTimes(const CompactLattice &lat, vector< int32 > *times)
As LatticeStateTimes, but in the CompactLattice format.
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
int32 OutputPosteriors(const std::string &utterance, std::ostream &os)
fst::VectorFst< CompactLatticeArc > CompactLattice
int NumArgs() const
Number of positional parameters (c.f. argc-1).
#define KALDI_ASSERT(cond)
fst::ArcTpl< CompactLatticeWeight > CompactLatticeArc
void TopSortCompactLatticeIfNeeded(CompactLattice *clat)
Topologically sort the compact lattice if not already topologically sorted.
int main(int argc, char *argv[])
std::vector< double > beta_
bool ComputeCompactLatticeAlphas(const CompactLattice &clat, vector< double > *alpha)
bool IsFinal(int32 trans_id) const
int32 TransitionIdToPhone(int32 trans_id) const
const CompactLattice & clat_
const TransitionModel * trans_model_