lattice-depth.cc File Reference
Include dependency graph for lattice-depth.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 28 of file lattice-depth.cc.

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

28  {
29  try {
30  using namespace kaldi;
31  typedef kaldi::int32 int32;
32  typedef kaldi::int64 int64;
33 
34  using fst::VectorFst;
35  using fst::StdArc;
36  typedef StdArc::StateId StateId;
37 
38  const char *usage =
39  "Compute the lattice depths in terms of the average number of arcs that\n"
40  "cross a frame. See also lattice-depth-per-frame\n"
41  "Usage: lattice-depth <lattice-rspecifier> [<depth-wspecifier>]\n"
42  "E.g.: lattice-depth ark:- ark,t:-\n";
43 
44  ParseOptions po(usage);
45 
46  po.Read(argc, argv);
47 
48  if (po.NumArgs() < 1 || po.NumArgs() > 2) {
49  po.PrintUsage();
50  exit(1);
51  }
52 
53  std::string lats_rspecifier = po.GetArg(1);
54  SequentialCompactLatticeReader clat_reader(lats_rspecifier);
55 
56  std::string depth_wspecifier = po.GetOptArg(2);
57  BaseFloatWriter lats_depth_writer(depth_wspecifier);
58 
59  int64 num_done = 0;
60  double sum_depth = 0.0, total_t = 0.0;
61  for (; !clat_reader.Done(); clat_reader.Next()) {
62  CompactLattice clat = clat_reader.Value();
63  std::string key = clat_reader.Key();
64 
66 
67  int32 t;
68  BaseFloat depth = CompactLatticeDepth(clat, &t);
69 
70  if (depth_wspecifier != "")
71  lats_depth_writer.Write(key, depth);
72 
73  sum_depth += depth * t;
74  total_t += t;
75  num_done++;
76  }
77  KALDI_LOG << "Done " << num_done << " lattices.";
78  // Warning: the script egs/s5/*/steps/oracle_wer.sh parses the next line.
79  KALDI_LOG << "Overall density is " << (sum_depth / total_t) << " over "
80  << total_t << " frames.";
81  if (num_done != 0) return 0;
82  else return 1;
83  } catch (const std::exception &e) {
84  std::cerr << e.what();
85  return -1;
86  }
87 }
fst::StdArc::StateId StateId
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
Lattice::StateId StateId
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
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
BaseFloat CompactLatticeDepth(const CompactLattice &clat, int32 *num_frames)
Returns the depth of the lattice, defined as the average number of arcs crossing any given frame...
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Definition: kaldi-table.h:287
fst::VectorFst< CompactLatticeArc > CompactLattice
Definition: kaldi-lattice.h:46
void TopSortCompactLatticeIfNeeded(CompactLattice *clat)
Topologically sort the compact lattice if not already topologically sorted.
#define KALDI_LOG
Definition: kaldi-error.h:153