29 using namespace kaldi;
32 typedef kaldi::int64 int64;
35 "Train the neural network parameters with a discriminative objective\n" 36 "function (MMI, SMBR or MPFE). This uses training examples prepared with\n" 37 "nnet-get-egs-discriminative\n" 39 "Usage: nnet-train-discriminative-simple [options] <model-in> <training-examples-in> <model-out>\n" 41 "nnet-train-discriminative-simple 1.nnet ark:1.degs 2.nnet\n";
43 bool binary_write =
true;
44 std::string use_gpu =
"yes";
48 po.Register(
"binary", &binary_write,
"Write output in binary mode");
49 po.Register(
"use-gpu", &use_gpu,
50 "yes|no|optional|wait, only has effect if compiled with CUDA");
55 if (po.NumArgs() != 3) {
61 CuDevice::Instantiate().SelectGpuId(use_gpu);
64 std::string nnet_rxfilename = po.GetArg(1),
65 examples_rspecifier = po.GetArg(2),
66 nnet_wxfilename = po.GetArg(3);
68 int64 num_examples = 0;
75 Input ki(nnet_rxfilename, &binary_read);
76 trans_model.
Read(ki.Stream(), binary_read);
77 am_nnet.
Read(ki.Stream(), binary_read);
84 for (; !example_reader.Done(); example_reader.Next(), num_examples++) {
86 example_reader.Value(),
88 if (num_examples % 10 == 0 && num_examples != 0) {
98 Output ko(nnet_wxfilename, binary_write);
99 trans_model.
Write(ko.Stream(), binary_write);
100 am_nnet.
Write(ko.Stream(), binary_write);
104 CuDevice::Instantiate().PrintProfile();
106 KALDI_LOG <<
"Finished training, processed " << num_examples
107 <<
" training examples. Wrote model to " 109 return (num_examples == 0 ? 1 : 0);
110 }
catch(
const std::exception &e) {
111 std::cerr << e.what() <<
'\n';
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
int32 GetVerboseLevel()
Get verbosity level, usually set via command line '–verbose=' switch.
void Read(std::istream &is, bool binary)
void Register(OptionsItf *opts)
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
void Read(std::istream &is, bool binary)
void Write(std::ostream &os, bool binary) const
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
void Print(std::string criterion)
void Write(std::ostream &os, bool binary) const
const Nnet & GetNnet() const
void NnetDiscriminativeUpdate(const AmNnet &am_nnet, const TransitionModel &tmodel, const NnetDiscriminativeUpdateOptions &opts, const DiscriminativeNnetExample &eg, Nnet *nnet_to_update, NnetDiscriminativeStats *stats)
Does the neural net computation, lattice forward-backward, and backprop, for either the MMI...