112     using namespace kaldi;
   115     typedef kaldi::int64 int64;
   118         "Get frame-by-frame examples of data for neural network training.\n"   119         "Essentially this is a format change from features and posteriors\n"   120         "into a special frame-by-frame format.  To split randomly into\n"   121         "different subsets, do nnet-copy-egs with --random=true, but\n"   122         "note that this does not randomize the order of frames.\n"   124         "Usage:  nnet-get-weighted-egs [options] <features-rspecifier> "   125         "<pdf-post-rspecifier> <weights-rspecifier> <training-examples-out>\n"   127         "An example [where $feats expands to the actual features]:\n"   128         "nnet-get-weighted-egs --left-context=8 --right-context=8 \"$feats\" \\\n"   129         "  \"ark:gunzip -c exp/nnet/ali.1.gz | ali-to-pdf exp/nnet/1.nnet ark:- ark:- | ali-to-post ark:- ark:- |\" \\\n"   131         "Note: the --left-context and --right-context would be derived from\n"   132         "the output of nnet-info.";
   135     int32 left_context = 0, right_context = 0, const_feat_dim = 0;
   136     int32 srand_seed = 0;
   139     bool use_frame_selection = 
true, use_frame_weights=
false;
   142     po.Register(
"left-context", &left_context, 
"Number of frames of left context "   143                 "the neural net requires.");
   144     po.Register(
"right-context", &right_context, 
"Number of frames of right context "   145                 "the neural net requires.");
   146     po.Register(
"const-feat-dim", &const_feat_dim, 
"If specified, the last "   147                 "const-feat-dim dimensions of the feature input are treated as "   148                 "constant over the context window (so are not spliced)");
   149     po.Register(
"keep-proportion", &keep_proportion, 
"If <1.0, this program will "   150                 "randomly keep this proportion of the input samples.  If >1.0, it will "   151                 "in expectation copy a sample this many times.  It will copy it a number "   152                 "of times equal to floor(keep-proportion) or ceil(keep-proportion).");
   153     po.Register(
"srand", &srand_seed, 
"Seed for random number generator "   154                 "(only relevant if --keep-proportion != 1.0)");
   155     po.Register(
"weight-threshold", &weight_threshold, 
"Keep only frames with weights "   156                 "above this threshold.");
   157     po.Register(
"use-frame-selection", &use_frame_selection, 
"Remove the frames below threshold.");
   158     po.Register(
"use-frame-weights", &use_frame_weights, 
"Scale the error derivatives by the weight");
   164     if (po.NumArgs() != 4) {
   169     std::string feature_rspecifier = po.GetArg(1),
   170         pdf_post_rspecifier = po.GetArg(2),
   171         weights_rspecifier = po.GetArg(3),
   172         examples_wspecifier = po.GetArg(4);
   180     int32 num_done = 0, num_err = 0;
   181     int64 num_frames_written = 0;
   182     int64 num_frames_skipped = 0;
   184     for (; !feat_reader.Done(); feat_reader.Next()) {
   185       std::string key = feat_reader.Key();
   187       if (!pdf_post_reader.HasKey(key)) {
   188         KALDI_WARN << 
"No pdf-level posterior for key " << key;
   191         const Posterior &pdf_post = pdf_post_reader.Value(key);
   192         if (pdf_post.size() != feats.
NumRows()) {
   193           KALDI_WARN << 
"Posterior has wrong size " << pdf_post.size()
   194                      << 
" versus " << feats.
NumRows();
   198         if (!weights_reader.HasKey(key)) {
   199           KALDI_ERR << 
"No weights for utterance " << key;
   206           if (weights.
Dim() != 
static_cast<int32
>(pdf_post.size())) {
   208               << 
" have wrong size, " << weights.
Dim()
   209               << 
" vs. " << pdf_post.size();
   213           ProcessFile(feats, pdf_post, key, weights, left_context, right_context,
   214                       const_feat_dim, keep_proportion, weight_threshold,
   215                       use_frame_selection, use_frame_weights,
   216                       &num_frames_written, &num_frames_skipped, &example_writer);
   222     KALDI_LOG << 
"Finished generating examples, "   223               << 
"successfully processed " << num_done
   224               << 
" feature files, wrote " << num_frames_written << 
" examples, "   225               << 
"skipped " << num_frames_skipped << 
" examples, "   226               << num_err << 
" files had errors.";
   227     return (num_done == 0 ? 1 : 0);
   228   } 
catch(
const std::exception &e) {
   229     std::cerr << e.what() << 
'\n';
 This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
 
A templated class for writing objects to an archive or script file; see The Table concept...
 
Allows random access to a collection of objects in an archive or script file; see The Table concept...
 
std::vector< std::vector< std::pair< int32, BaseFloat > > > Posterior
Posterior is a typedef for storing acoustic-state (actually, transition-id) posteriors over an uttera...
 
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
 
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
 
MatrixIndexT Dim() const
Returns the dimension of the vector. 
 
A class representing a vector. 
 
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix). 
 
static void ProcessFile(const MatrixBase< BaseFloat > &feats, const Posterior &pdf_post, const std::string &utt_id, int32 left_context, int32 right_context, int32 num_frames, int32 const_feat_dim, int64 *num_frames_written, int64 *num_egs_written, NnetExampleWriter *example_writer)