This is an extention to the "normal" lattice-generating decoder. More...
#include <lattice-incremental-decoder.h>
Classes | |
struct | TokenList |
Public Types | |
using | Arc = typename FST::Arc |
using | Label = typename Arc::Label |
using | StateId = typename Arc::StateId |
using | Weight = typename Arc::Weight |
using | ForwardLinkT = decoder::ForwardLink< Token > |
Public Member Functions | |
LatticeIncrementalDecoderTpl (const FST &fst, const TransitionModel &trans_model, const LatticeIncrementalDecoderConfig &config) | |
LatticeIncrementalDecoderTpl (const LatticeIncrementalDecoderConfig &config, FST *fst, const TransitionModel &trans_model) | |
void | SetOptions (const LatticeIncrementalDecoderConfig &config) |
const LatticeIncrementalDecoderConfig & | GetOptions () const |
~LatticeIncrementalDecoderTpl () | |
bool | Decode (DecodableInterface *decodable) |
CAUTION: it's unlikely that you will ever want to call this function. More... | |
bool | ReachedFinal () const |
says whether a final-state was active on the last frame. More... | |
const CompactLattice & | GetLattice (int32 num_frames_to_include, bool use_final_probs=false) |
This decoder has no GetBestPath() function. More... | |
int | NumFramesInLattice () const |
void | InitDecoding () |
InitDecoding initializes the decoding, and should only be used if you intend to call AdvanceDecoding(). More... | |
void | AdvanceDecoding (DecodableInterface *decodable, int32 max_num_frames=-1) |
This will decode until there are no more frames ready in the decodable object. More... | |
BaseFloat | FinalRelativeCost () const |
FinalRelativeCost() serves the same purpose as ReachedFinal(), but gives more information. More... | |
int32 | NumFramesDecoded () const |
Returns the number of frames decoded so far. More... | |
void | FinalizeDecoding () |
Finalizes the decoding, doing an extra pruning step on the last frame that uses the final-probs. More... | |
Protected Types | |
using | Elem = typename HashList< StateId, Token * >::Elem |
Protected Member Functions | |
void | PossiblyResizeHash (size_t num_toks) |
Token * | FindOrAddToken (StateId state, int32 frame_plus_one, BaseFloat tot_cost, Token *backpointer, bool *changed) |
void | PruneForwardLinks (int32 frame_plus_one, bool *extra_costs_changed, bool *links_pruned, BaseFloat delta) |
void | ComputeFinalCosts (unordered_map< Token *, BaseFloat > *final_costs, BaseFloat *final_relative_cost, BaseFloat *final_best_cost) const |
void | PruneForwardLinksFinal () |
void | PruneTokensForFrame (int32 frame_plus_one) |
void | PruneActiveTokens (BaseFloat delta) |
BaseFloat | GetCutoff (Elem *list_head, size_t *tok_count, BaseFloat *adaptive_beam, Elem **best_elem) |
Gets the weight cutoff. Also counts the active tokens. More... | |
BaseFloat | ProcessEmitting (DecodableInterface *decodable) |
void | ProcessNonemitting (BaseFloat cost_cutoff) |
Label | AllocateNewTokenLabel () |
void | DeleteElems (Elem *list) |
void | ClearActiveTokens () |
int32 | GetNumToksForFrame (int32 frame) |
void | UpdateLatticeDeterminization () |
UpdateLatticeDeterminization() ensures the work of determinization is kept up to date so that when you do need the lattice you can get it fast. More... | |
KALDI_DISALLOW_COPY_AND_ASSIGN (LatticeIncrementalDecoderTpl) | |
Static Protected Member Functions | |
static void | DeleteForwardLinks (Token *tok) |
NOTE: for parts the internal implementation that are shared with LatticeFasterDecoer, we have removed the comments. More... | |
Protected Attributes | |
HashList< StateId, Token * > | toks_ |
std::vector< TokenList > | active_toks_ |
std::vector< StateId > | queue_ |
std::vector< BaseFloat > | tmp_array_ |
const FST * | fst_ |
bool | delete_fst_ |
std::vector< BaseFloat > | cost_offsets_ |
int32 | num_toks_ |
bool | warned_ |
bool | decoding_finalized_ |
unordered_map< Token *, BaseFloat > | final_costs_ |
BaseFloat | final_relative_cost_ |
BaseFloat | final_best_cost_ |
LatticeIncrementalDecoderConfig | config_ |
LatticeIncrementalDeterminizer | determinizer_ |
Much of the the incremental determinization algorithm is encapsulated in the determinize_ object. More... | |
unordered_map< Token *, StateId > | temp_token_map_ |
int32 | num_frames_in_lattice_ |
num_frames_in_lattice_ is the highest `num_frames_to_include_` argument for any prior call to GetLattice(). More... | |
unordered_map< Token *, Label > | token2label_map_ |
unordered_map< Token *, Label > | token2label_map_temp_ |
Label | next_token_label_ |
This is an extention to the "normal" lattice-generating decoder.
See Lattice generation FasterDecoder: a more optimized decoder and SimpleDecoder: the simplest possible decoder for more information.
The main difference is the incremental determinization which will be discussed in the function GetLattice(). This means that the work of determinizatin isn't done all at once at the end of the file, but incrementally while decoding. See the comment at the top of this file for more explanation.
The decoder is templated on the FST type and the token type. The token type will normally be StdToken, but also may be BackpointerToken which is to support quick lookup of the current best path (see lattice-faster-online-decoder.h)
The FST you invoke this decoder with is expected to be of type Fst::Fst<fst::StdArc>, a.k.a. StdFst, or GrammarFst. If you invoke it with FST == StdFst and it notices that the actual FST type is fst::VectorFst<fst::StdArc> or fst::ConstFst<fst::StdArc>, the decoder object will internally cast itself to one that is templated on those more specific types; this is an optimization for speed.
Definition at line 465 of file lattice-incremental-decoder.h.
using Arc = typename FST::Arc |
Definition at line 467 of file lattice-incremental-decoder.h.
Definition at line 625 of file lattice-incremental-decoder.h.
using ForwardLinkT = decoder::ForwardLink<Token> |
Definition at line 471 of file lattice-incremental-decoder.h.
using Label = typename Arc::Label |
Definition at line 468 of file lattice-incremental-decoder.h.
using StateId = typename Arc::StateId |
Definition at line 469 of file lattice-incremental-decoder.h.
using Weight = typename Arc::Weight |
Definition at line 470 of file lattice-incremental-decoder.h.
LatticeIncrementalDecoderTpl | ( | const FST & | fst, |
const TransitionModel & | trans_model, | ||
const LatticeIncrementalDecoderConfig & | config | ||
) |
Definition at line 28 of file lattice-incremental-decoder.cc.
LatticeIncrementalDecoderTpl | ( | const LatticeIncrementalDecoderConfig & | config, |
FST * | fst, | ||
const TransitionModel & | trans_model | ||
) |
Definition at line 41 of file lattice-incremental-decoder.cc.
Definition at line 54 of file lattice-incremental-decoder.cc.
void AdvanceDecoding | ( | DecodableInterface * | decodable, |
int32 | max_num_frames = -1 |
||
) |
This will decode until there are no more frames ready in the decodable object.
You can keep calling it each time more frames become available (this is the normal pattern in a real-time/online decoding scenario). If max_num_frames is specified, it specifies the maximum number of frames the function will decode before returning.
Definition at line 539 of file lattice-incremental-decoder.cc.
Referenced by LatticeIncrementalDecoderTpl< FST, decoder::BackpointerToken >::AdvanceDecoding().
|
inlineprotected |
Definition at line 684 of file lattice-incremental-decoder.h.
|
protected |
Definition at line 852 of file lattice-incremental-decoder.cc.
|
protected |
Definition at line 492 of file lattice-incremental-decoder.cc.
bool Decode | ( | DecodableInterface * | decodable | ) |
CAUTION: it's unlikely that you will ever want to call this function.
In a scenario where you have the entire file and just want to decode it, there is no point using this decoder.
An example of how to do decoding together with incremental determinization. It decodes until there are no more frames left in the "decodable" object.
In this example, config_.determinize_delay, config_.determinize_period and config_.determinize_max_active are used to determine the time to call GetLattice().
Users will probably want to use appropriate combinations of AdvanceDecoding() and GetLattice() to build their application; this just gives you some idea how.
The function returns true if any kind of traceback is available (not necessarily from a final state).
Definition at line 121 of file lattice-incremental-decoder.cc.
Referenced by kaldi::DecodeUtteranceLatticeIncremental().
|
protected |
Definition at line 843 of file lattice-incremental-decoder.cc.
|
inlinestaticprotected |
NOTE: for parts the internal implementation that are shared with LatticeFasterDecoer, we have removed the comments.
Definition at line 765 of file lattice-incremental-decoder.cc.
void FinalizeDecoding | ( | ) |
Finalizes the decoding, doing an extra pruning step on the last frame that uses the final-probs.
May be called only once.
Definition at line 588 of file lattice-incremental-decoder.cc.
BaseFloat FinalRelativeCost | ( | ) | const |
FinalRelativeCost() serves the same purpose as ReachedFinal(), but gives more information.
It returns the difference between the best (final-cost plus cost) of any token on the final frame, and the best cost of any token on the final frame. If it is infinity it means no final-states were present on the final frame. It will usually be nonnegative. If it not too positive (e.g. < 5 is my first guess, but this is not tested) you can take it as a good indication that we reached the final-state with reasonable likelihood.
Definition at line 409 of file lattice-incremental-decoder.cc.
|
inlineprotected |
Definition at line 197 of file lattice-incremental-decoder.cc.
|
protected |
Gets the weight cutoff. Also counts the active tokens.
Definition at line 606 of file lattice-incremental-decoder.cc.
const CompactLattice & GetLattice | ( | int32 | num_frames_to_include, |
bool | use_final_probs = false |
||
) |
This decoder has no GetBestPath() function.
If you need that functionality you should probably use lattice-incremental-online-decoder.h, which makes it very efficient to obtain the best path. This GetLattice() function returns the lattice containing `num_frames_to_decode` frames; this will be all frames decoded so far, if you let num_frames_to_decode == NumFramesDecoded(), but it will generally be better to make it a few frames less than that to avoid the lattice having too many active states at the end.
[in] | num_frames_to_include | The number of frames that you want to be included in the lattice. Must be >= NumFramesInLattice() and <= NumFramesDecoded(). |
[in] | use_final_probs | True if you want the final-probs of HCLG to be included in the output lattice. Must not be set to true if num_frames_to_include != NumFramesDecoded(). Must be set to true if you have previously called FinalizeDecoding(). |
(If no state was final on frame `num_frames_to_include`, the final-probs won't be included regardless of `use_final_probs`; you can test whether this was the case by calling ReachedFinal().
See also UpdateLatticeDeterminizaton(). Caution: this const ref is only valid until the next time you call AdvanceDecoding() or GetLattice().
CAUTION: the lattice may contain disconnnected states; you should call Connect() on the output before writing it out.
Definition at line 870 of file lattice-incremental-decoder.cc.
Referenced by kaldi::DecodeUtteranceLatticeIncremental().
Definition at line 1094 of file lattice-incremental-decoder.cc.
|
inline |
Definition at line 486 of file lattice-incremental-decoder.h.
void InitDecoding | ( | ) |
InitDecoding initializes the decoding, and should only be used if you intend to call AdvanceDecoding().
If you call Decode(), you don't need to call this. You can also call InitDecoding if you have already decoded an utterance and want to start with a new utterance.
Definition at line 61 of file lattice-incremental-decoder.cc.
|
protected |
|
inline |
Returns the number of frames decoded so far.
Definition at line 600 of file lattice-incremental-decoder.h.
Referenced by kaldi::DecodeUtteranceLatticeIncremental().
|
inline |
Definition at line 569 of file lattice-incremental-decoder.h.
|
protected |
Definition at line 151 of file lattice-incremental-decoder.cc.
|
protected |
Definition at line 675 of file lattice-incremental-decoder.cc.
|
protected |
Definition at line 776 of file lattice-incremental-decoder.cc.
|
protected |
Definition at line 451 of file lattice-incremental-decoder.cc.
|
protected |
Definition at line 243 of file lattice-incremental-decoder.cc.
|
protected |
Definition at line 322 of file lattice-incremental-decoder.cc.
|
protected |
Definition at line 420 of file lattice-incremental-decoder.cc.
|
inline |
says whether a final-state was active on the last frame.
If it was not, the lattice (or traceback) will end with states that are not final-states.
Definition at line 514 of file lattice-incremental-decoder.h.
Referenced by kaldi::DecodeUtteranceLatticeIncremental().
|
inline |
Definition at line 484 of file lattice-incremental-decoder.h.
|
protected |
UpdateLatticeDeterminization() ensures the work of determinization is kept up to date so that when you do need the lattice you can get it fast.
It uses the configuration values `determinize_delay`, `determinize_max_delay` and `determinize_min_chunk_size` to decide whether and when to call GetLattice(). You can safely call this as often as you want (e.g. after each time you call AdvanceDecoding(); it won't do subtantially more work if it is called frequently.
Definition at line 86 of file lattice-incremental-decoder.cc.
|
protected |
Definition at line 643 of file lattice-incremental-decoder.h.
|
protected |
Definition at line 661 of file lattice-incremental-decoder.h.
|
protected |
Definition at line 648 of file lattice-incremental-decoder.h.
|
protected |
Definition at line 651 of file lattice-incremental-decoder.h.
|
protected |
Definition at line 647 of file lattice-incremental-decoder.h.
|
protected |
Much of the the incremental determinization algorithm is encapsulated in the determinize_ object.
Definition at line 664 of file lattice-incremental-decoder.h.
|
protected |
Definition at line 655 of file lattice-incremental-decoder.h.
|
protected |
Definition at line 653 of file lattice-incremental-decoder.h.
|
protected |
Definition at line 654 of file lattice-incremental-decoder.h.
|
protected |
Definition at line 646 of file lattice-incremental-decoder.h.
|
protected |
Definition at line 682 of file lattice-incremental-decoder.h.
|
protected |
num_frames_in_lattice_ is the highest `num_frames_to_include_` argument for any prior call to GetLattice().
Definition at line 672 of file lattice-incremental-decoder.h.
|
protected |
Definition at line 649 of file lattice-incremental-decoder.h.
|
protected |
Definition at line 644 of file lattice-incremental-decoder.h.
|
protected |
Definition at line 668 of file lattice-incremental-decoder.h.
|
protected |
Definition at line 645 of file lattice-incremental-decoder.h.
|
protected |
Definition at line 676 of file lattice-incremental-decoder.h.
|
protected |
Definition at line 679 of file lattice-incremental-decoder.h.
Definition at line 642 of file lattice-incremental-decoder.h.
|
protected |
Definition at line 650 of file lattice-incremental-decoder.h.