gmm-boost-silence.cc File Reference
Include dependency graph for gmm-boost-silence.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 25 of file gmm-boost-silence.cc.

References DiagGmm::ComputeGconsts(), ParseOptions::GetArg(), AmDiagGmm::GetPdf(), kaldi::GetPdfsForPhones(), rnnlm::i, kaldi::IsSortedAndUniq(), KALDI_ASSERT, KALDI_LOG, KALDI_WARN, ParseOptions::NumArgs(), ParseOptions::PrintUsage(), AmDiagGmm::Read(), ParseOptions::Read(), TransitionModel::Read(), ParseOptions::Register(), VectorBase< Real >::Scale(), DiagGmm::SetWeights(), kaldi::SplitStringToIntegers(), Output::Stream(), Input::Stream(), DiagGmm::weights(), AmDiagGmm::Write(), and TransitionModel::Write().

25  {
26  try {
27  using namespace kaldi;
28  typedef kaldi::int32 int32;
29 
30  const char *usage =
31  "Modify GMM-based model to boost (by a certain factor) all\n"
32  "probabilities associated with the specified phones (could be\n"
33  "all silence phones, or just the ones used for optional silence).\n"
34  "Note: this is done by modifying the GMM weights. If the silence\n"
35  "model shares a GMM with other models, then it will modify the GMM\n"
36  "weights for all models that may correspond to silence.\n"
37  "\n"
38  "Usage: gmm-boost-silence [options] <silence-phones-list> <model-in> <model-out>\n"
39  "e.g.: gmm-boost-silence --boost=1.5 1:2:3 1.mdl 1_boostsil.mdl\n";
40 
41  bool binary_write = true;
42  BaseFloat boost = 1.5;
43 
44  ParseOptions po(usage);
45  po.Register("binary", &binary_write, "Write output in binary mode");
46  po.Register("boost", &boost, "Factor by which to boost silence probs");
47 
48  po.Read(argc, argv);
49 
50  if (po.NumArgs() != 3) {
51  po.PrintUsage();
52  exit(1);
53  }
54 
55  std::string
56  silence_phones_string = po.GetArg(1),
57  model_rxfilename = po.GetArg(2),
58  model_wxfilename = po.GetArg(3);
59 
60  std::vector<int32> silence_phones;
61  if (silence_phones_string != "") {
62  SplitStringToIntegers(silence_phones_string, ":", false, &silence_phones);
63  std::sort(silence_phones.begin(), silence_phones.end());
64  KALDI_ASSERT(IsSortedAndUniq(silence_phones) && "Silence phones non-unique.");
65  } else {
66  KALDI_WARN << "gmm-boost-silence: no silence phones specified, doing nothing.";
67  }
68 
69  AmDiagGmm am_gmm;
70  TransitionModel trans_model;
71  {
72  bool binary_read;
73  Input ki(model_rxfilename, &binary_read);
74  trans_model.Read(ki.Stream(), binary_read);
75  am_gmm.Read(ki.Stream(), binary_read);
76  }
77 
78  { // Do the modification to the am_gmm object.
79  std::vector<int32> pdfs;
80  bool ans = GetPdfsForPhones(trans_model, silence_phones, &pdfs);
81  if (!ans) {
82  KALDI_WARN << "The pdfs for the silence phones may be shared by other phones "
83  << "(note: this probably does not matter.)";
84  }
85  for (size_t i = 0; i < pdfs.size(); i++) {
86  int32 pdf = pdfs[i];
87  DiagGmm &gmm = am_gmm.GetPdf(pdf);
88  Vector<BaseFloat> weights(gmm.weights());
89  weights.Scale(boost);
90  gmm.SetWeights(weights);
91  gmm.ComputeGconsts();
92  }
93  KALDI_LOG << "Boosted weights for " << pdfs.size()
94  << " pdfs, by factor of " << boost;
95  }
96 
97  {
98  Output ko(model_wxfilename, binary_write);
99  trans_model.Write(ko.Stream(), binary_write);
100  am_gmm.Write(ko.Stream(), binary_write);
101  }
102 
103  KALDI_LOG << "Wrote model to " << model_wxfilename;
104  } catch(const std::exception &e) {
105  std::cerr << e.what() << '\n';
106  return -1;
107  }
108 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
bool SplitStringToIntegers(const std::string &full, const char *delim, bool omit_empty_strings, std::vector< I > *out)
Split a string (e.g.
Definition: text-utils.h:68
int32 ComputeGconsts()
Sets the gconsts.
Definition: diag-gmm.cc:114
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
void Read(std::istream &is, bool binary)
#define KALDI_WARN
Definition: kaldi-error.h:150
const Vector< BaseFloat > & weights() const
Definition: diag-gmm.h:178
void Scale(Real alpha)
Multiplies all elements by this constant.
DiagGmm & GetPdf(int32 pdf_index)
Accessors.
Definition: am-diag-gmm.h:119
void Write(std::ostream &os, bool binary) const
A class representing a vector.
Definition: kaldi-vector.h:406
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
void Write(std::ostream &out_stream, bool binary) const
Definition: am-diag-gmm.cc:163
Definition for Gaussian Mixture Model with diagonal covariances.
Definition: diag-gmm.h:42
void SetWeights(const VectorBase< Real > &w)
Mutators for both float or double.
Definition: diag-gmm-inl.h:28
bool GetPdfsForPhones(const TransitionModel &trans_model, const std::vector< int32 > &phones, std::vector< int32 > *pdfs)
Works out which pdfs might correspond to the given phones.
bool IsSortedAndUniq(const std::vector< T > &vec)
Returns true if the vector is sorted and contains each element only once.
Definition: stl-utils.h:63
#define KALDI_LOG
Definition: kaldi-error.h:153
void Read(std::istream &in_stream, bool binary)
Definition: am-diag-gmm.cc:147