lattice-incremental-online-decoder.h
Go to the documentation of this file.
1 // decoder/lattice-incremental-online-decoder.h
2 
3 // Copyright 2019 Zhehuai Chen
4 //
5 // See ../../COPYING for clarification regarding multiple authors
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16 // MERCHANTABLITY OR NON-INFRINGEMENT.
17 // See the Apache 2 License for the specific language governing permissions and
18 // limitations under the License.
19 
20 // see note at the top of lattice-faster-decoder.h, about how to maintain this
21 // file in sync with lattice-faster-decoder.h
22 
23 
24 #ifndef KALDI_DECODER_LATTICE_INCREMENTAL_ONLINE_DECODER_H_
25 #define KALDI_DECODER_LATTICE_INCREMENTAL_ONLINE_DECODER_H_
26 
27 #include "util/stl-utils.h"
28 #include "util/hash-list.h"
29 #include "fst/fstlib.h"
30 #include "itf/decodable-itf.h"
31 #include "fstext/fstext-lib.h"
33 #include "lat/kaldi-lattice.h"
35 
36 namespace kaldi {
37 
38 
39 
50 template <typename FST>
52  public LatticeIncrementalDecoderTpl<FST, decoder::BackpointerToken> {
53  public:
54  using Arc = typename FST::Arc;
55  using Label = typename Arc::Label;
56  using StateId = typename Arc::StateId;
57  using Weight = typename Arc::Weight;
60 
61  // Instantiate this class once for each thing you have to decode.
62  // This version of the constructor does not take ownership of
63  // 'fst'.
65  const TransitionModel &trans_model,
66  const LatticeIncrementalDecoderConfig &config):
67  LatticeIncrementalDecoderTpl<FST, Token>(fst, trans_model, config) { }
68 
69  // This version of the initializer takes ownership of 'fst', and will delete
70  // it when this object is destroyed.
72  FST *fst,
73  const TransitionModel &trans_model):
74  LatticeIncrementalDecoderTpl<FST, Token>(config, fst, trans_model) { }
75 
76 
78  void *tok;
80  // note, "frame" is the frame-index of the frame you'll get the
81  // transition-id for next time, if you call TraceBackBestPath on this
82  // iterator (assuming it's not an epsilon transition). Note that this
83  // is one less than you might reasonably expect, e.g. it's -1 for
84  // the nonemitting transitions before the first frame.
85  BestPathIterator(void *t, int32 f): tok(t), frame(f) { }
86  bool Done() { return tok == NULL; }
87  };
88 
89 
98  bool GetBestPath(Lattice *ofst,
99  bool use_final_probs = true) const;
100 
101 
102 
110  BestPathIterator BestPathEnd(bool use_final_probs,
111  BaseFloat *final_cost = NULL) const;
112 
113 
122  BestPathIterator iter, LatticeArc *arc) const;
123 
125 };
126 
128 
129 
130 } // end namespace kaldi.
131 
132 #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
This is an extention to the "normal" lattice-generating decoder.
LatticeIncrementalOnlineDecoderTpl is as LatticeIncrementalDecoderTpl but also supports an efficient ...
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
KALDI_DISALLOW_COPY_AND_ASSIGN(LatticeIncrementalOnlineDecoderTpl)
kaldi::int32 int32
LatticeIncrementalOnlineDecoderTpl< fst::StdFst > LatticeIncrementalOnlineDecoder
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.
fst::VectorFst< LatticeArc > Lattice
Definition: kaldi-lattice.h:44
fst::StdArc::Label Label
fst::StdArc::Weight Weight
The normal decoder, lattice-faster-decoder.h, sometimes has an issue when doing real-time application...
LatticeIncrementalOnlineDecoderTpl(const LatticeIncrementalDecoderConfig &config, FST *fst, const TransitionModel &trans_model)
LatticeIncrementalOnlineDecoderTpl(const FST &fst, const TransitionModel &trans_model, const LatticeIncrementalDecoderConfig &config)
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...
bool GetBestPath(Lattice *ofst, bool use_final_probs=true) const
Outputs an FST corresponding to the single best path through the lattice.