34 using namespace kaldi;
37 using fst::SymbolTable;
42 "Align features given neural-net-based model\n" 43 "Usage: nnet-align-compiled [options] <model-in> <graphs-rspecifier> " 44 "<feature-rspecifier> <alignments-wspecifier>\n" 46 " nnet-align-compiled 1.mdl ark:graphs.fsts scp:train.scp ark:1.ali\n" 48 " compile-train-graphs tree 1.mdl lex.fst 'ark:sym2int.pl -f 2- words.txt text|' \\\n" 49 " ark:- | nnet-align-compiled 1.mdl ark:- scp:train.scp t, ark:1.ali\n";
53 std::string use_gpu =
"yes";
57 std::string per_frame_acwt_wspecifier;
60 po.Register(
"transition-scale", &transition_scale,
61 "Transition-probability scale [relative to acoustics]");
62 po.Register(
"acoustic-scale", &acoustic_scale,
63 "Scaling factor for acoustic likelihoods");
64 po.Register(
"self-loop-scale", &self_loop_scale,
65 "Scale of self-loop versus non-self-loop " 66 "log probs [relative to acoustics]");
67 po.Register(
"write-per-frame-acoustic-loglikes", &per_frame_acwt_wspecifier,
68 "Wspecifier for table of vectors containing the acoustic log-likelihoods " 69 "per frame for each utterance. E.g. ark:foo/per_frame_logprobs.1.ark");
70 po.Register(
"use-gpu", &use_gpu,
71 "yes|no|optional|wait, only has effect if compiled with CUDA");
74 if (po.NumArgs() < 4 || po.NumArgs() > 5) {
80 CuDevice::Instantiate().SelectGpuId(use_gpu);
83 std::string model_in_filename = po.GetArg(1),
84 fst_rspecifier = po.GetArg(2),
85 feature_rspecifier = po.GetArg(3),
86 alignment_wspecifier = po.GetArg(4),
87 scores_wspecifier = po.GetOptArg(5);
89 int num_done = 0, num_err = 0, num_retry = 0;
90 double tot_like = 0.0;
91 kaldi::int64 frame_count = 0;
98 Input ki(model_in_filename, &binary);
99 trans_model.
Read(ki.Stream(), binary);
100 am_nnet.
Read(ki.Stream(), binary);
109 for (; !fst_reader.Done(); fst_reader.Next()) {
110 std::string utt = fst_reader.Key();
111 if (!feature_reader.HasKey(utt)) {
112 KALDI_WARN <<
"No features for utterance " << utt;
117 VectorFst<StdArc> decode_fst(fst_reader.Value());
118 fst_reader.FreeCurrent();
123 KALDI_WARN <<
"Zero-length utterance: " << utt;
129 std::vector<int32> disambig_syms;
131 transition_scale, self_loop_scale,
135 bool pad_input =
true;
137 pad_input, acoustic_scale);
140 acoustic_scale, &decode_fst, &nnet_decodable,
141 &alignment_writer, &scores_writer,
142 &num_done, &num_err, &num_retry,
143 &tot_like, &frame_count, &per_frame_acwt_writer);
145 KALDI_LOG <<
"Overall log-likelihood per frame is " << (tot_like/frame_count)
146 <<
" over " << frame_count<<
" frames.";
147 KALDI_LOG <<
"Retried " << num_retry <<
" out of " 148 << (num_done + num_err) <<
" utterances.";
149 KALDI_LOG <<
"Done " << num_done <<
", errors on " << num_err;
152 CuDevice::Instantiate().PrintProfile();
154 return (num_done != 0 ? 0 : 1);
155 }
catch(
const std::exception &e) {
156 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void Register(OptionsItf *opts)
void Read(std::istream &is, bool binary)
A templated class for writing objects to an archive or script file; see The Table concept...
This class represents a matrix that's stored on the GPU if we have one, and in memory if not...
Allows random access to a collection of objects in an archive or script file; see The Table concept...
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)
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
DecodableAmNnet is a decodable object that decodes with a neural net acoustic model of type AmNnet...
MatrixIndexT NumRows() const
Dimensions.
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...