lattice-faster-online-decoder.h
Go to the documentation of this file.
1 // decoder/lattice-faster-online-decoder.h
2 
3 // Copyright 2009-2013 Microsoft Corporation; Mirko Hannemann;
4 // 2013-2014 Johns Hopkins University (Author: Daniel Povey)
5 // 2014 Guoguo Chen
6 // 2018 Zhehuai Chen
7 
8 // See ../../COPYING for clarification regarding multiple authors
9 //
10 // Licensed under the Apache License, Version 2.0 (the "License");
11 // you may not use this file except in compliance with the License.
12 // You may obtain a copy of the License at
13 //
14 // http://www.apache.org/licenses/LICENSE-2.0
15 //
16 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
18 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
19 // MERCHANTABLITY OR NON-INFRINGEMENT.
20 // See the Apache 2 License for the specific language governing permissions and
21 // limitations under the License.
22 
23 // see note at the top of lattice-faster-decoder.h, about how to maintain this
24 // file in sync with lattice-faster-decoder.h
25 
26 
27 #ifndef KALDI_DECODER_LATTICE_FASTER_ONLINE_DECODER_H_
28 #define KALDI_DECODER_LATTICE_FASTER_ONLINE_DECODER_H_
29 
30 #include "util/stl-utils.h"
31 #include "util/hash-list.h"
32 #include "fst/fstlib.h"
33 #include "itf/decodable-itf.h"
34 #include "fstext/fstext-lib.h"
36 #include "lat/kaldi-lattice.h"
38 
39 namespace kaldi {
40 
41 
42 
53 template <typename FST>
55  public LatticeFasterDecoderTpl<FST, decoder::BackpointerToken> {
56  public:
57  using Arc = typename FST::Arc;
58  using Label = typename Arc::Label;
59  using StateId = typename Arc::StateId;
60  using Weight = typename Arc::Weight;
63 
64  // Instantiate this class once for each thing you have to decode.
65  // This version of the constructor does not take ownership of
66  // 'fst'.
68  const LatticeFasterDecoderConfig &config):
69  LatticeFasterDecoderTpl<FST, Token>(fst, config) { }
70 
71  // This version of the initializer takes ownership of 'fst', and will delete
72  // it when this object is destroyed.
74  FST *fst):
75  LatticeFasterDecoderTpl<FST, Token>(config, fst) { }
76 
77 
79  void *tok;
81  // note, "frame" is the frame-index of the frame you'll get the
82  // transition-id for next time, if you call TraceBackBestPath on this
83  // iterator (assuming it's not an epsilon transition). Note that this
84  // is one less than you might reasonably expect, e.g. it's -1 for
85  // the nonemitting transitions before the first frame.
86  BestPathIterator(void *t, int32 f): tok(t), frame(f) { }
87  bool Done() const { return tok == NULL; }
88  };
89 
90 
99  bool GetBestPath(Lattice *ofst,
100  bool use_final_probs = true) const;
101 
102 
105  bool TestGetBestPath(bool use_final_probs = true) const;
106 
107 
115  BestPathIterator BestPathEnd(bool use_final_probs,
116  BaseFloat *final_cost = NULL) const;
117 
118 
127  BestPathIterator iter, LatticeArc *arc) const;
128 
129 
135  bool GetRawLatticePruned(Lattice *ofst,
136  bool use_final_probs,
137  BaseFloat beam) const;
138 
140 };
141 
143 
144 
145 } // end namespace kaldi.
146 
147 #endif
fst::StdArc::StateId StateId
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
fst::ArcTpl< LatticeWeight > LatticeArc
Definition: kaldi-lattice.h:40
LatticeFasterOnlineDecoderTpl(const FST &fst, const LatticeFasterDecoderConfig &config)
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
LatticeFasterOnlineDecoderTpl(const LatticeFasterDecoderConfig &config, FST *fst)
kaldi::int32 int32
fst::VectorFst< LatticeArc > Lattice
Definition: kaldi-lattice.h:44
KALDI_DISALLOW_COPY_AND_ASSIGN(LatticeFasterOnlineDecoderTpl)
LatticeFasterOnlineDecoderTpl is as LatticeFasterDecoderTpl but also supports an efficient way to get...
BestPathIterator TraceBackBestPath(BestPathIterator iter, LatticeArc *arc) const
This function can be used in conjunction with BestPathEnd() to trace back the best path one link at a...
fst::StdArc::Label Label
bool TestGetBestPath(bool use_final_probs=true) const
This function does a self-test of GetBestPath().
fst::StdArc::Weight Weight
This is the "normal" lattice-generating decoder.
BestPathIterator BestPathEnd(bool use_final_probs, BaseFloat *final_cost=NULL) const
This function returns an iterator that can be used to trace back the best path.
bool GetBestPath(Lattice *ofst, bool use_final_probs=true) const
Outputs an FST corresponding to the single best path through the lattice.
LatticeFasterOnlineDecoderTpl< fst::StdFst > LatticeFasterOnlineDecoder
bool GetRawLatticePruned(Lattice *ofst, bool use_final_probs, BaseFloat beam) const
Behaves the same as GetRawLattice but only processes tokens whose extra_cost is smaller than the best...