lattice-add-penalty.cc File Reference
Include dependency graph for lattice-add-penalty.cc:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 23 of file lattice-add-penalty.cc.

References kaldi::AddWordInsPenToCompactLattice(), SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), KALDI_LOG, SequentialTableReader< Holder >::Key(), SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), ParseOptions::Register(), SequentialTableReader< Holder >::Value(), and TableWriter< Holder >::Write().

23  {
24  using namespace kaldi;
25  typedef kaldi::int64 int64;
26  try {
27  const char *usage =
28  "Add word insertion penalty to the lattice.\n"
29  "Note: penalties are negative log-probs, base e, and are added to the\n"
30  "'language model' part of the cost.\n"
31  "\n"
32  "Usage: lattice-add-penalty [options] <lattice-rspecifier> <lattice-wspecifier>\n"
33  " e.g.: lattice-add-penalty --word-ins-penalty=1.0 ark:- ark:-\n";
34 
35  ParseOptions po(usage);
36 
37  BaseFloat word_ins_penalty = 0.0;
38 
39  po.Register("word-ins-penalty", &word_ins_penalty, "Word insertion penalty");
40 
41  po.Read(argc, argv);
42 
43  if (po.NumArgs() != 2) {
44  po.PrintUsage();
45  exit(1);
46  }
47 
48  std::string lats_rspecifier = po.GetArg(1),
49  lats_wspecifier = po.GetArg(2);
50 
51  SequentialCompactLatticeReader clat_reader(lats_rspecifier);
52  CompactLatticeWriter clat_writer(lats_wspecifier); // write as compact.
53 
54  int64 n_done = 0;
55 
56  for (; !clat_reader.Done(); clat_reader.Next()) {
57  CompactLattice clat(clat_reader.Value());
58  AddWordInsPenToCompactLattice(word_ins_penalty, &clat);
59  clat_writer.Write(clat_reader.Key(), clat);
60  n_done++;
61  }
62  KALDI_LOG << "Done adding word insertion penalty to " << n_done << " lattices.";
63  return (n_done != 0 ? 0 : 1);
64  } catch(const std::exception &e) {
65  std::cerr << e.what();
66  return -1;
67  }
68 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
A templated class for writing objects to an archive or script file; see The Table concept...
Definition: kaldi-table.h:368
float BaseFloat
Definition: kaldi-types.h:29
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Definition: kaldi-table.h:287
void AddWordInsPenToCompactLattice(BaseFloat word_ins_penalty, CompactLattice *clat)
This function add the word insertion penalty to graph score of each word in the compact lattice...
fst::VectorFst< CompactLatticeArc > CompactLattice
Definition: kaldi-lattice.h:46
#define KALDI_LOG
Definition: kaldi-error.h:153