nnet3-discriminative-merge-egs.cc
Go to the documentation of this file.
1 // nnet3bin/nnet3-discriminative-merge-egs.cc
2 
3 // Copyright 2012-2015 Johns Hopkins University (author: Daniel Povey)
4 // 2014-2015 Vimal Manohar
5 
6 // See ../../COPYING for clarification regarding multiple authors
7 //
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 //
12 // http://www.apache.org/licenses/LICENSE-2.0
13 //
14 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
16 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
17 // MERCHANTABLITY OR NON-INFRINGEMENT.
18 // See the Apache 2 License for the specific language governing permissions and
19 // limitations under the License.
20 
21 #include "base/kaldi-common.h"
22 #include "util/common-utils.h"
23 #include "hmm/transition-model.h"
25 
26 
27 int main(int argc, char *argv[]) {
28  try {
29  using namespace kaldi;
30  using namespace kaldi::nnet3;
31  typedef kaldi::int32 int32;
32  typedef kaldi::int64 int64;
33 
34  const char *usage =
35  "This copies nnet3 discriminative training examples from input to output, merging them\n"
36  "into composite examples. The --minibatch-size option controls how many egs\n"
37  "are merged into a single output eg.\n"
38  "\n"
39  "Usage: nnet3-discriminative-egs [options] <egs-rspecifier> <egs-wspecifier>\n"
40  "e.g.\n"
41  "nnet3-discriminative-merge-egs --minibatch-size=128 ark:1.degs ark:- | nnet3-discriminative-train ... \n"
42  "See also nnet3-discriminative-copy-egs\n";
43 
44  ExampleMergingConfig merging_config("64"); // 64 is default minibatch size.
45 
46  ParseOptions po(usage);
47  merging_config.Register(&po);
48 
49  po.Read(argc, argv);
50 
51  if (po.NumArgs() != 2) {
52  po.PrintUsage();
53  exit(1);
54  }
55 
56  std::string examples_rspecifier = po.GetArg(1),
57  examples_wspecifier = po.GetArg(2);
58 
59  SequentialNnetDiscriminativeExampleReader example_reader(examples_rspecifier);
60  NnetDiscriminativeExampleWriter example_writer(examples_wspecifier);
61 
62  merging_config.ComputeDerived();
63  DiscriminativeExampleMerger merger(merging_config, &example_writer);
64  for (; !example_reader.Done(); example_reader.Next()) {
65  const NnetDiscriminativeExample &cur_eg = example_reader.Value();
66  merger.AcceptExample(new NnetDiscriminativeExample(cur_eg));
67  }
68  // the merger itself prints the necessary diagnostics.
69  merger.Finish();
70  return merger.ExitStatus();
71  } catch(const std::exception &e) {
72  std::cerr << e.what() << '\n';
73  return -1;
74  }
75 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
void AcceptExample(NnetDiscriminativeExample *a)
This class is responsible for arranging examples in groups that have the same strucure (i...
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
int main(int argc, char *argv[])
A templated class for writing objects to an archive or script file; see The Table concept...
Definition: kaldi-table.h:368
kaldi::int32 int32
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 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.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
NnetDiscriminativeExample is like NnetExample, but specialized for sequence training.