29 using fst::SymbolTable;
34 "Boost graph likelihoods (decrease graph costs) by b * #frame-phone-errors\n" 35 "on each arc in the lattice. Useful for discriminative training, e.g.\n" 36 "boosted MMI. Modifies input lattices. This version takes the reference\n" 37 "in the form of alignments. Needs the model (just the transitions) to\n" 38 "transform pdf-ids to phones. Takes the --silence-phones option and these\n" 39 "phones appearing in the lattice are always assigned zero error, or with the\n" 40 "--max-silence-error option, at most this error-count per frame\n" 41 "(--max-silence-error=1 is equivalent to not specifying --silence-phones).\n" 43 "Usage: lattice-boost-ali [options] model lats-rspecifier ali-rspecifier lats-wspecifier\n" 44 " e.g.: lattice-boost-ali --silence-phones=1:2:3 --b=0.05 1.mdl ark:1.lats ark:1.ali ark:boosted.lats\n";
48 std::string silence_phones_str;
52 "Boosting factor (more -> more boosting of errors / larger margin)");
53 po.Register(
"max-silence", &max_silence_error,
54 "Maximum error assigned to silence phones [c.f. --silence-phones option]." 55 "0.0 -> original BMMI paper, 1.0 -> no special silence treatment.");
56 po.Register(
"silence-phones", &silence_phones_str,
57 "Colon-separated list of integer id's of silence phones, e.g. 46:47");
60 if (po.NumArgs() != 4) {
65 std::vector<int32> silence_phones;
67 KALDI_ERR <<
"Invalid silence-phones string " << silence_phones_str;
69 if (silence_phones.empty())
70 KALDI_WARN <<
"No silence phones specified, make sure this is what you intended.";
72 std::string model_rxfilename = po.GetArg(1),
73 lats_rspecifier = po.GetArg(2),
74 ali_rspecifier = po.GetArg(3),
75 lats_wspecifier = po.GetArg(4);
86 trans.
Read(ki.Stream(), binary_in);
89 int32 n_done = 0, n_err = 0, n_no_ali = 0;
91 for (; !lattice_reader.Done(); lattice_reader.Next()) {
92 std::string key = lattice_reader.Key();
94 lattice_reader.FreeCurrent();
96 if (lat.Start() == fst::kNoStateId) {
97 KALDI_WARN <<
"Empty lattice for utterance " << key;
103 if (!alignment_reader.HasKey(key)) {
104 KALDI_WARN <<
"No alignment for utterance " << key;
108 const std::vector<int32> &alignment = alignment_reader.Value(key);
110 max_silence_error, &lat)) {
117 compact_lattice_writer.Write(key, clat);
120 KALDI_LOG <<
"Done " << n_done <<
" lattices, missing alignments for " 121 << n_no_ali <<
", other errors on " << n_err;
122 return (n_done != 0 ? 0 : 1);
123 }
catch(
const std::exception &e) {
124 std::cerr << e.what();
bool SplitStringToIntegers(const std::string &full, const char *delim, bool omit_empty_strings, std::vector< I > *out)
Split a string (e.g.
A templated class for writing objects to an archive or script file; see The Table concept...
void SortAndUniq(std::vector< T > *vec)
Sorts and uniq's (removes duplicates) from a vector.
Allows random access to a collection of objects in an archive or script file; see The Table concept...
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
void Read(std::istream &is, bool binary)
void ConvertLattice(const ExpandedFst< ArcTpl< Weight > > &ifst, MutableFst< ArcTpl< CompactLatticeWeightTpl< Weight, Int > > > *ofst, bool invert)
Convert lattice from a normal FST to a CompactLattice FST.
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
fst::VectorFst< LatticeArc > Lattice
fst::VectorFst< CompactLatticeArc > CompactLattice
bool LatticeBoost(const TransitionModel &trans, const std::vector< int32 > &alignment, const std::vector< int32 > &silence_phones, BaseFloat b, BaseFloat max_silence_error, Lattice *lat)
Boosts LM probabilities by b * [number of frame errors]; equivalently, adds -b*[number of frame error...