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\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 }
72 
73 
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: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
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.