est-mllt.cc
Go to the documentation of this file.
1 // bin/est-mllt.cc
2 // Copyright 2009-2011 Microsoft Corporation
3 
4 // See ../../COPYING for clarification regarding multiple authors
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 //
10 // http://www.apache.org/licenses/LICENSE-2.0
11 //
12 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
14 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
15 // MERCHANTABLITY OR NON-INFRINGEMENT.
16 // See the Apache 2 License for the specific language governing permissions and
17 // limitations under the License.
18 
19 #include "base/kaldi-common.h"
20 #include "util/common-utils.h"
21 #include "gmm/am-diag-gmm.h"
22 #include "tree/context-dep.h"
23 #include "hmm/transition-model.h"
24 #include "transform/mllt.h"
25 
26 int main(int argc, char *argv[]) {
27  try {
28  using namespace kaldi;
29  typedef kaldi::int32 int32;
30 
31  const char *usage =
32  "Do update for MLLT (also known as STC)\n"
33  "Usage: est-mllt [options] <mllt-mat-out> <stats-in1> <stats-in2> ... \n"
34  "e.g.: est-mllt 2.mat 1a.macc 1b.macc ... \n"
35  "where the stats are obtained from gmm-acc-mllt\n"
36  "Note: use compose-transforms <mllt-mat-out> <prev-mllt-mat> to combine with previous\n"
37  " MLLT or LDA transform, if any, and\n"
38  " gmm-transform-means to apply <mllt-mat-out> to GMM means.\n";
39 
40  bool binary = true; // write in binary if true.
41 
42  ParseOptions po(usage);
43  po.Register("binary", &binary, "Write output in binary mode");
44 
45  po.Read(argc, argv);
46 
47  if (po.NumArgs() < 2) {
48  po.PrintUsage();
49  exit(1);
50  }
51 
52  std::string mllt_out_filename = po.GetArg(1);
53 
54  MlltAccs mllt_accs;
55  for (int32 i = 2; i <= po.NumArgs(); i++) {
56  std::string acc_filename = po.GetArg(i);
57  bool binary_in, add = true;
58  Input ki(acc_filename, &binary_in);
59  mllt_accs.Read(ki.Stream(), binary_in, add);
60  }
61 
62  Matrix<BaseFloat> mat(mllt_accs.Dim(), mllt_accs.Dim());
63  mat.SetUnit();
64  BaseFloat objf_impr, count;
65  mllt_accs.Update(&mat, &objf_impr, &count);
66 
67  KALDI_LOG << "Overall objective function improvement for MLLT is "
68  << (objf_impr/count) << " over " << count << " frames, logdet is "
69  << mat.LogDet();
70 
71  Output ko(mllt_out_filename, binary);
72  mat.Write(ko.Stream(), binary);
73 
74  return 0;
75  } catch(const std::exception &e) {
76  std::cerr << e.what() << '\n';
77  return -1;
78  }
79 }
80 
81 
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
void Read(std::istream &is, bool binary, bool add=false)
Definition: mllt.cc:34
kaldi::int32 int32
void SetUnit()
Sets to zero, except ones along diagonal [for non-square matrices too].
void Register(const std::string &name, bool *ptr, const std::string &doc)
void Update(MatrixBase< BaseFloat > *M, BaseFloat *objf_impr_out, BaseFloat *count_out) const
The Update function does the ML update; it requires that M has the right size.
Definition: mllt.h:69
const size_t count
std::istream & Stream()
Definition: kaldi-io.cc:826
float BaseFloat
Definition: kaldi-types.h:29
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
std::ostream & Stream()
Definition: kaldi-io.cc:701
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
int main(int argc, char *argv[])
Definition: est-mllt.cc:26
int NumArgs() const
Number of positional parameters (c.f. argc-1).
int32 Dim()
Definition: mllt.h:60
#define KALDI_LOG
Definition: kaldi-error.h:153
A class for estimating Maximum Likelihood Linear Transform, also known as global Semi-tied Covariance...
Definition: mllt.h:42