30 int main(
int argc,
char *argv[]) {
32 using namespace kaldi;
34 typedef kaldi::int64 int64;
35 using fst::SymbolTable;
41 "This program can be used to subtract scores from one language model and\n" 42 "add scores from another one. It uses an efficient rescoring algorithm that\n" 43 "avoids exploring the entire composed lattice. The first (negative-weight)\n" 44 "language model is expected to be an FST, e.g. G.fst; the second one can\n" 45 "either be in FST or const-arpa format. Any FST-format language models will\n" 46 "be projected on their output by this program, making it unnecessary for the\n" 47 "caller to remove disambiguation symbols.\n" 49 "Usage: lattice-lmrescore-pruned [options] <lm-to-subtract> <lm-to-add> <lattice-rspecifier> <lattice-wspecifier>\n" 50 " e.g.: lattice-lmrescore-pruned --acoustic-scale=0.1 \\\n" 51 " data/lang/G.fst data/lang_fg/G.fst ark:in.lats ark:out.lats\n" 52 " or: lattice-lmrescore-pruned --acoustic-scale=0.1 --add-const-arpa=true\\\n" 53 " data/lang/G.fst data/lang_fg/G.carpa ark:in.lats ark:out.lats\n";
62 bool add_const_arpa =
false;
64 po.
Register(
"lm-scale", &lm_scale,
"Scaling factor for <lm-to-add>; its negative " 65 "will be applied to <lm-to-subtract>.");
66 po.
Register(
"acoustic-scale", &acoustic_scale,
"Scaling factor for acoustic " 67 "probabilities (e.g. 0.1 for non-chain systems); important because " 68 "of its effect on pruning.");
69 po.
Register(
"add-const-arpa", &add_const_arpa,
"If true, <lm-to-add> is expected" 70 "to be in const-arpa format; if false it's expected to be in FST" 81 std::string lm_to_subtract_rxfilename = po.
GetArg(1),
82 lm_to_add_rxfilename = po.
GetArg(2),
83 lats_rspecifier = po.
GetArg(3),
84 lats_wspecifier = po.
GetArg(4);
88 lm_to_subtract_rxfilename);
89 VectorFst<StdArc> *lm_to_add_fst = NULL;
99 -lm_scale, &lm_to_subtract_det_backoff);
104 if (add_const_arpa) {
110 if (lm_scale != 1.0) {
111 lm_to_add_orig = lm_to_add;
124 int32 num_done = 0, num_err = 0;
126 for (; !clat_reader.
Done(); clat_reader.
Next()) {
127 std::string key = clat_reader.
Key();
130 if (acoustic_scale != 1.0) {
141 &lm_to_subtract_det_scale, lm_to_add);
149 if (composed_clat.NumStates() == 0) {
153 if (acoustic_scale != 1.0) {
154 if (acoustic_scale == 0.0)
155 KALDI_ERR <<
"Acoustic scale cannot be zero.";
159 compact_lattice_writer.
Write(key, composed_clat);
163 delete lm_to_subtract_fst;
164 delete lm_to_add_fst;
165 delete lm_to_add_orig;
168 KALDI_LOG <<
"Overall, succeeded for " << num_done
169 <<
" lattices, failed for " << num_err;
170 return (num_done != 0 ? 0 : 1);
171 }
catch(
const std::exception &e) {
172 std::cerr << e.what();
This class wraps an Fst, representing a language model, using the interface for "BackoffDeterministic...
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Class ScaleDeterministicOnDemandFst takes another DeterministicOnDemandFst and scales the weights (li...
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
A templated class for writing objects to an archive or script file; see The Table concept...
void Write(const std::string &key, const T &value) const
void Register(const std::string &name, bool *ptr, const std::string &doc)
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
int main(int argc, char *argv[])
std::vector< std::vector< double > > AcousticLatticeScale(double acwt)
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...
fst::VectorFst< fst::StdArc > * ReadAndPrepareLmFst(std::string rxfilename)
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
void ComposeCompactLatticePruned(const ComposeLatticePrunedOptions &opts, const CompactLattice &clat, fst::DeterministicOnDemandFst< fst::StdArc > *det_fst, CompactLattice *composed_clat)
Does pruned composition of a lattice 'clat' with a DeterministicOnDemandFst 'det_fst'; implements LM ...
fst::VectorFst< CompactLatticeArc > CompactLattice
int NumArgs() const
Number of positional parameters (c.f. argc-1).
void ReadFstKaldi(std::istream &is, bool binary, VectorFst< Arc > *fst)
void TopSortCompactLatticeIfNeeded(CompactLattice *clat)
Topologically sort the compact lattice if not already topologically sorted.
This class wraps a ConstArpaLm format language model with the interface defined in DeterministicOnDem...