lattice-equivalent.cc File Reference
Include dependency graph for lattice-equivalent.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 lattice-equivalent.cc.

References SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), RandomAccessTableReader< Holder >::HasKey(), KALDI_ASSERT, KALDI_LOG, KALDI_WARN, SequentialTableReader< Holder >::Key(), SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), ParseOptions::PrintUsage(), kaldi::Rand(), ParseOptions::Read(), ParseOptions::Register(), RandomAccessTableReader< Holder >::Value(), and SequentialTableReader< Holder >::Value().

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  "Test whether sets of lattices are equivalent (return with status 0 if\n"
37  "all were equivalent, 1 otherwise, -1 on error)\n"
38  "Usage: lattice-equivalent [options] lattice-rspecifier1 lattice-rspecifier2\n"
39  " e.g.: lattice-equivalent ark:1.lats ark:2.lats\n";
40 
41  ParseOptions po(usage);
42  BaseFloat delta = 0.1; // Use a relatively high delta as for long paths, the absolute
43  // scores can be quite large.
44  int32 num_paths = 20;
45  BaseFloat max_error_proportion = 0.0;
46  po.Register("delta", &delta,
47  "Delta parameter for equivalence test");
48  po.Register("num-paths", &num_paths,
49  "Number of paths per lattice for testing randomized equivalence");
50  po.Register("max-error-proportion", &max_error_proportion,
51  "Maximum proportion of missing 2nd lattices, or inequivalent "
52  "lattices, we allow before returning nonzero status");
53 
54  po.Read(argc, argv);
55 
56  if (po.NumArgs() != 2) {
57  po.PrintUsage();
58  exit(1);
59  }
60 
61  KALDI_ASSERT(max_error_proportion >= 0.0 && max_error_proportion <= 1.0);
62 
63  std::string lats_rspecifier1 = po.GetArg(1),
64  lats_rspecifier2 = po.GetArg(2);
65 
66  // Read as regular lattice-- this is more efficient for testing
67  // equivalence, I tihnk.
68  SequentialLatticeReader lattice_reader1(lats_rspecifier1);
69 
70  RandomAccessLatticeReader lattice_reader2(lats_rspecifier2);
71 
72 
73  int32 n_equivalent = 0, n_inequivalent = 0, n_no2nd = 0;
74 
75  for (; !lattice_reader1.Done(); lattice_reader1.Next()) {
76  std::string key = lattice_reader1.Key();
77  const Lattice &lat1 = lattice_reader1.Value();
78  if (!lattice_reader2.HasKey(key)) {
79  KALDI_WARN << "No 2nd lattice present for utterance " << key;
80  n_no2nd++;
81  continue;
82  }
83  const Lattice &lat2 = lattice_reader2.Value(key);
84  if (fst::RandEquivalent(lat1, lat2, num_paths, delta, Rand())) {
85  n_equivalent++;
86  KALDI_LOG << "Lattices were equivalent for utterance " << key;
87  } else {
88  n_inequivalent++;
89  KALDI_LOG << "Lattices were inequivalent for utterance " << key;
90  }
91  }
92  KALDI_LOG << "Done " << (n_equivalent + n_inequivalent) << " lattices, "
93  << n_equivalent << " were equivalent, " << n_inequivalent
94  << " were not; for " << n_no2nd << ", could not find 2nd lattice.";
95 
96  int32 num_inputs = n_equivalent + n_inequivalent + n_no2nd;
97  int32 max_bad = max_error_proportion * num_inputs;
98 
99  if (n_no2nd > max_bad) return -1; // treat this as error.
100  else return (n_inequivalent > max_bad ? 1 : 0);
101  } catch(const std::exception &e) {
102  std::cerr << e.what();
103  return -1;
104  }
105 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
fst::StdArc StdArc
kaldi::int32 int32
Allows random access to a collection of objects in an archive or script file; see The Table concept...
Definition: kaldi-table.h:233
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
fst::VectorFst< LatticeArc > Lattice
Definition: kaldi-lattice.h:44
#define KALDI_WARN
Definition: kaldi-error.h:150
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
#define KALDI_LOG
Definition: kaldi-error.h:153