sgmm2-est-ebw.cc File Reference
Include dependency graph for sgmm2-est-ebw.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 sgmm2-est-ebw.cc.

References MleAmSgmm2Accs::Check(), count, kaldi::g_num_threads, ParseOptions::GetArg(), KALDI_LOG, ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), MleAmSgmm2Accs::Read(), TransitionModel::Read(), AmSgmm2::Read(), Vector< Real >::Read(), ParseOptions::Register(), EbwAmSgmm2Options::Register(), Output::Stream(), Input::Stream(), kaldi::StringToSgmmUpdateFlags(), kaldi::StringToSgmmWriteFlags(), EbwAmSgmm2Updater::Update(), TransitionModel::Write(), and AmSgmm2::Write().

28  {
29  using namespace kaldi;
30  typedef kaldi::int32 int32;
31  using std::string;
32  try {
33  const char *usage =
34  "Estimate SGMM model parameters discriminatively using Extended\n"
35  "Baum-Welch style of update\n"
36  "Usage: sgmm2-est-ebw [options] <model-in> <num-stats-in> <den-stats-in> <model-out>\n";
37 
38 
39  string update_flags_str = "vMNwcSt";
40  bool binary_write = true;
41  string write_flags_str = "gsnu";
42  EbwAmSgmm2Options opts;
43 
44 
45  ParseOptions po(usage);
46  po.Register("binary", &binary_write, "Write output in binary mode");
47  po.Register("update-flags", &update_flags_str, "Which SGMM parameters to "
48  "update: subset of vMNwcSt.");
49  po.Register("write-flags", &write_flags_str, "Which SGMM parameters to "
50  "write: subset of gsnu");
51  po.Register("num-threads", &g_num_threads, "Number of threads to use in "
52  "weight update and normalizer computation");
53  opts.Register(&po);
54 
55  po.Read(argc, argv);
56  if (po.NumArgs() != 4) {
57  po.PrintUsage();
58  exit(1);
59  }
60  string model_in_filename = po.GetArg(1),
61  num_stats_filename = po.GetArg(2),
62  den_stats_filename = po.GetArg(3),
63  model_out_filename = po.GetArg(4);
64 
65  SgmmUpdateFlagsType update_flags = StringToSgmmUpdateFlags(update_flags_str);
66  SgmmWriteFlagsType write_flags = StringToSgmmWriteFlags(write_flags_str);
67 
68  AmSgmm2 am_sgmm;
69  TransitionModel trans_model;
70  {
71  bool binary;
72  Input ki(model_in_filename, &binary);
73  trans_model.Read(ki.Stream(), binary);
74  am_sgmm.Read(ki.Stream(), binary);
75  }
76 
77  MleAmSgmm2Accs sgmm_num_accs;
78  {
79  bool binary;
80  Vector<double> transition_accs; // won't be used.
81  Input ki(num_stats_filename, &binary);
82  transition_accs.Read(ki.Stream(), binary);
83  sgmm_num_accs.Read(ki.Stream(), binary, false); // false == add; doesn't matter.
84  }
85  MleAmSgmm2Accs sgmm_den_accs;
86  {
87  bool binary;
88  Vector<double> transition_accs; // won't be used.
89  Input ki(den_stats_filename, &binary);
90  transition_accs.Read(ki.Stream(), binary);
91  sgmm_den_accs.Read(ki.Stream(), binary, false); // false == add; doesn't matter.
92  }
93 
94  sgmm_num_accs.Check(am_sgmm, true); // Will check consistency and print some diagnostics.
95  sgmm_den_accs.Check(am_sgmm, true); // Will check consistency and print some diagnostics.
96 
97  { // Update SGMM.
98  BaseFloat auxf_impr, count;
99  kaldi::EbwAmSgmm2Updater sgmm_updater(opts);
100  sgmm_updater.Update(sgmm_num_accs, sgmm_den_accs, &am_sgmm,
101  update_flags, &auxf_impr, &count);
102  KALDI_LOG << "Overall auxf impr/frame from SGMM update is " << (auxf_impr/count)
103  << " over " << count << " frames.";
104  }
105 
106  {
107  Output ko(model_out_filename, binary_write);
108  trans_model.Write(ko.Stream(), binary_write);
109  am_sgmm.Write(ko.Stream(), binary_write, write_flags);
110  }
111 
112  KALDI_LOG << "Wrote model to " << model_out_filename;
113  return 0;
114  } catch(const std::exception &e) {
115  std::cerr << e.what();
116  return -1;
117  }
118 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
uint16 SgmmWriteFlagsType
Bitwise OR of the above flags.
Definition: model-common.h:70
void Write(std::ostream &os, bool binary, SgmmWriteFlagsType write_params) const
Definition: am-sgmm2.cc:203
Class for definition of the subspace Gmm acoustic model.
Definition: am-sgmm2.h:231
This header implements a form of Extended Baum-Welch training for SGMMs.
void Read(std::istream &in_stream, bool binary, bool add)
int32 g_num_threads
Definition: kaldi-thread.cc:25
void Read(std::istream &is, bool binary)
Definition: am-sgmm2.cc:89
kaldi::int32 int32
SgmmUpdateFlagsType StringToSgmmUpdateFlags(std::string str)
Definition: model-common.cc:64
const size_t count
float BaseFloat
Definition: kaldi-types.h:29
uint16 SgmmUpdateFlagsType
Bitwise OR of the above flags.
Definition: model-common.h:59
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
void Read(std::istream &is, bool binary)
void Write(std::ostream &os, bool binary) const
void Register(OptionsItf *opts)
SgmmUpdateFlagsType StringToSgmmWriteFlags(std::string str)
Definition: model-common.cc:86
void Check(const AmSgmm2 &model, bool show_properties=true) const
Checks the various accumulators for correct sizes given a model.
Class for the accumulators associated with the phonetic-subspace model parameters.
#define KALDI_LOG
Definition: kaldi-error.h:153
void Read(std::istream &in, bool binary, bool add=false)
Read function using C++ streams.