25 int main(
int argc,
char *argv[]) {
27 using namespace kaldi;
30 typedef kaldi::int64 int64;
33 "Compares two archives of discriminative training examples and checks\n" 34 "that they behave the same way for purposes of discriminative training.\n" 35 "This program was created as a way of testing nnet-get-egs-discriminative\n" 36 "The model is only needed for its transition-model.\n" 38 "Usage: nnet-compare-hash-discriminative [options] <model-rxfilename> " 39 "<egs-rspecifier1> <egs-rspecifier2>\n" 41 "Note: options --drop-frames and --criterion should be matched with the\n" 42 "command line of nnet-get-egs-discriminative used to get the examples\n" 43 "nnet-compare-hash-discriminative --drop-frames=true --criterion=mmi ark:1.degs ark:2.degs\n";
45 std::string criterion =
"smbr";
46 bool drop_frames =
false;
47 bool one_silence_class =
false;
49 BaseFloat acoustic_scale = 1.0, lm_scale = 1.0;
52 po.
Register(
"acoustic-scale", &acoustic_scale,
53 "Scaling factor for acoustic likelihoods");
55 "Scaling factor for \"graph costs\" (including LM costs)");
56 po.
Register(
"criterion", &criterion,
"Training criterion, 'mmi'|'mpfe'|'smbr'");
57 po.
Register(
"drop-frames", &drop_frames,
"If true, for MMI training, drop " 58 "frames where num and den do not intersect.");
59 po.
Register(
"one-silence-class", &one_silence_class,
"If true, newer " 60 "behavior which will tend to reduce insertions.");
61 po.
Register(
"threshold", &threshold,
"Threshold for equality testing " 72 std::string model_rxfilename = po.
GetArg(1),
73 examples_rspecifier1 = po.
GetArg(2),
74 examples_rspecifier2 = po.
GetArg(3);
76 int64 num_done1 = 0, num_done2 = 0;
85 double num_weight1 = 0.0, den_weight1 = 0.0, tot_t1 = 0.0;
86 double num_weight2 = 0.0, den_weight2 = 0.0, tot_t2 = 0.0;
89 example_reader1(examples_rspecifier1),
90 example_reader2(examples_rspecifier2);
92 KALDI_LOG <<
"Computing first hash function";
93 for (; !example_reader1.Done(); example_reader1.Next(), num_done1++) {
98 one_silence_class, &hash1,
99 &num_weight1, &den_weight1, &tot_t1);
101 KALDI_LOG <<
"Processed " << num_done1 <<
" examples.";
103 KALDI_LOG <<
"Computing second hash function";
104 for (; !example_reader2.
Done(); example_reader2.
Next(), num_done2++) {
108 UpdateHash(tmodel, eg, criterion, drop_frames,
109 one_silence_class, &hash2,
110 &num_weight2, &den_weight2, &tot_t2);
112 KALDI_LOG <<
"Processed " << num_done2 <<
" examples.";
118 KALDI_LOG <<
"Products are as follows (should be the same): prod1 = " 119 << prod1 <<
", prod2 = " << prod2 <<
", cross_prod = " 122 KALDI_LOG <<
"Num-weight1 = " << num_weight1 <<
", den-weight1 = " 123 << den_weight1 <<
", tot_t1 = " << tot_t1;
124 KALDI_LOG <<
"Num-weight2 = " << num_weight2 <<
", den-weight2 = " 125 << den_weight2 <<
", tot_t2 = " << tot_t2;
132 }
catch(
const std::exception &e) {
133 std::cerr << e.what() <<
'\n';
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[])
void UpdateHash(const TransitionModel &tmodel, const DiscriminativeNnetExample &eg, std::string criterion, bool drop_frames, bool one_silence_class, Matrix< double > *hash, double *num_weight, double *den_weight, double *tot_t)
This function is used in code that tests the functionality that we provide here, about splitting and ...
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...
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
std::vector< std::vector< double > > LatticeScale(double lmwt, double acwt)
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
CompactLattice den_lat
The denominator lattice.
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
Real TraceMatMat(const MatrixBase< Real > &A, const MatrixBase< Real > &B, MatrixTransposeType trans)
We need to declare this here as it will be a friend function.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
This struct is used to store the information we need for discriminative training (MMI or MPE)...
#define KALDI_ASSERT(cond)
Note on how to parse this filename: it contains functions relatied to neural-net training examples...
static bool ApproxEqual(float a, float b, float relative_tolerance=0.001)
return abs(a - b) <= relative_tolerance * (abs(a)+abs(b)).