31 using namespace kaldi;
33 typedef kaldi::int64 int64;
36 "Rescores lattice with rnnlm. The LM will be wrapped into the\n" 37 "DeterministicOnDemandFst interface and the rescoring is done by\n" 38 "composing with the wrapped LM using a special type of composition\n" 39 "algorithm. Determinization will be applied on the composed lattice.\n" 41 "Usage: lattice-lmrescore-rnnlm [options] [unk_prob_rspecifier] \\\n" 42 " <word-symbol-table-rxfilename> <lattice-rspecifier> \\\n" 43 " <rnnlm-rxfilename> <lattice-wspecifier>\n" 44 " e.g.: lattice-lmrescore-rnnlm --lm-scale=-1.0 words.txt \\\n" 45 " ark:in.lats rnnlm ark:out.lats\n";
48 int32 max_ngram_order = 3;
51 po.Register(
"lm-scale", &lm_scale,
"Scaling factor for language model " 52 "costs; frequently 1.0 or -1.0");
53 po.Register(
"max-ngram-order", &max_ngram_order,
"If positive, limit the " 54 "rnnlm context to the given number, -1 means we are not going " 62 if (po.NumArgs() != 4 && po.NumArgs() != 5) {
67 std::string lats_rspecifier, unk_prob_rspecifier,
68 word_symbols_rxfilename, rnnlm_rxfilename, lats_wspecifier;
69 if (po.NumArgs() == 4) {
70 unk_prob_rspecifier =
"";
71 word_symbols_rxfilename = po.GetArg(1);
72 lats_rspecifier = po.GetArg(2);
73 rnnlm_rxfilename = po.GetArg(3);
74 lats_wspecifier = po.GetArg(4);
75 }
else if (po.NumArgs() == 5) {
76 unk_prob_rspecifier = po.GetArg(1);
77 word_symbols_rxfilename = po.GetArg(2);
78 lats_rspecifier = po.GetArg(3);
79 rnnlm_rxfilename = po.GetArg(4);
80 lats_wspecifier = po.GetArg(5);
85 word_symbols_rxfilename, rnnlm_rxfilename);
91 int32 n_done = 0, n_fail = 0;
92 for (; !compact_lattice_reader.Done(); compact_lattice_reader.Next()) {
93 std::string key = compact_lattice_reader.Key();
96 if (lm_scale != 0.0) {
103 ArcSort(&clat, fst::OLabelCompare<CompactLatticeArc>());
116 Invert(&composed_lat);
120 if (determinized_clat.Start() == fst::kNoStateId) {
121 KALDI_WARN <<
"Empty lattice for utterance " << key
122 <<
" (incompatible LM?)";
125 compact_lattice_writer.Write(key, determinized_clat);
131 compact_lattice_writer.Write(key, clat);
135 KALDI_LOG <<
"Done " << n_done <<
" lattices, failed for " << n_fail;
136 return (n_done != 0 ? 0 : 1);
137 }
catch(
const std::exception &e) {
138 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
A templated class for writing objects to 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...
void ComposeCompactLatticeDeterministic(const CompactLattice &clat, fst::DeterministicOnDemandFst< fst::StdArc > *det_fst, CompactLattice *composed_clat)
This function Composes a CompactLattice format lattice with a DeterministicOnDemandFst<fst::StdFst> f...
fst::VectorFst< LatticeArc > Lattice
fst::VectorFst< CompactLatticeArc > CompactLattice
std::vector< std::vector< double > > GraphLatticeScale(double lmwt)
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 Register(OptionsItf *opts)