All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ali-to-post.cc
Go to the documentation of this file.
1 // bin/ali-to-post.cc
2 
3 // Copyright 2009-2012 Microsoft Corporation, Go-Vivace Inc.,
4 // Johns Hopkins University (author: Daniel Povey)
5 
6 // See ../../COPYING for clarification regarding multiple authors
7 //
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 //
12 // http://www.apache.org/licenses/LICENSE-2.0
13 //
14 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
16 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
17 // MERCHANTABLITY OR NON-INFRINGEMENT.
18 // See the Apache 2 License for the specific language governing permissions and
19 // limitations under the License.
20 
21 
22 #include "base/kaldi-common.h"
23 #include "util/common-utils.h"
24 #include "gmm/am-diag-gmm.h"
25 #include "hmm/transition-model.h"
26 #include "hmm/hmm-utils.h"
27 #include "hmm/posterior.h"
28 
31 int main(int argc, char *argv[]) {
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
void Write(const std::string &key, const T &value) const
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
int main(int argc, char *argv[])
Convert alignments to viterbi style posteriors.
Definition: ali-to-post.cc:31
A templated class for writing objects to an archive or script file; see The Table concept...
Definition: kaldi-table.h:368
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
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
#define KALDI_LOG
Definition: kaldi-error.h:133
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.