nbest-to-linear.cc File Reference
Include dependency graph for nbest-to-linear.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 26 of file nbest-to-linear.cc.

References SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), fst::GetLinearSymbolSequence(), ParseOptions::GetOptArg(), KALDI_LOG, KALDI_WARN, SequentialTableReader< Holder >::Key(), SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), SequentialTableReader< Holder >::Value(), LatticeWeightTpl< FloatType >::Value1(), LatticeWeightTpl< FloatType >::Value2(), and TableWriter< Holder >::Write().

26  {
27  try {
28  using namespace kaldi;
29  typedef kaldi::int32 int32;
30  typedef kaldi::int64 int64;
31  using fst::SymbolTable;
32  using fst::VectorFst;
33  using fst::StdArc;
34 
35  const char *usage =
36  "Takes as input lattices/n-bests which must be linear (single path);\n"
37  "convert from lattice to up to 4 archives containing transcriptions, alignments,\n"
38  "and acoustic and LM costs (note: use ark:/dev/null for unwanted outputs)\n"
39  "Usage: nbest-to-linear [options] <nbest-rspecifier> <alignments-wspecifier> "
40  "[<transcriptions-wspecifier> [<lm-cost-wspecifier> [<ac-cost-wspecifier>]]]\n"
41  " e.g.: lattice-to-nbest --n=10 ark:1.lats ark:- | \\\n"
42  " nbest-to-linear ark:1.lats ark,t:1.ali 'ark,t:|int2sym.pl -f 2- words.txt > text'\n";
43 
44  ParseOptions po(usage);
45 
46  po.Read(argc, argv);
47 
48  if (po.NumArgs() < 2 || po.NumArgs() > 5) {
49  po.PrintUsage();
50  exit(1);
51  }
52 
53  std::string lats_rspecifier = po.GetArg(1),
54  ali_wspecifier = po.GetArg(2),
55  trans_wspecifier = po.GetOptArg(3),
56  lm_cost_wspecifier = po.GetOptArg(4),
57  ac_cost_wspecifier = po.GetOptArg(5);
58 
59  SequentialLatticeReader lattice_reader(lats_rspecifier);
60 
61  Int32VectorWriter ali_writer(ali_wspecifier);
62  Int32VectorWriter trans_writer(trans_wspecifier);
63  BaseFloatWriter lm_cost_writer(lm_cost_wspecifier);
64  BaseFloatWriter ac_cost_writer(ac_cost_wspecifier);
65 
66  int32 n_done = 0, n_err = 0;
67 
68  for (; !lattice_reader.Done(); lattice_reader.Next()) {
69  std::string key = lattice_reader.Key();
70  Lattice lat = lattice_reader.Value();
71 
72  std::vector<int32> ilabels;
73  std::vector<int32> olabels;
74  LatticeWeight weight;
75 
76  if (!GetLinearSymbolSequence(lat, &ilabels, &olabels, &weight)) {
77  KALDI_WARN << "Lattice/nbest for key " << key << " had wrong format: "
78  "note, this program expects input with one path, e.g. from "
79  "lattice-to-nbest.";
80  n_err++;
81  } else {
82  if (ali_wspecifier != "") ali_writer.Write(key, ilabels);
83  if (trans_wspecifier != "") trans_writer.Write(key, olabels);
84  if (lm_cost_wspecifier != "") lm_cost_writer.Write(key, weight.Value1());
85  if (ac_cost_wspecifier!= "") ac_cost_writer.Write(key, weight.Value2());
86  n_done++;
87  }
88  }
89  KALDI_LOG << "Done " << n_done << " n-best entries, "
90  << n_err << " had errors.";
91  return (n_done != 0 ? 0 : 1);
92  } catch(const std::exception &e) {
93  std::cerr << e.what();
94  return -1;
95  }
96 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
fst::StdArc StdArc
A templated class for writing objects to an archive or script file; see The Table concept...
Definition: kaldi-table.h:368
kaldi::int32 int32
bool GetLinearSymbolSequence(const Fst< Arc > &fst, std::vector< I > *isymbols_out, std::vector< I > *osymbols_out, typename Arc::Weight *tot_weight_out)
GetLinearSymbolSequence gets the symbol sequence from a linear FST.
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
fst::VectorFst< LatticeArc > Lattice
Definition: kaldi-lattice.h:44
#define KALDI_WARN
Definition: kaldi-error.h:150
#define KALDI_LOG
Definition: kaldi-error.h:153