nnet-copy-egs-discriminative.cc File Reference
Include dependency graph for nnet-copy-egs-discriminative.cc:

Go to the source code of this file.

Namespaces

 kaldi
 This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for mispronunciations detection tasks, the reference:
 
 kaldi::nnet2
 

Functions

int32 GetCount (double expected_count)
 
void AverageConstPart (int32 const_feat_dim, DiscriminativeNnetExample *eg)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 65 of file nnet-copy-egs-discriminative.cc.

References kaldi::nnet2::AverageConstPart(), count, SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), kaldi::nnet2::GetCount(), rnnlm::i, KALDI_LOG, SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), ParseOptions::PrintUsage(), kaldi::Rand(), ParseOptions::Read(), ParseOptions::Register(), and SequentialTableReader< Holder >::Value().

65  {
66  try {
67  using namespace kaldi;
68  using namespace kaldi::nnet2;
69  typedef kaldi::int32 int32;
70  typedef kaldi::int64 int64;
71 
72  const char *usage =
73  "Copy examples for discriminative neural\n"
74  "network training. Supports multiple wspecifiers, in\n"
75  "which case it will write the examples round-robin to the outputs.\n"
76  "\n"
77  "Usage: nnet-copy-egs-discriminative [options] <egs-rspecifier> <egs-wspecifier1> [<egs-wspecifier2> ...]\n"
78  "\n"
79  "e.g.\n"
80  "nnet-copy-egs-discriminative ark:train.degs ark,t:text.degs\n"
81  "or:\n"
82  "nnet-copy-egs-discriminative ark:train.degs ark:1.degs ark:2.degs\n";
83 
84  bool random = false;
85  int32 srand_seed = 0;
86  BaseFloat keep_proportion = 1.0;
87  int32 const_feat_dim = 0;
88 
89  ParseOptions po(usage);
90  po.Register("random", &random, "If true, will write frames to output "
91  "archives randomly, not round-robin.");
92  po.Register("keep-proportion", &keep_proportion, "If <1.0, this program will "
93  "randomly keep this proportion of the input samples. If >1.0, it will "
94  "in expectation copy a sample this many times. It will copy it a number "
95  "of times equal to floor(keep-proportion) or ceil(keep-proportion).");
96  po.Register("srand", &srand_seed, "Seed for random number generator "
97  "(only relevant if --random=true or --keep-proportion != 1.0)");
98  po.Register("const-feat-dim", &const_feat_dim,
99  "Dimension of part of features (last dims) which varies little "
100  "or not at all with time, and which should be stored as a single "
101  "vector for each example rather than in the feature matrix."
102  "Useful in systems that use iVectors. Helpful to save space.");
103 
104  po.Read(argc, argv);
105 
106  srand(srand_seed);
107 
108  if (po.NumArgs() < 2) {
109  po.PrintUsage();
110  exit(1);
111  }
112 
113  std::string examples_rspecifier = po.GetArg(1);
114 
116  examples_rspecifier);
117 
118  int32 num_outputs = po.NumArgs() - 1;
119  std::vector<DiscriminativeNnetExampleWriter*> example_writers(num_outputs);
120  for (int32 i = 0; i < num_outputs; i++)
121  example_writers[i] = new DiscriminativeNnetExampleWriter(
122  po.GetArg(i+2));
123 
124 
125  int64 num_read = 0, num_written = 0, num_frames_written = 0;
126  for (; !example_reader.Done(); example_reader.Next(), num_read++) {
127  int32 count = GetCount(keep_proportion);
128  for (int32 c = 0; c < count; c++) {
129  int32 index = (random ? Rand() : num_written) % num_outputs;
130  std::ostringstream ostr;
131  ostr << num_written;
132  if (const_feat_dim == 0) {
133  example_writers[index]->Write(ostr.str(),
134  example_reader.Value());
135  } else {
136  DiscriminativeNnetExample eg = example_reader.Value();
137  AverageConstPart(const_feat_dim, &eg);
138  example_writers[index]->Write(ostr.str(), eg);
139  }
140  num_written++;
141  num_frames_written +=
142  static_cast<int64>(example_reader.Value().num_ali.size());
143  }
144  }
145 
146  for (int32 i = 0; i < num_outputs; i++)
147  delete example_writers[i];
148  KALDI_LOG << "Read " << num_read << " discriminative neural-network training"
149  << " examples, wrote " << num_written << ", consisting of "
150  << num_frames_written << " frames.";
151  return (num_written == 0 ? 1 : 0);
152  } catch(const std::exception &e) {
153  std::cerr << e.what() << '\n';
154  return -1;
155  }
156 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
void AverageConstPart(int32 const_feat_dim, DiscriminativeNnetExample *eg)
kaldi::int32 int32
TableWriter< KaldiObjectHolder< DiscriminativeNnetExample > > DiscriminativeNnetExampleWriter
Definition: nnet-example.h:181
const size_t count
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
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Definition: kaldi-table.h:287
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
This struct is used to store the information we need for discriminative training (MMI or MPE)...
Definition: nnet-example.h:136
#define KALDI_LOG
Definition: kaldi-error.h:153
int32 GetCount(double expected_count)