37 using namespace kaldi;
40 using fst::SymbolTable;
45 "Align features given nnet3 neural net model\n" 46 "Usage: nnet3-align-compiled [options] <nnet-in> <graphs-rspecifier> " 47 "<features-rspecifier> <alignments-wspecifier>\n" 49 " nnet3-align-compiled 1.mdl ark:graphs.fsts scp:train.scp ark:1.ali\n" 51 " compile-train-graphs tree 1.mdl lex.fst 'ark:sym2int.pl -f 2- words.txt text|' \\\n" 52 " ark:- | nnet3-align-compiled 1.mdl ark:- scp:train.scp t, ark:1.ali\n";
57 std::string use_gpu =
"yes";
60 std::string per_frame_acwt_wspecifier;
62 std::string ivector_rspecifier,
63 online_ivector_rspecifier,
65 int32 online_ivector_period = 0;
69 po.Register(
"use-gpu", &use_gpu,
70 "yes|no|optional|wait, only has effect if compiled with CUDA");
71 po.Register(
"transition-scale", &transition_scale,
72 "Transition-probability scale [relative to acoustics]");
73 po.Register(
"self-loop-scale", &self_loop_scale,
74 "Scale of self-loop versus non-self-loop " 75 "log probs [relative to acoustics]");
76 po.Register(
"write-per-frame-acoustic-loglikes", &per_frame_acwt_wspecifier,
77 "Wspecifier for table of vectors containing the acoustic log-likelihoods " 78 "per frame for each utterance. E.g. ark:foo/per_frame_logprobs.1.ark");
79 po.Register(
"ivectors", &ivector_rspecifier,
"Rspecifier for " 80 "iVectors as vectors (i.e. not estimated online); per utterance " 81 "by default, or per speaker if you provide the --utt2spk option.");
82 po.Register(
"online-ivectors", &online_ivector_rspecifier,
"Rspecifier for " 83 "iVectors estimated online, as matrices. If you supply this," 84 " you must set the --online-ivector-period option.");
85 po.Register(
"online-ivector-period", &online_ivector_period,
"Number of frames " 86 "between iVectors in matrices supplied to the --online-ivectors " 90 if (po.NumArgs() < 4 || po.NumArgs() > 5) {
96 CuDevice::Instantiate().SelectGpuId(use_gpu);
99 std::string model_in_filename = po.GetArg(1),
100 fst_rspecifier = po.GetArg(2),
101 feature_rspecifier = po.GetArg(3),
102 alignment_wspecifier = po.GetArg(4),
103 scores_wspecifier = po.GetOptArg(5);
105 int num_done = 0, num_err = 0, num_retry = 0;
106 double tot_like = 0.0;
107 kaldi::int64 frame_count = 0;
115 Input ki(model_in_filename, &binary);
116 trans_model.
Read(ki.Stream(), binary);
117 am_nnet.
Read(ki.Stream(), binary);
128 online_ivector_rspecifier);
130 ivector_rspecifier, utt2spk_rspecifier);
139 for (; !fst_reader.Done(); fst_reader.Next()) {
140 std::string utt = fst_reader.Key();
141 if (!feature_reader.HasKey(utt)) {
142 KALDI_WARN <<
"No features for utterance " << utt;
147 VectorFst<StdArc> decode_fst(fst_reader.Value());
148 fst_reader.FreeCurrent();
153 KALDI_WARN <<
"Zero-length utterance: " << utt;
160 if (!ivector_rspecifier.empty()) {
161 if (!ivector_reader.HasKey(utt)) {
162 KALDI_WARN <<
"No iVector available for utterance " << utt;
166 ivector = &ivector_reader.Value(utt);
169 if (!online_ivector_rspecifier.empty()) {
170 if (!online_ivector_reader.HasKey(utt)) {
171 KALDI_WARN <<
"No online iVector available for utterance " << utt;
175 online_ivectors = &online_ivector_reader.Value(utt);
180 std::vector<int32> disambig_syms;
182 transition_scale, self_loop_scale,
187 decodable_opts, trans_model, am_nnet,
188 features, ivector, online_ivectors,
189 online_ivector_period, &compiler);
193 &decode_fst, &nnet_decodable,
194 &alignment_writer, &scores_writer,
195 &num_done, &num_err, &num_retry,
196 &tot_like, &frame_count, &per_frame_acwt_writer);
198 KALDI_LOG <<
"Overall log-likelihood per frame is " 199 << (tot_like/frame_count)
200 <<
" over " << frame_count<<
" frames.";
201 KALDI_LOG <<
"Retried " << num_retry <<
" out of " 202 << (num_done + num_err) <<
" utterances.";
203 KALDI_LOG <<
"Done " << num_done <<
", errors on " << num_err;
207 CuDevice::Instantiate().PrintProfile();
209 return (num_done != 0 ? 0 : 1);
210 }
catch(
const std::exception &e) {
211 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void CollapseModel(const CollapseModelConfig &config, Nnet *nnet)
This function modifies the neural net for efficiency, in a way that suitable to be done in test time...
void Register(OptionsItf *opts)
This class is for when you are reading something in random access, but it may actually be stored per-...
This class enables you to do the compilation and optimization in one call, and also ensures that if t...
void SetBatchnormTestMode(bool test_mode, Nnet *nnet)
This function affects only components of type BatchNormComponent.
A templated class for writing objects to an archive or script file; see The Table concept...
const Nnet & GetNnet() const
void Read(std::istream &is, bool binary)
Allows random access to a collection of objects in an archive or script file; see The Table concept...
void SetDropoutTestMode(bool test_mode, Nnet *nnet)
This function affects components of child-classes of RandomComponent.
void AddTransitionProbs(const TransitionModel &trans_model, const std::vector< int32 > &disambig_syms, BaseFloat transition_scale, BaseFloat self_loop_scale, fst::VectorFst< fst::StdArc > *fst)
Adds transition-probs, with the supplied scales (see Scaling of transition and acoustic probabilities...
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
void Read(std::istream &is, bool binary)
void Register(OptionsItf *opts)
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
A class representing a vector.
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
void AlignUtteranceWrapper(const AlignConfig &config, const std::string &utt, BaseFloat acoustic_scale, fst::VectorFst< fst::StdArc > *fst, DecodableInterface *decodable, Int32VectorWriter *alignment_writer, BaseFloatWriter *scores_writer, int32 *num_done, int32 *num_error, int32 *num_retried, double *tot_like, int64 *frame_count, BaseFloatVectorWriter *per_frame_acwt_writer)
AlignUtteranceWapper is a wrapper for alignment code used in training, that is called from many diffe...
NnetOptimizeOptions optimize_config
Config class for the CollapseModel function.