29 using namespace kaldi;
32 typedef kaldi::int64 int64;
35 "Get examples of data for discriminative neural network training;\n" 36 "each one corresponds to part of a file, of variable (and configurable)\n" 39 "Usage: nnet-get-egs-discriminative [options] <model> " 40 "<features-rspecifier> <ali-rspecifier> <den-lat-rspecifier> " 41 "<training-examples-out>\n" 43 "An example [where $feats expands to the actual features]:\n" 44 "nnet-get-egs-discriminative --acoustic-scale=0.1 \\\n" 45 " 1.mdl '$feats' 'ark,s,cs:gunzip -c ali.1.gz|' 'ark,s,cs:gunzip -c lat.1.gz|' ark:1.degs\n";
54 if (po.NumArgs() != 5) {
59 std::string nnet_rxfilename = po.GetArg(1),
60 feature_rspecifier = po.GetArg(2),
61 ali_rspecifier = po.GetArg(3),
62 clat_rspecifier = po.GetArg(4),
63 examples_wspecifier = po.GetArg(5);
70 Input ki(nnet_rxfilename, &binary);
71 trans_model.
Read(ki.Stream(), binary);
72 am_nnet.
Read(ki.Stream(), binary);
85 int32 num_done = 0, num_err = 0;
86 int64 examples_count = 0;
90 for (; !feat_reader.Done(); feat_reader.Next()) {
91 std::string key = feat_reader.Key();
93 if (!ali_reader.HasKey(key)) {
94 KALDI_WARN <<
"No pdf-level posterior for key " << key;
98 const std::vector<int32> &alignment = ali_reader.Value(key);
99 if (!clat_reader.HasKey(key)) {
100 KALDI_WARN <<
"No denominator lattice for key " << key;
106 if (clat.Properties(fst::kTopSorted,
true) == 0) {
114 left_context, right_context, &eg)) {
115 KALDI_WARN <<
"Error converting lattice to example.";
120 std::vector<DiscriminativeNnetExample> egs;
124 KALDI_VLOG(2) <<
"Split lattice " << key <<
" into " 125 << egs.size() <<
" pieces.";
126 for (
size_t i = 0;
i < egs.size();
i++) {
128 std::vector<DiscriminativeNnetExample> excised_egs;
130 &excised_egs, &stats);
131 for (
size_t j = 0;
j < excised_egs.size();
j++) {
132 std::ostringstream os;
133 os << (examples_count++);
134 std::string example_key = os.str();
135 example_writer.Write(example_key, excised_egs[
j]);
141 if (num_done > 0) stats.
Print();
143 KALDI_LOG <<
"Finished generating examples, " 144 <<
"successfully processed " << num_done
145 <<
" feature files, " << num_err <<
" had errors.";
146 return (num_done == 0 ? 1 : 0);
147 }
catch(
const std::exception &e) {
148 std::cerr << e.what() <<
'\n';
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
int32 LeftContext() const
Returns the left-context summed over all the Components...
void SplitDiscriminativeExample(const SplitDiscriminativeExampleConfig &config, const TransitionModel &tmodel, const DiscriminativeNnetExample &eg, std::vector< DiscriminativeNnetExample > *egs_out, SplitExampleStats *stats_out)
Split a "discriminative example" into multiple pieces, splitting where the lattice has "pinch points"...
void ExciseDiscriminativeExample(const SplitDiscriminativeExampleConfig &config, const TransitionModel &tmodel, const DiscriminativeNnetExample &eg, std::vector< DiscriminativeNnetExample > *egs_out, SplitExampleStats *stats_out)
Remove unnecessary frames from discriminative training example.
void Read(std::istream &is, bool binary)
A templated class for writing objects to an archive or script file; see The Table concept...
This struct exists only for diagnostic purposes.
Allows random access to a collection of objects in an archive or script file; see The Table concept...
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
bool LatticeToDiscriminativeExample(const std::vector< int32 > &alignment, const Matrix< BaseFloat > &feats, const CompactLattice &clat, BaseFloat weight, int32 left_context, int32 right_context, DiscriminativeNnetExample *eg)
Converts lattice to discriminative training example.
void Read(std::istream &is, bool binary)
int32 RightContext() const
Returns the right-context summed over all the Components...
Arc::StateId CreateSuperFinal(MutableFst< Arc > *fst)
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
void Register(OptionsItf *opts)
fst::VectorFst< CompactLatticeArc > CompactLattice
This struct is used to store the information we need for discriminative training (MMI or MPE)...
const Nnet & GetNnet() const
Config structure for SplitExample, for splitting discriminative training examples.