post-to-weights.cc File Reference
#include "base/kaldi-common.h"
#include "util/common-utils.h"
#include "hmm/posterior.h"
Include dependency graph for post-to-weights.cc:

Go to the source code of this file.

Functions

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

Function Documentation

◆ main()

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

Definition at line 26 of file post-to-weights.cc.

References SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), rnnlm::i, rnnlm::j, KALDI_LOG, SequentialTableReader< Holder >::Key(), SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), SequentialTableReader< Holder >::Value(), and TableWriter< Holder >::Write().

26  {
27  try {
28  using namespace kaldi;
29  typedef kaldi::int32 int32;
30 
31  const char *usage =
32  "Turn posteriors into per-frame weights (typically most useful after\n"
33  "weight-silence-post, to get silence weights)\n"
34  "See also: weight-silence-post, post-to-pdf-post, post-to-phone-post\n"
35  "post-to-feats, get-post-on-ali\n"
36  "Usage: post-to-weights <post-rspecifier> <weights-wspecifier>\n";
37 
38  ParseOptions po(usage);
39  po.Read(argc, argv);
40 
41  if (po.NumArgs() != 2) {
42  po.PrintUsage();
43  exit(1);
44  }
45 
46  std::string post_rspecifier = po.GetArg(1),
47  weights_wspecifier = po.GetArg(2);
48 
49  SequentialPosteriorReader posterior_reader(post_rspecifier);
50  BaseFloatVectorWriter weights_writer(weights_wspecifier);
51 
52  int32 num_done = 0;
53 
54  for (; !posterior_reader.Done(); posterior_reader.Next()) {
55  std::string key = posterior_reader.Key();
56  const Posterior &posterior = posterior_reader.Value();
57  int32 num_frames = static_cast<int32>(posterior.size());
58  Vector<BaseFloat> weights(num_frames);
59  for (int32 i = 0; i < num_frames; i++) {
60  BaseFloat sum = 0.0;
61  for (size_t j = 0; j < posterior[i].size(); j++)
62  sum += posterior[i][j].second;
63  weights(i) = sum;
64  }
65  weights_writer.Write(key, weights);
66  num_done++;
67  }
68  KALDI_LOG << "Done converting " << num_done << " posteriors to weights.";
69  return (num_done != 0 ? 0 : 1);
70  } catch(const std::exception &e) {
71  std::cerr << e.what();
72  return -1;
73  }
74 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
A templated class for writing objects to an archive or script file; see The Table concept...
Definition: kaldi-table.h:368
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
std::vector< std::vector< std::pair< int32, BaseFloat > > > Posterior
Posterior is a typedef for storing acoustic-state (actually, transition-id) posteriors over an uttera...
Definition: posterior.h:42
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Definition: kaldi-table.h:287
A class representing a vector.
Definition: kaldi-vector.h:406
#define KALDI_LOG
Definition: kaldi-error.h:153