28 using namespace kaldi;
30 typedef kaldi::int64 int64;
31 using fst::SymbolTable;
36 "Takes two archives of lattices (indexed by utterances) and combines\n" 37 "the individual lattice pairs (one from each archive). Keeps the alignments\n" 38 "from the first lattice. Equivalent to\n" 39 "projecting the second archive on words (lattice-project), then composing\n" 40 "the pairs of lattices (lattice-compose), then scaling graph and acoustic\n" 41 "costs by 0.5 (lattice-scale). You can control the individual scales with\n" 42 "--alpha, which is the scale of the first lattices (the second is 1-alpha).\n" 43 "Usage: lattice-interp [options] lattice-rspecifier-a lattice-rspecifier-b" 44 " lattice-wspecifier\n" 45 " e.g.: lattice-compose ark:1.lats ark:2.lats ark:composed.lats\n";
50 po.Register(
"alpha", &alpha,
"Scale of the first lattice in the pair (should be in range [0, 1])");
53 if (po.NumArgs() != 3) {
58 std::string lats_rspecifier1 = po.GetArg(1),
59 lats_rspecifier2 = po.GetArg(2),
60 lats_wspecifier = po.GetArg(3);
67 int32 n_processed = 0, n_empty = 0, n_success = 0, n_no_2ndlat=0;
69 for (; !lattice_reader1.Done(); lattice_reader1.Next()) {
70 std::string key = lattice_reader1.Key();
71 Lattice lat1 = lattice_reader1.Value();
72 lattice_reader1.FreeCurrent();
74 ArcSort(&lat1, fst::OLabelCompare<LatticeArc>());
76 if (lattice_reader2.HasKey(key)) {
83 fst::Project(&lat2, fst::PROJECT_OUTPUT);
85 ArcSort(&lat2, fst::ILabelCompare<LatticeArc>());
88 Compose(lat1, lat2, &lat3);
89 if (lat3.Start() == fst::kNoStateId) {
90 KALDI_WARN <<
"For utterance " << key <<
", composed result is empty.";
96 compact_lattice_writer.Write(key, clat3);
99 KALDI_WARN <<
"No lattice found for utterance " << key <<
" in " 100 << lats_rspecifier2 <<
". Not producing output";
104 KALDI_LOG <<
"Done " << n_processed <<
" lattices; " 105 << n_success <<
" had nonempty result, " << n_empty
106 <<
" had empty composition; in " << n_no_2ndlat
107 <<
", had empty second lattice.";
108 return (n_success != 0 ? 0 : 1);
109 }
catch(
const std::exception &e) {
110 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void RemoveAlignmentsFromCompactLattice(MutableFst< ArcTpl< CompactLatticeWeightTpl< Weight, Int > > > *fst)
Removes state-level alignments (the strings that are part of the weights).
A templated class for writing objects to an archive or script file; see The Table concept...
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 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...
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...
std::vector< std::vector< double > > LatticeScale(double lmwt, double acwt)
fst::VectorFst< LatticeArc > Lattice
fst::VectorFst< CompactLatticeArc > CompactLattice