align-mapped.cc File Reference
Include dependency graph for align-mapped.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 31 of file align-mapped.cc.

References kaldi::AlignUtteranceWrapper(), TrainingGraphCompiler::CompileGraphFromText(), SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), RandomAccessTableReader< Holder >::HasKey(), KALDI_ERR, KALDI_LOG, KALDI_WARN, SequentialTableReader< Holder >::Key(), SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), MatrixBase< Real >::NumRows(), ParseOptions::PrintUsage(), ParseOptions::Read(), fst::ReadFstKaldi(), kaldi::ReadIntegerVectorSimple(), kaldi::ReadKaldiObject(), AlignConfig::Register(), TrainingGraphCompilerOptions::Register(), ParseOptions::Register(), RandomAccessTableReader< Holder >::Value(), and SequentialTableReader< Holder >::Value().

31  {
32  try {
33  using namespace kaldi;
34  typedef kaldi::int32 int32;
35  using fst::SymbolTable;
36  using fst::VectorFst;
37  using fst::StdArc;
38 
39  const char *usage =
40  "Generate alignments, reading log-likelihoods as matrices.\n"
41  " (model is needed only for the integer mappings in its transition-model)\n"
42  "Usage: align-mapped [options] <tree-in> <trans-model-in> <lexicon-fst-in> "
43  "<feature-rspecifier> <transcriptions-rspecifier> <alignments-wspecifier>\n"
44  "e.g.: \n"
45  " align-mapped tree trans.mdl lex.fst scp:train.scp ark:train.tra ark:nnet.ali\n";
46  ParseOptions po(usage);
47  AlignConfig align_config;
48  BaseFloat acoustic_scale = 1.0;
49  std::string disambig_rxfilename;
51 
52  align_config.Register(&po);
53  gopts.Register(&po);
54  po.Register("acoustic-scale", &acoustic_scale, "Scaling factor for acoustic likelihoods");
55  po.Register("read-disambig-syms", &disambig_rxfilename, "File containing "
56  "list of disambiguation symbols in phone symbol table");
57 
58  po.Read(argc, argv);
59 
60  if (po.NumArgs() != 6) {
61  po.PrintUsage();
62  exit(1);
63  }
64 
65  std::string tree_in_filename = po.GetArg(1),
66  model_in_filename = po.GetArg(2),
67  lex_in_filename = po.GetArg(3),
68  feature_rspecifier = po.GetArg(4),
69  transcript_rspecifier = po.GetArg(5),
70  alignment_wspecifier = po.GetArg(6);
71 
72  ContextDependency ctx_dep;
73  ReadKaldiObject(tree_in_filename, &ctx_dep);
74 
75  TransitionModel trans_model;
76  ReadKaldiObject(model_in_filename, &trans_model);
77 
78  VectorFst<StdArc> *lex_fst = fst::ReadFstKaldi(lex_in_filename);
79  // ownership will be taken by gc.
80 
81  std::vector<int32> disambig_syms;
82  if (disambig_rxfilename != "")
83  if (!ReadIntegerVectorSimple(disambig_rxfilename, &disambig_syms))
84  KALDI_ERR << "fstcomposecontext: Could not read disambiguation symbols from "
85  << disambig_rxfilename;
86 
87  TrainingGraphCompiler gc(trans_model, ctx_dep, lex_fst, disambig_syms,
88  gopts);
89 
90  lex_fst = NULL; // we gave ownership to gc.
91 
92  SequentialBaseFloatMatrixReader loglikes_reader(feature_rspecifier);
93  RandomAccessInt32VectorReader transcript_reader(transcript_rspecifier);
94  Int32VectorWriter alignment_writer(alignment_wspecifier);
95 
96  int num_done = 0, num_err = 0, num_retry = 0;
97  double tot_like = 0.0;
98  kaldi::int64 frame_count = 0;
99 
100  for (; !loglikes_reader.Done(); loglikes_reader.Next()) {
101  std::string utt = loglikes_reader.Key();
102  if (!transcript_reader.HasKey(utt)) {
103  KALDI_WARN << "No transcript for utterance " << utt;
104  num_err++;
105  continue;
106  }
107  const Matrix<BaseFloat> &loglikes = loglikes_reader.Value();
108  const std::vector<int32> &transcript = transcript_reader.Value(utt);
109 
110  VectorFst<StdArc> decode_fst;
111  if (!gc.CompileGraphFromText(transcript, &decode_fst)) {
112  KALDI_WARN << "Problem creating decoding graph for utterance " <<
113  utt <<" [serious error]";
114  num_err++;
115  continue;
116  }
117  if (loglikes.NumRows() == 0) {
118  KALDI_WARN << "Empty loglikes matrix for utterance: " << utt;
119  num_err++;
120  continue;
121  }
122 
123  DecodableMatrixScaledMapped decodable(trans_model, loglikes, acoustic_scale);
124 
125  AlignUtteranceWrapper(align_config, utt,
126  acoustic_scale, &decode_fst, &decodable,
127  &alignment_writer, NULL,
128  &num_done, &num_err, &num_retry,
129  &tot_like, &frame_count);
130  }
131  KALDI_LOG << "Overall log-likelihood per frame is " << (tot_like/frame_count)
132  << " over " << frame_count<< " frames.";
133  KALDI_LOG << "Retried " << num_retry << " out of "
134  << (num_done + num_err) << " utterances.";
135  KALDI_LOG << "Done " << num_done << ", errors on " << num_err;
136  return (num_done != 0 ? 0 : 1);
137  } catch(const std::exception &e) {
138  std::cerr << e.what();
139  return -1;
140  }
141 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
void Register(OptionsItf *opts)
fst::StdArc StdArc
A templated class for writing objects to an archive or script file; see The Table concept...
Definition: kaldi-table.h:368
kaldi::int32 int32
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
Definition: kaldi-io.cc:832
Allows random access to a collection of objects in an archive or script file; see The Table concept...
Definition: kaldi-table.h:233
float BaseFloat
Definition: kaldi-types.h:29
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
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_WARN
Definition: kaldi-error.h:150
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64
void ReadFstKaldi(std::istream &is, bool binary, VectorFst< Arc > *fst)
bool ReadIntegerVectorSimple(const std::string &rxfilename, std::vector< int32 > *list)
ReadFromList attempts to read this list of integers, one per line, from the given file...
void AlignUtteranceWrapper(const AlignConfig &config, const std::string &utt, BaseFloat acoustic_scale, fst::VectorFst< fst::StdArc > *fst, DecodableInterface *decodable, Int32VectorWriter *alignment_writer, BaseFloatWriter *scores_writer, int32 *num_done, int32 *num_error, int32 *num_retried, double *tot_like, int64 *frame_count, BaseFloatVectorWriter *per_frame_acwt_writer)
AlignUtteranceWapper is a wrapper for alignment code used in training, that is called from many diffe...
#define KALDI_LOG
Definition: kaldi-error.h:153