36 using namespace kaldi;
38 "Compute MLLR transforms per-utterance (default) or per-speaker for " 39 "the supplied set of speakers (spk2utt option). Note: writes RegtreeMllrDiagGmm objects\n" 40 "Usage: gmm-est-regtree-mllr [options] <model-in> <feature-rspecifier> " 41 "<posteriors-rspecifier> <regression-tree> <transforms-wspecifier>\n";
44 string spk2utt_rspecifier;
46 po.Register(
"spk2utt", &spk2utt_rspecifier,
"rspecifier for speaker to " 47 "utterance-list map");
48 po.Register(
"binary", &binary,
"Write output in binary mode");
55 if (po.NumArgs() != 5) {
60 string model_filename = po.GetArg(1),
61 feature_rspecifier = po.GetArg(2),
62 posteriors_rspecifier = po.GetArg(3),
63 regtree_filename = po.GetArg(4),
64 xforms_wspecifier = po.GetArg(5);
73 Input ki(model_filename, &binary);
74 trans_model.
Read(ki.Stream(), binary);
75 am_gmm.
Read(ki.Stream(), binary);
80 Input in(regtree_filename, &binary);
81 regtree.
Read(in.Stream(), binary, am_gmm);
88 double tot_like = 0.0, tot_t = 0;
90 int32 num_done = 0, num_no_posterior = 0, num_other_error = 0;
91 double tot_objf_impr = 0.0, tot_t_objf = 0.0;
92 if (spk2utt_rspecifier !=
"") {
95 for (; !spk2utt_reader.Done(); spk2utt_reader.Next()) {
96 string spk = spk2utt_reader.Key();
98 const vector<string> &uttlist = spk2utt_reader.Value();
99 for (vector<string>::const_iterator utt_itr = uttlist.begin(),
100 itr_end = uttlist.end(); utt_itr != itr_end; ++utt_itr) {
101 if (!feature_reader.HasKey(*utt_itr)) {
102 KALDI_WARN <<
"Did not find features for utterance " << *utt_itr;
105 if (!posteriors_reader.HasKey(*utt_itr)) {
106 KALDI_WARN <<
"Did not find posteriors for utterance " 112 const Posterior &posterior = posteriors_reader.Value(*utt_itr);
113 if (posterior.size() != feats.
NumRows()) {
114 KALDI_WARN <<
"Posteriors has wrong size " << (posterior.size())
115 <<
" vs. " << (feats.
NumRows());
123 for (
size_t i = 0;
i < posterior.size();
i++) {
124 for (
size_t j = 0;
j < pdf_posterior[
i].size();
j++) {
125 int32 pdf_id = pdf_posterior[
i][
j].first;
128 feats.
Row(
i), pdf_id,
133 KALDI_VLOG(2) <<
"Average like for this file is " << (file_like/file_t)
134 <<
" over " << file_t <<
" frames.";
135 tot_like += file_like;
138 if (num_done % 10 == 0)
139 KALDI_VLOG(1) <<
"Avg like per frame so far is " 140 << (tot_like / tot_t);
143 mllr_accs.
Update(regtree, opts, &mllr_xforms, &objf_impr, &t);
144 KALDI_LOG <<
"MLLR objf improvement for speaker " << spk <<
" is " 145 << (objf_impr/(t+1.0e-10)) <<
" per frame over " << t
147 tot_objf_impr += objf_impr;
149 mllr_writer.Write(spk, mllr_xforms);
153 for (; !feature_reader.Done(); feature_reader.Next()) {
154 string key = feature_reader.Key();
155 if (!posteriors_reader.HasKey(key)) {
156 KALDI_WARN <<
"Did not find aligned transcription for utterance " 162 const Posterior &posterior = posteriors_reader.Value(key);
164 if (posterior.size() != feats.
NumRows()) {
165 KALDI_WARN <<
"Posteriors has wrong size " << (posterior.size())
166 <<
" vs. " << (feats.
NumRows());
176 for (
size_t i = 0;
i < posterior.size();
i++) {
177 for (
size_t j = 0;
j < pdf_posterior[
i].size();
j++) {
178 int32 pdf_id = pdf_posterior[
i][
j].first;
181 feats.
Row(
i), pdf_id,
186 KALDI_VLOG(2) <<
"Average like for this file is " << (file_like/file_t)
187 <<
" over " << file_t <<
" frames.";
188 tot_like += file_like;
190 if (num_done % 10 == 0)
191 KALDI_VLOG(1) <<
"Avg like per frame so far is " << (tot_like / tot_t);
193 mllr_accs.
Update(regtree, opts, &mllr_xforms, &objf_impr, &t);
194 KALDI_LOG <<
"MLLR objf improvement for utterance " << key <<
" is " 195 << (objf_impr/(t+1.0e-10)) <<
" per frame over " << t
197 tot_objf_impr += objf_impr;
199 mllr_writer.Write(feature_reader.Key(), mllr_xforms);
202 KALDI_LOG <<
"Done " << num_done <<
" files, " << num_no_posterior
203 <<
" with no posteriors, " << num_other_error
204 <<
" with other errors.";
205 KALDI_LOG <<
"Overall objf improvement from MLLR is " << (tot_objf_impr/tot_t_objf)
206 <<
" per frame " <<
" over " << tot_t_objf <<
" frames.";
207 KALDI_LOG <<
"Overall acoustic likelihood was " << (tot_like/tot_t)
208 <<
" over " << tot_t <<
" frames.";
210 }
catch(
const std::exception &e) {
211 std::cerr << e.what();
void Read(std::istream &in, bool binary, const AmDiagGmm &am)
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void Register(OptionsItf *opts)
An MLLR mean transformation is an affine transformation of Gaussian means.
Configuration variables for FMLLR transforms.
A templated class for writing objects to an archive or script file; see The Table concept...
void Init(int32 num_bclass, int32 dim)
Allows random access to a collection of objects in an archive or script file; see The Table concept...
int32 NumBaseclasses() const
Accessors (const)
std::vector< std::vector< std::pair< int32, BaseFloat > > > Posterior
Posterior is a typedef for storing acoustic-state (actually, transition-id) posteriors over an uttera...
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
A regression tree is a clustering of Gaussian densities in an acoustic model, such that the group of ...
void Read(std::istream &is, bool binary)
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Class for computing the maximum-likelihood estimates of the parameters of an acoustic model that uses...
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
void ConvertPosteriorToPdfs(const TransitionModel &tmodel, const Posterior &post_in, Posterior *post_out)
Converts a posterior over transition-ids to be a posterior over pdf-ids.
BaseFloat AccumulateForGmm(const RegressionTree ®tree, const AmDiagGmm &am, const VectorBase< BaseFloat > &data, int32 pdf_index, BaseFloat weight)
Accumulate stats for a single GMM in the model; returns log likelihood.
void Update(const RegressionTree ®tree, const RegtreeMllrOptions &opts, RegtreeMllrDiagGmm *out_mllr, BaseFloat *auxf_impr, BaseFloat *t) const
void Read(std::istream &in_stream, bool binary)