157 using namespace kaldi;
160 typedef kaldi::int64 int64;
163 "Get frame-by-frame examples of data for nnet3+sequence neural network\n" 164 "training. This involves breaking up utterances into pieces of sizes\n" 165 "determined by the --num-frames option.\n" 167 "Usage: nnet3-discriminative-get-egs [options] <model> <features-rspecifier> " 168 "<denominator-lattice-rspecifier> <numerator-alignment-rspecifier> <egs-wspecifier>\n" 170 "An example [where $feats expands to the actual features]:\n" 171 " nnet3-discriminative-get-egs --left-context=25 --right-context=9 --num-frames=150,100,90 \\\n" 172 " \"$feats\" \"ark,s,cs:gunzip -c lat.1.gz\" scp:ali.scp ark:degs.1.ark\n";
174 bool compress =
true;
175 int32 length_tolerance = 100, online_ivector_period = 1;
177 std::string online_ivector_rspecifier;
186 po.Register(
"compress", &compress,
"If true, write egs in " 187 "compressed format (recommended)");
188 po.Register(
"ivectors", &online_ivector_rspecifier,
"Alias for --online-ivectors " 189 "option, for back compatibility");
190 po.Register(
"online-ivectors", &online_ivector_rspecifier,
"Rspecifier of ivector " 191 "features, as a matrix.");
192 po.Register(
"online-ivector-period", &online_ivector_period,
"Number of frames " 193 "between iVectors in matrices supplied to the --online-ivectors " 195 po.Register(
"length-tolerance", &length_tolerance,
"Tolerance for " 196 "difference in num-frames between feat and ivector matrices");
202 if (po.NumArgs() != 5) {
210 std::string model_wxfilename = po.GetArg(1),
211 feature_rspecifier = po.GetArg(2),
212 den_lat_rspecifier = po.GetArg(3),
213 num_ali_rspecifier = po.GetArg(4),
214 examples_wspecifier = po.GetArg(5);
220 Input ki(model_wxfilename, &binary);
221 tmodel.
Read(ki.Stream(), binary);
229 online_ivector_rspecifier);
233 for (; !feat_reader.Done(); feat_reader.Next()) {
234 std::string key = feat_reader.Key();
236 if (!den_lat_reader.HasKey(key)) {
237 KALDI_WARN <<
"No denominator lattice for key " << key;
239 }
else if (!ali_reader.HasKey(key)) {
240 KALDI_WARN <<
"No numerator alignment for key " << key;
244 if (!supervision.
Initialize(ali_reader.Value(key),
245 den_lat_reader.Value(key),
247 KALDI_WARN <<
"Failed to convert lattice to supervision " 248 <<
"for utterance " << key;
254 if (!online_ivector_rspecifier.empty()) {
255 if (!online_ivector_reader.HasKey(key)) {
256 KALDI_WARN <<
"No iVectors for utterance " << key;
262 online_ivector_feats = &(online_ivector_reader.Value(key));
265 if (online_ivector_feats != NULL &&
267 online_ivector_period)) > length_tolerance
268 || online_ivector_feats->
NumRows() == 0)) {
270 <<
" and iVectors " << online_ivector_feats->
NumRows()
271 <<
"exceeds tolerance " << length_tolerance;
276 feats, online_ivector_feats, online_ivector_period,
277 supervision, key, compress,
278 &utt_splitter, &example_writer))
283 KALDI_WARN << num_err <<
" utterances had errors and could " 286 return utt_splitter.ExitStatus();
287 }
catch(
const std::exception &e) {
288 std::cerr << e.what() <<
'\n';
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void Register(OptionsItf *opts)
A templated class for writing objects to an archive or script file; see The Table concept...
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...
static bool ProcessFile(const discriminative::SplitDiscriminativeSupervisionOptions &config, const TransitionModel &tmodel, const MatrixBase< BaseFloat > &feats, const MatrixBase< BaseFloat > *ivector_feats, int32 ivector_period, const discriminative::DiscriminativeSupervision &supervision, const std::string &utt_id, bool compress, UtteranceSplitter *utt_splitter, NnetDiscriminativeExampleWriter *example_writer)
void Read(std::istream &is, bool binary)
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
void Register(OptionsItf *po)
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
bool Initialize(const std::vector< int32 > &alignment, const Lattice &lat, BaseFloat weight)
void ComputeDerived()
This function decodes 'num_frames_str' into 'num_frames', and ensures that the members of 'num_frames...