72 using namespace kaldi;
77 "Set the priors of the neural net to the computed posterios from the net,\n" 78 "on typical data (e.g. training data). This is correct under more general\n" 79 "circumstances than using the priors of the class labels in the training data\n" 81 "Typical usage of this program will involve computation of an average pdf-level\n" 82 "posterior with nnet-compute or nnet-compute-from-egs, piped into matrix-sum-rows\n" 83 "and then vector-sum, to compute the average posterior\n" 85 "Usage: nnet-adjust-priors [options] <nnet-in> <summed-posterior-vector-in> <nnet-out>\n" 87 " nnet-adjust-priors final.mdl prior.vec final.mdl\n";
89 bool binary_write =
true;
95 po.Register(
"binary", &binary_write,
"Write output in binary mode");
96 po.Register(
"prior-floor", &prior_floor,
"When setting priors, floor for " 97 "priors (only used to avoid generating NaNs upon inversion)");
101 if (po.NumArgs() != 3) {
106 std::string nnet_rxfilename = po.GetArg(1),
107 posterior_vec_rxfilename = po.GetArg(2),
108 nnet_wxfilename = po.GetArg(3);
114 Input ki(nnet_rxfilename, &binary_read);
115 trans_model.
Read(ki.Stream(), binary_read);
116 am_nnet.
Read(ki.Stream(), binary_read);
124 posterior_vec.
Scale(1.0 / posterior_vec.
Sum());
133 Output ko(nnet_wxfilename, binary_write);
134 trans_model.
Write(ko.Stream(), binary_write);
135 am_nnet.
Write(ko.Stream(), binary_write);
137 KALDI_LOG <<
"Modified priors of neural network model and wrote it to " 140 }
catch(
const std::exception &e) {
141 std::cerr << e.what() <<
'\n';
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void Read(std::istream &is, bool binary)
void PrintPriorDiagnostics(const Vector< BaseFloat > &old_priors, const Vector< BaseFloat > &new_priors)
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 Read(std::istream &is, bool binary)
const VectorBase< BaseFloat > & Priors() const
void Write(std::ostream &os, bool binary) const
void Scale(Real alpha)
Multiplies all elements by this constant.
Real Sum() const
Returns sum of the elements.
void Write(std::ostream &os, bool binary) const
A class representing a vector.
#define KALDI_ASSERT(cond)
void SetPriors(const VectorBase< BaseFloat > &priors)