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\n"
37  "Usage: ali-to-post [options] <alignments-rspecifier> <posteriors-wspecifier>\n"
38  "e.g.:\n"
39  " ali-to-post ark:1.ali ark:1.post\n";
40 
41  ParseOptions po(usage);
42 
43  po.Read(argc, argv);
44 
45  if (po.NumArgs() != 2) {
46  po.PrintUsage();
47  exit(1);
48  }
49 
50  std::string alignments_rspecifier = po.GetArg(1);
51  std::string posteriors_wspecifier = po.GetArg(2);
52 
53  int32 num_done = 0;
54  SequentialInt32VectorReader alignment_reader(alignments_rspecifier);
55  PosteriorWriter posterior_writer(posteriors_wspecifier);
56 
57  for (; !alignment_reader.Done(); alignment_reader.Next()) {
58  num_done++;
59  const std::vector<int32> &alignment = alignment_reader.Value();
60  // Posterior is vector<vector<pair<int32, BaseFloat> > >
61  Posterior post;
62  AlignmentToPosterior(alignment, &post);
63  posterior_writer.Write(alignment_reader.Key(), post);
64  }
65  KALDI_LOG << "Converted " << num_done << " alignments.";
66  return (num_done != 0 ? 0 : 1);
67  } catch(const std::exception &e) {
68  std::cerr << e.what();
69  return -1;
70  }
71 }
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