27 #include "rnnlm/rnnlm-lattice-rescoring.h" 31 int main(
int argc,
char *argv[]) {
33 using namespace kaldi;
35 typedef kaldi::int64 int64;
38 "Rescores lattice with kaldi-rnnlm. This script is called from \n" 39 "scripts/rnnlm/lmrescore.sh. An example for rescoring \n" 40 "lattices is at egs/swbd/s5c/local/rnnlm/run_lstm.sh \n" 42 "Usage: lattice-lmrescore-kaldi-rnnlm [options] \\\n" 43 " <embedding-file> <raw-rnnlm-rxfilename> \\\n" 44 " <lattice-rspecifier> <lattice-wspecifier>\n" 45 " e.g.: lattice-lmrescore-kaldi-rnnlm --lm-scale=-1.0 \\\n" 46 " word_embedding.mat \\\n" 47 " --bos-symbol=1 --eos-symbol=2 \\\n" 48 " final.raw ark:in.lats ark:out.lats\n";
51 rnnlm::RnnlmComputeStateComputationOptions opts;
53 int32 max_ngram_order = 3;
56 po.
Register(
"lm-scale", &lm_scale,
"Scaling factor for language model " 58 po.
Register(
"max-ngram-order", &max_ngram_order,
59 "If positive, allow RNNLM histories longer than this to be identified " 60 "with each other for rescoring purposes (an approximation that " 61 "saves time and reduces output lattice size).");
71 if (opts.bos_index == -1 || opts.eos_index == -1) {
72 KALDI_ERR <<
"You must set --bos-symbol and --eos-symbol options";
75 std::string word_embedding_rxfilename = po.
GetArg(1),
76 rnnlm_rxfilename = po.
GetArg(2),
77 lats_rspecifier = po.
GetArg(3),
78 lats_wspecifier = po.
GetArg(4);
88 const rnnlm::RnnlmComputeStateInfo info(opts, rnnlm, word_embedding_mat);
94 int32 n_done = 0, n_fail = 0;
96 rnnlm::KaldiRnnlmDeterministicFst rnnlm_fst(max_ngram_order, info);
98 for (; !compact_lattice_reader.
Done(); compact_lattice_reader.
Next()) {
99 std::string key = compact_lattice_reader.
Key();
102 if (lm_scale != 0.0) {
109 ArcSort(&clat, fst::OLabelCompare<CompactLatticeArc>());
121 Invert(&composed_lat);
125 if (determinized_clat.Start() == fst::kNoStateId) {
126 KALDI_WARN <<
"Empty lattice for utterance " << key
127 <<
" (incompatible LM?)";
130 compact_lattice_writer.
Write(key, determinized_clat);
136 compact_lattice_writer.
Write(key, clat);
141 KALDI_LOG <<
"Done " << n_done <<
" lattices, failed for " << n_fail;
142 return (n_done != 0 ? 0 : 1);
143 }
catch(
const std::exception &e) {
144 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
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...
This class represents a matrix that's stored on the GPU if we have one, and in memory if not...
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)
This file contains some miscellaneous functions dealing with class Nnet.
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
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.
fst::VectorFst< CompactLatticeArc > CompactLattice
std::vector< std::vector< double > > GraphLatticeScale(double lmwt)
int NumArgs() const
Number of positional parameters (c.f. argc-1).
bool IsSimpleNnet(const Nnet &nnet)
This function returns true if the nnet has the following properties: It has an output called "output"...
int main(int argc, char *argv[])
#define KALDI_ASSERT(cond)
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...