training-graph-compiler.h
Go to the documentation of this file.
1 // decoder/training-graph-compiler.h
2 
3 // Copyright 2009-2011 Microsoft Corporation
4 // 2018 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 #ifndef KALDI_DECODER_TRAINING_GRAPH_COMPILER_H_
21 #define KALDI_DECODER_TRAINING_GRAPH_COMPILER_H_
22 
23 #include "base/kaldi-common.h"
24 #include "hmm/transition-model.h"
25 #include "fst/fstlib.h"
26 #include "fstext/fstext-lib.h"
27 #include "tree/context-dep.h"
28 
29 
30 namespace kaldi {
31 
33 
36  bool rm_eps;
37  bool reorder; // (Dan-style graphs)
38 
39  explicit TrainingGraphCompilerOptions(BaseFloat transition_scale = 1.0,
40  BaseFloat self_loop_scale = 1.0,
41  bool b = true) :
42  transition_scale(transition_scale),
43  self_loop_scale(self_loop_scale),
44  rm_eps(false),
45  reorder(b) { }
46 
47  void Register(OptionsItf *opts) {
48  opts->Register("transition-scale", &transition_scale, "Scale of transition "
49  "probabilities (excluding self-loops)");
50  opts->Register("self-loop-scale", &self_loop_scale, "Scale of self-loop vs. "
51  "non-self-loop probability mass ");
52  opts->Register("reorder", &reorder, "Reorder transition ids for greater decoding efficiency.");
53  opts->Register("rm-eps", &rm_eps, "Remove [most] epsilons before minimization (only applicable "
54  "if disambig symbols present)");
55  }
56 };
57 
58 
60  public:
61  TrainingGraphCompiler(const TransitionModel &trans_model, // Maintains reference to this object.
62  const ContextDependency &ctx_dep, // And this.
63  fst::VectorFst<fst::StdArc> *lex_fst, // Takes ownership of this object.
64  // It should not contain disambiguation symbols or subsequential symbol,
65  // but it should contain optional silence.
66  const std::vector<int32> &disambig_syms, // disambig symbols in phone symbol table.
67  const TrainingGraphCompilerOptions &opts);
68 
69 
70  // CompileGraph compiles a single training graph its input is a
71  // weighted acceptor (G) at the word level, its output is HCLG.
72  // Note: G could actually be a transducer, it would also work.
73  // This function is not const for technical reasons involving the cache.
74  // if not for "table_compose" we could make it const.
75  bool CompileGraph(const fst::VectorFst<fst::StdArc> &word_grammar,
76  fst::VectorFst<fst::StdArc> *out_fst);
77 
78  // CompileGraphs allows you to compile a number of graphs at the same
79  // time. This consumes more memory but is faster.
80  bool CompileGraphs(
81  const std::vector<const fst::VectorFst<fst::StdArc> *> &word_fsts,
82  std::vector<fst::VectorFst<fst::StdArc> *> *out_fsts);
83 
84  // This version creates an FST from the text and calls CompileGraph.
85  bool CompileGraphFromText(const std::vector<int32> &transcript,
86  fst::VectorFst<fst::StdArc> *out_fst);
87 
88  // This function creates FSTs from the text and calls CompileGraphs.
89  bool CompileGraphsFromText(
90  const std::vector<std::vector<int32> > &word_grammar,
91  std::vector<fst::VectorFst<fst::StdArc> *> *out_fsts);
92 
93 
94  ~TrainingGraphCompiler() { delete lex_fst_; }
95  private:
98  fst::VectorFst<fst::StdArc> *lex_fst_; // lexicon FST (an input; we take
99  // ownership as we need to modify it).
100  std::vector<int32> disambig_syms_; // disambig symbols (if any) in the phone
101  int32 subsequential_symbol_; // search in ../fstext/context-fst.h for more info.
102  // symbol table.
104  // this is one of Dan's extensions.
105 
107 };
108 
109 
110 
111 } // end namespace kaldi.
112 
113 #endif
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
const ContextDependency & ctx_dep_
fst::TableComposeCache< fst::Fst< fst::StdArc > > lex_cache_
kaldi::int32 int32
const TransitionModel & trans_model_
fst::VectorFst< fst::StdArc > * lex_fst_
virtual void Register(const std::string &name, bool *ptr, const std::string &doc)=0
TableComposeCache lets us do multiple compositions while caching the same matcher.
TrainingGraphCompilerOptions opts_
TrainingGraphCompilerOptions(BaseFloat transition_scale=1.0, BaseFloat self_loop_scale=1.0, bool b=true)