compile-questions.cc File Reference
Include dependency graph for compile-questions.cc:

Go to the source code of this file.

Namespaces

 kaldi
 This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for mispronunciations detection tasks, the reference:
 

Functions

int32 ProcessTopo (const HmmTopology &topo, const std::vector< std::vector< int32 > > &questions)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 57 of file compile-questions.cc.

References ParseOptions::GetArg(), rnnlm::i, QuestionsForKey::initial_questions, kaldi::IsSortedAndUniq(), rnnlm::j, KALDI_ERR, KALDI_LOG, KALDI_WARN, kaldi::kPdfClass, rnnlm::n, ParseOptions::NumArgs(), kaldi::PrintableRxfilename(), ParseOptions::PrintUsage(), kaldi::ProcessTopo(), ParseOptions::Read(), kaldi::ReadIntegerVectorVectorSimple(), kaldi::ReadKaldiObject(), ParseOptions::Register(), Questions::SetQuestionsOf(), kaldi::SortAndUniq(), and kaldi::WriteKaldiObject().

57  {
58  using namespace kaldi;
59  try {
60  using namespace kaldi;
61  typedef kaldi::int32 int32;
62 
63  const char *usage =
64  "Compile questions\n"
65  "Usage: compile-questions [options] <topo> <questions-text-file> <questions-out>\n"
66  "e.g.: \n"
67  " compile-questions questions.txt questions.qst\n";
68  bool binary = true;
69  int32 P = 1, N = 3;
70  int32 num_iters_refine = 0;
71 
72 
73  ParseOptions po(usage);
74  po.Register("binary", &binary,
75  "Write output in binary mode");
76  po.Register("context-width", &N,
77  "Context window size [must match acc-tree-stats].");
78  po.Register("central-position", &P,
79  "Central position in phone context window [must match acc-tree-stats]");
80  po.Register("num-iters-refine", &num_iters_refine,
81  "Number of iters of refining questions at each node. >0 --> questions "
82  "not refined");
83 
84  po.Read(argc, argv);
85 
86  if (po.NumArgs() != 3) {
87  po.PrintUsage();
88  exit(1);
89  }
90 
91  std::string
92  topo_filename = po.GetArg(1),
93  questions_rxfilename = po.GetArg(2),
94  questions_out_filename = po.GetArg(3);
95 
96  HmmTopology topo; // just needed for checking, and to get the
97  // largest number of pdf-classes for any phone.
98  ReadKaldiObject(topo_filename, &topo);
99 
100  std::vector<std::vector<int32> > questions; // sets of phones.
101  if (!ReadIntegerVectorVectorSimple(questions_rxfilename, &questions))
102  KALDI_ERR << "Could not read questions from "
103  << PrintableRxfilename(questions_rxfilename);
104  for (size_t i = 0; i < questions.size(); i++) {
105  std::sort(questions[i].begin(), questions[i].end());
106  if (!IsSortedAndUniq(questions[i]))
107  KALDI_ERR << "Questions contain duplicate phones";
108  }
109  size_t nq = static_cast<int32>(questions.size());
110  SortAndUniq(&questions);
111  if (questions.size() != nq)
112  KALDI_WARN << (nq-questions.size())
113  << " duplicate questions present in " << questions_rxfilename;
114 
115  // ProcessTopo checks that all phones in the topo are
116  // represented in at least one questions (else warns), and
117  // returns the max # pdf classes in any given phone (normally
118  // 3).
119  int32 max_num_pdfclasses = ProcessTopo(topo, questions);
120 
121  Questions qo;
122 
123  QuestionsForKey phone_opts(num_iters_refine);
124  // the questions-options corresponding to keys 0, 1, .. N-1 which
125  // represent the phonetic context positions (including the central phone).
126  for (int32 n = 0; n < N; n++) {
127  KALDI_LOG << "Setting questions for phonetic-context position "<< n;
128  phone_opts.initial_questions = questions;
129  qo.SetQuestionsOf(n, phone_opts);
130  }
131 
132  QuestionsForKey pdfclass_opts(num_iters_refine);
133  std::vector<std::vector<int32> > pdfclass_questions(max_num_pdfclasses-1);
134  for (int32 i = 0; i < max_num_pdfclasses - 1; i++)
135  for (int32 j = 0; j <= i; j++)
136  pdfclass_questions[i].push_back(j);
137  // E.g. if max_num_pdfclasses == 3, pdfclass_questions is now [ [0], [0, 1] ].
138  pdfclass_opts.initial_questions = pdfclass_questions;
139  KALDI_LOG << "Setting questions for hmm-position [hmm-position ranges from 0 to "<< (max_num_pdfclasses-1) <<"]";
140  qo.SetQuestionsOf(kPdfClass, pdfclass_opts);
141 
142  WriteKaldiObject(qo, questions_out_filename, binary);
143  KALDI_LOG << "Wrote questions to "<<questions_out_filename;
144  } catch(const std::exception &e) {
145  std::cerr << e.what();
146  return -1;
147  }
148 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
This class defines, for each EventKeyType, a set of initial questions that it tries and also a number...
A class for storing topology information for phones.
Definition: hmm-topology.h:93
int32 ProcessTopo(const HmmTopology &topo, const std::vector< std::vector< int32 > > &questions)
void SetQuestionsOf(EventKeyType key, const QuestionsForKey &options_of_key)
kaldi::int32 int32
void SortAndUniq(std::vector< T > *vec)
Sorts and uniq&#39;s (removes duplicates) from a vector.
Definition: stl-utils.h:39
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
Definition: kaldi-io.cc:832
static const EventKeyType kPdfClass
Definition: context-dep.h:39
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
bool ReadIntegerVectorVectorSimple(const std::string &rxfilename, std::vector< std::vector< int32 > > *list)
struct rnnlm::@11::@12 n
QuestionsForKey is a class used to define the questions for a key, and also options that allow us to ...
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_WARN
Definition: kaldi-error.h:150
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
Definition: kaldi-io.h:257
std::string PrintableRxfilename(const std::string &rxfilename)
PrintableRxfilename turns the rxfilename into a more human-readable form for error reporting...
Definition: kaldi-io.cc:61
bool IsSortedAndUniq(const std::vector< T > &vec)
Returns true if the vector is sorted and contains each element only once.
Definition: stl-utils.h:63
#define KALDI_LOG
Definition: kaldi-error.h:153