34 while (expected_count > 1.0) {
49 basic_dim = dim - const_feat_dim;
50 KALDI_ASSERT(const_feat_dim < eg->input_frames.NumCols());
54 eg->
spk_info.AddRowSumMat(1.0 / mat.NumRows(),
55 mat.Range(0, mat.NumRows(),
56 basic_dim, const_feat_dim),
65 int main(
int argc,
char *argv[]) {
67 using namespace kaldi;
70 typedef kaldi::int64 int64;
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" 77 "Usage: nnet-copy-egs-discriminative [options] <egs-rspecifier> <egs-wspecifier1> [<egs-wspecifier2> ...]\n" 80 "nnet-copy-egs-discriminative ark:train.degs ark,t:text.degs\n" 82 "nnet-copy-egs-discriminative ark:train.degs ark:1.degs ark:2.degs\n";
87 int32 const_feat_dim = 0;
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.");
113 std::string examples_rspecifier = po.
GetArg(1);
116 examples_rspecifier);
118 int32 num_outputs = po.
NumArgs() - 1;
119 std::vector<DiscriminativeNnetExampleWriter*> example_writers(num_outputs);
120 for (int32
i = 0;
i < num_outputs;
i++)
125 int64 num_read = 0, num_written = 0, num_frames_written = 0;
126 for (; !example_reader.
Done(); example_reader.
Next(), num_read++) {
128 for (int32 c = 0; c <
count; c++) {
129 int32 index = (random ?
Rand() : num_written) % num_outputs;
130 std::ostringstream ostr;
132 if (const_feat_dim == 0) {
133 example_writers[index]->Write(ostr.str(),
134 example_reader.
Value());
138 example_writers[index]->Write(ostr.str(), eg);
141 num_frames_written +=
142 static_cast<int64
>(example_reader.
Value().num_ali.size());
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';
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void AverageConstPart(int32 const_feat_dim, DiscriminativeNnetExample *eg)
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
bool WithProb(BaseFloat prob, struct RandomState *state)
int main(int argc, char *argv[])
void Register(const std::string &name, bool *ptr, const std::string &doc)
TableWriter< KaldiObjectHolder< DiscriminativeNnetExample > > DiscriminativeNnetExampleWriter
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...
Vector< BaseFloat > spk_info
spk_info contains any component of the features that varies slowly or not at all with time (and hence...
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
Matrix< BaseFloat > input_frames
The input data– typically with a number of frames [NumRows()] larger than labels.size(), because it includes features to the left and right as needed for the temporal context of the network.
int Rand(struct RandomState *state)
int NumArgs() const
Number of positional parameters (c.f. argc-1).
This struct is used to store the information we need for discriminative training (MMI or MPE)...
#define KALDI_ASSERT(cond)
SubMatrix< Real > Range(const MatrixIndexT row_offset, const MatrixIndexT num_rows, const MatrixIndexT col_offset, const MatrixIndexT num_cols) const
Return a sub-part of matrix.
int32 GetCount(double expected_count)
Note on how to parse this filename: it contains functions relatied to neural-net training examples...