28 int main(
int argc,
char *argv[]) {
30 using namespace kaldi;
32 typedef kaldi::int64 int64;
35 "Rescores lattice with the ConstArpaLm format language model. The LM\n" 36 "will be wrapped into the DeterministicOnDemandFst interface and the\n" 37 "rescoring is done by composing with the wrapped LM using a special\n" 38 "type of composition algorithm. Determinization will be applied on\n" 39 "the composed lattice.\n" 41 "Usage: lattice-lmrescore-const-arpa [options] lattice-rspecifier \\\n" 42 " const-arpa-in lattice-wspecifier\n" 43 " e.g.: lattice-lmrescore-const-arpa --lm-scale=-1.0 ark:in.lats \\\n" 44 " const_arpa ark:out.lats\n";
49 po.
Register(
"lm-scale", &lm_scale,
"Scaling factor for language model " 50 "costs; frequently 1.0 or -1.0");
59 std::string lats_rspecifier = po.
GetArg(1),
60 lm_rxfilename = po.
GetArg(2),
61 lats_wspecifier = po.
GetArg(3);
71 int32 n_done = 0, n_fail = 0;
72 for (; !compact_lattice_reader.
Done(); compact_lattice_reader.
Next()) {
73 std::string key = compact_lattice_reader.
Key();
77 if (lm_scale != 0.0) {
84 ArcSort(&clat, fst::OLabelCompare<CompactLatticeArc>());
93 &const_arpa_fst, &composed_clat);
98 Invert(&composed_lat);
102 if (determinized_clat.Start() == fst::kNoStateId) {
103 KALDI_WARN <<
"Empty lattice for utterance " << key
104 <<
" (incompatible LM?)";
107 compact_lattice_writer.
Write(key, determinized_clat);
113 compact_lattice_writer.
Write(key, clat);
117 KALDI_LOG <<
"Done " << n_done <<
" lattices, failed for " << n_fail;
118 return (n_done != 0 ? 0 : 1);
119 }
catch(
const std::exception &e) {
120 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].
int main(int argc, char *argv[])
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)
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 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...
This class wraps a ConstArpaLm format language model with the interface defined in DeterministicOnDem...