34     using namespace kaldi;
    36     typedef kaldi::int64 int64;
    37     using fst::SymbolTable;
    43         "Rescores lattice with kaldi-rnnlm. This script is called from \n"    44         "scripts/rnnlm/lmrescore_pruned.sh. An example for rescoring \n"    45         "lattices is at egs/swbd/s5c/local/rnnlm/run_lstm.sh \n"    47         "Usage: lattice-lmrescore-kaldi-rnnlm-pruned [options] \\\n"    48         "             <old-lm-rxfilename> <embedding-file> \\\n"    49         "             <raw-rnnlm-rxfilename> \\\n"    50         "             <lattice-rspecifier> <lattice-wspecifier>\n"    51         " e.g.: lattice-lmrescore-kaldi-rnnlm-pruned --lm-scale=-1.0 fst_words.txt \\\n"    52         "              --bos-symbol=1 --eos-symbol=2 \\\n"    53         "              data/lang_test/G.fst word_embedding.mat \\\n"    54         "              final.raw ark:in.lats ark:out.lats\n\n"    55         "       lattice-lmrescore-kaldi-rnnlm-pruned --lm-scale=-1.0 fst_words.txt \\\n"    56         "              --bos-symbol=1 --eos-symbol=2 \\\n"    57         "              data/lang_test_fg/G.carpa word_embedding.mat \\\n"    58         "              final.raw ark:in.lats ark:out.lats\n";
    61     rnnlm::RnnlmComputeStateComputationOptions opts;
    64     int32 max_ngram_order = 3;
    67     bool use_carpa = 
false;
    69     po.Register(
"lm-scale", &lm_scale, 
"Scaling factor for <lm-to-add>; its negative "    70                 "will be applied to <lm-to-subtract>.");
    71     po.Register(
"acoustic-scale", &acoustic_scale, 
"Scaling factor for acoustic "    72                 "probabilities (e.g. 0.1 for non-chain systems); important because "    73                 "of its effect on pruning.");
    74     po.Register(
"max-ngram-order", &max_ngram_order,
    75         "If positive, allow RNNLM histories longer than this to be identified "    76         "with each other for rescoring purposes (an approximation that "    77         "saves time and reduces output lattice size).");
    78     po.Register(
"use-const-arpa", &use_carpa, 
"If true, read the old-LM file "    79                 "as a const-arpa file as opposed to an FST file");
    86     if (po.NumArgs() != 5) {
    91     if (opts.bos_index == -1 || opts.eos_index == -1) {
    92       KALDI_ERR << 
"must set --bos-symbol and --eos-symbol options";
    95     std::string lm_to_subtract_rxfilename, lats_rspecifier,
    96                 word_embedding_rxfilename, rnnlm_rxfilename, lats_wspecifier;
    98     lm_to_subtract_rxfilename = po.GetArg(1),
    99     word_embedding_rxfilename = po.GetArg(2);
   100     rnnlm_rxfilename = po.GetArg(3);
   101     lats_rspecifier = po.GetArg(4);
   102     lats_wspecifier = po.GetArg(5);
   107     VectorFst<StdArc> *lm_to_subtract_fst = NULL;
   118       lm_to_subtract_det_scale
   120                                                  carpa_lm_to_subtract_fst);
   123           lm_to_subtract_rxfilename);
   124       lm_to_subtract_det_backoff =
   126       lm_to_subtract_det_scale =
   128                                                   lm_to_subtract_det_backoff);
   139     const rnnlm::RnnlmComputeStateInfo info(opts, rnnlm, word_embedding_mat);
   145     int32 num_done = 0, num_err = 0;
   147     rnnlm::KaldiRnnlmDeterministicFst* lm_to_add_orig = 
   148          new rnnlm::KaldiRnnlmDeterministicFst(max_ngram_order, info);
   150     for (; !compact_lattice_reader.Done(); compact_lattice_reader.Next()) {
   154       std::string key = compact_lattice_reader.Key();
   156       compact_lattice_reader.FreeCurrent();
   163       if (acoustic_scale != 1.0) {
   169           lm_to_subtract_det_scale, lm_to_add);
   174                                   &combined_lms, &composed_clat);
   176       lm_to_add_orig->Clear();
   178       if (composed_clat.NumStates() == 0) {
   182         if (acoustic_scale != 1.0) {
   183           if (acoustic_scale == 0.0)
   184             KALDI_ERR << 
"Acoustic scale cannot be zero.";
   188         compact_lattice_writer.Write(key, composed_clat);
   194     delete lm_to_subtract_fst;
   195     delete lm_to_add_orig;
   196     delete lm_to_subtract_det_backoff;
   197     delete lm_to_subtract_det_scale;
   200     delete carpa_lm_to_subtract_fst;
   202     KALDI_LOG << 
"Overall, succeeded for " << num_done
   203               << 
" lattices, failed for " << num_err;
   204     return (num_done != 0 ? 0 : 1);
   205   } 
catch(
const std::exception &e) {
   206     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...
 
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 ReadKaldiObject(const std::string &filename, Matrix< float > *m)
 
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...
 
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
 
bool IsSimpleNnet(const Nnet &nnet)
This function returns true if the nnet has the following properties: It has an output called "output"...
 
#define KALDI_ASSERT(cond)
 
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...
 
void Register(OptionsItf *po)