All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ali-to-post.cc File Reference
#include "base/kaldi-common.h"
#include "util/common-utils.h"
#include "gmm/am-diag-gmm.h"
#include "hmm/transition-model.h"
#include "hmm/hmm-utils.h"
#include "hmm/posterior.h"
Include dependency graph for ali-to-post.cc:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 Convert alignments to viterbi style posteriors. More...
 

Function Documentation

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

Convert alignments to viterbi style posteriors.

The aligned symbol gets a weight of 1.0

Definition at line 31 of file ali-to-post.cc.

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

31  {
32  using namespace kaldi;
33  typedef kaldi::int32 int32;
34  try {
35  const char *usage =
36  "Convert alignments to posteriors. This is simply a format change\n"
37  "from integer vectors to Posteriors, which are vectors of lists of\n"
38  "pairs (int, float) where the float represents the posterior. The\n"
39  "floats would all be 1.0 in this case.\n"
40  "The posteriors will still be in terms of whatever integer index\n"
41  "the input contained, which will be transition-ids if they came\n"
42  "directly from decoding, or pdf-ids if they were processed by\n"
43  "ali-to-post.\n"
44  "Usage: ali-to-post [options] <alignments-rspecifier> <posteriors-wspecifier>\n"
45  "e.g.:\n"
46  " ali-to-post ark:1.ali ark:1.post\n"
47  "See also: ali-to-pdf, ali-to-phones, show-alignments, post-to-weights\n";
48 
49  ParseOptions po(usage);
50 
51  po.Read(argc, argv);
52 
53  if (po.NumArgs() != 2) {
54  po.PrintUsage();
55  exit(1);
56  }
57 
58  std::string alignments_rspecifier = po.GetArg(1);
59  std::string posteriors_wspecifier = po.GetArg(2);
60 
61  int32 num_done = 0;
62  SequentialInt32VectorReader alignment_reader(alignments_rspecifier);
63  PosteriorWriter posterior_writer(posteriors_wspecifier);
64 
65  for (; !alignment_reader.Done(); alignment_reader.Next()) {
66  num_done++;
67  const std::vector<int32> &alignment = alignment_reader.Value();
68  // Posterior is vector<vector<pair<int32, BaseFloat> > >
69  Posterior post;
70  AlignmentToPosterior(alignment, &post);
71  posterior_writer.Write(alignment_reader.Key(), post);
72  }
73  KALDI_LOG << "Converted " << num_done << " alignments.";
74  return (num_done != 0 ? 0 : 1);
75  } catch(const std::exception &e) {
76  std::cerr << e.what();
77  return -1;
78  }
79 }
Relabels neural network egs with the read pdf-id alignments.
Definition: chain.dox:20
A templated class for writing objects to an archive or script file; see The Table concept...
Definition: kaldi-table.h:366
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:43
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
void AlignmentToPosterior(const std::vector< int32 > &ali, Posterior *post)
Convert an alignment to a posterior (with a scale of 1.0 on each entry).
Definition: posterior.cc:290
#define KALDI_LOG
Definition: kaldi-error.h:133