This is the "normal" lattice-generating decoder. More...
#include <lattice-faster-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 | |
LatticeFasterDecoderTpl (const FST &fst, const LatticeFasterDecoderConfig &config) | |
LatticeFasterDecoderTpl (const LatticeFasterDecoderConfig &config, FST *fst) | |
void | SetOptions (const LatticeFasterDecoderConfig &config) |
const LatticeFasterDecoderConfig & | GetOptions () const |
~LatticeFasterDecoderTpl () | |
bool | Decode (DecodableInterface *decodable) |
Decodes until there are no more frames left in the "decodable" object. More... | |
bool | ReachedFinal () const |
says whether a final-state was active on the last frame. More... | |
bool | GetBestPath (Lattice *ofst, bool use_final_probs=true) const |
Outputs an FST corresponding to the single best path through the lattice. More... | |
bool | GetRawLattice (Lattice *ofst, bool use_final_probs=true) const |
Outputs an FST corresponding to the raw, state-level tracebacks. More... | |
bool | GetLattice (CompactLattice *ofst, bool use_final_probs=true) const |
[Deprecated, users should now use GetRawLattice and determinize it themselves, e.g. More... | |
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... | |
void | FinalizeDecoding () |
This function may be optionally called after AdvanceDecoding(), when you do not plan to decode any further. More... | |
BaseFloat | FinalRelativeCost () const |
FinalRelativeCost() serves the same purpose as ReachedFinal(), but gives more information. More... | |
int32 | NumFramesDecoded () const |
Protected Types | |
using | Elem = typename HashList< StateId, Token * >::Elem |
Protected Member Functions | |
void | PossiblyResizeHash (size_t num_toks) |
Elem * | 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) |
Processes emitting arcs for one frame. More... | |
void | ProcessNonemitting (BaseFloat cost_cutoff) |
Processes nonemitting (epsilon) arcs for one frame. More... | |
void | DeleteElems (Elem *list) |
void | ClearActiveTokens () |
KALDI_DISALLOW_COPY_AND_ASSIGN (LatticeFasterDecoderTpl) | |
Static Protected Member Functions | |
static void | DeleteForwardLinks (Token *tok) |
static void | TopSortTokens (Token *tok_list, std::vector< Token *> *topsorted_list) |
Protected Attributes | |
HashList< StateId, Token * > | toks_ |
std::vector< TokenList > | active_toks_ |
std::vector< const Elem *> | queue_ |
std::vector< BaseFloat > | tmp_array_ |
const FST * | fst_ |
bool | delete_fst_ |
std::vector< BaseFloat > | cost_offsets_ |
LatticeFasterDecoderConfig | config_ |
int32 | num_toks_ |
bool | warned_ |
bool | decoding_finalized_ |
decoding_finalized_ is true if someone called FinalizeDecoding(). More... | |
unordered_map< Token *, BaseFloat > | final_costs_ |
For the meaning of the next 3 variables, see the comment for decoding_finalized_ above., and ComputeFinalCosts(). More... | |
BaseFloat | final_relative_cost_ |
BaseFloat | final_best_cost_ |
This is the "normal" lattice-generating decoder.
See Lattice generation FasterDecoder: a more optimized decoder and SimpleDecoder: the simplest possible decoder for more information.
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 which is expected to equal 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 229 of file lattice-faster-decoder.h.
using Arc = typename FST::Arc |
Definition at line 231 of file lattice-faster-decoder.h.
Definition at line 360 of file lattice-faster-decoder.h.
using ForwardLinkT = decoder::ForwardLink<Token> |
Definition at line 235 of file lattice-faster-decoder.h.
using Label = typename Arc::Label |
Definition at line 232 of file lattice-faster-decoder.h.
using StateId = typename Arc::StateId |
Definition at line 233 of file lattice-faster-decoder.h.
using Weight = typename Arc::Weight |
Definition at line 234 of file lattice-faster-decoder.h.
LatticeFasterDecoderTpl | ( | const FST & | fst, |
const LatticeFasterDecoderConfig & | config | ||
) |
Definition at line 30 of file lattice-faster-decoder.cc.
LatticeFasterDecoderTpl | ( | const LatticeFasterDecoderConfig & | config, |
FST * | fst | ||
) |
Definition at line 40 of file lattice-faster-decoder.cc.
Definition at line 49 of file lattice-faster-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. If max_num_frames is specified, it specifies the maximum number of frames the function will decode before returning.
Definition at line 580 of file lattice-faster-decoder.cc.
Referenced by SingleUtteranceNnet2Decoder::AdvanceDecoding(), SingleUtteranceGmmDecoder::AdvanceDecoding(), LatticeFasterDecoderTpl< fst::StdFst, decoder::BackpointerToken >::AdvanceDecoding(), NnetBatchDecoder::Decode(), and SingleUtteranceNnet2DecoderThreaded::RunDecoderSearchInternal().
|
protected |
Definition at line 899 of file lattice-faster-decoder.cc.
|
protected |
Definition at line 536 of file lattice-faster-decoder.cc.
bool Decode | ( | DecodableInterface * | decodable | ) |
Decodes until there are no more frames left in the "decodable" object.
note, this may block waiting for input if the "decodable" object blocks. Returns true if any kind of traceback is available (not necessarily from a final state).
Definition at line 79 of file lattice-faster-decoder.cc.
Referenced by kaldi::DecodeUtteranceLatticeFaster(), and DecodeUtteranceLatticeFasterClass::operator()().
|
protected |
Definition at line 891 of file lattice-faster-decoder.cc.
|
inlinestaticprotected |
Definition at line 808 of file lattice-faster-decoder.cc.
void FinalizeDecoding | ( | ) |
This function may be optionally called after AdvanceDecoding(), when you do not plan to decode any further.
It does an extra pruning step that will help to prune the lattices output by GetLattice and (particularly) GetRawLattice more completely, particularly toward the end of the utterance. If you call this, you cannot call AdvanceDecoding again (it will fail), and you cannot call GetLattice() and related functions with use_final_probs = false. Used to be called PruneActiveTokensFinal().
Definition at line 625 of file lattice-faster-decoder.cc.
Referenced by SingleUtteranceNnet2Decoder::FinalizeDecoding(), SingleUtteranceGmmDecoder::FinalizeDecoding(), and SingleUtteranceNnet2DecoderThreaded::FinalizeDecoding().
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 461 of file lattice-faster-decoder.cc.
Referenced by SingleUtteranceNnet2DecoderThreaded::GetBestPath(), and SingleUtteranceNnet2DecoderThreaded::GetLattice().
|
inlineprotected |
Definition at line 253 of file lattice-faster-decoder.cc.
Outputs an FST corresponding to the single best path through the lattice.
Returns true if result is nonempty (using the return status is deprecated, it will become void). If "use_final_probs" is true AND we reached the final-state of the graph then it will include those as final-probs, else it will treat all final-probs as one. Note: this just calls GetRawLattice() and figures out the shortest path.
Definition at line 95 of file lattice-faster-decoder.cc.
Referenced by kaldi::DecodeUtteranceLatticeFaster(), and DecodeUtteranceLatticeFasterClass::~DecodeUtteranceLatticeFasterClass().
|
protected |
Gets the weight cutoff. Also counts the active tokens.
Definition at line 644 of file lattice-faster-decoder.cc.
bool GetLattice | ( | CompactLattice * | ofst, |
bool | use_final_probs = true |
||
) | const |
[Deprecated, users should now use GetRawLattice and determinize it themselves, e.g.
using DeterminizeLatticePhonePrunedWrapper]. Outputs an FST corresponding to the lattice-determinized lattice (one path per word sequence). Returns true if result is nonempty. If "use_final_probs" is true AND we reached the final-state of the graph then it will include those as final-probs, else it will treat all final-probs as one.
Definition at line 196 of file lattice-faster-decoder.cc.
|
inline |
Definition at line 252 of file lattice-faster-decoder.h.
Referenced by kaldi::DecodeUtteranceLatticeFaster(), and DecodeUtteranceLatticeFasterClass::operator()().
Outputs an FST corresponding to the raw, state-level tracebacks.
Returns true if result is nonempty. If "use_final_probs" is true AND we reached the final-state of the graph then it will include those as final-probs, else it will treat all final-probs as one. The raw lattice will be topologically sorted.
See also GetRawLatticePruned in lattice-faster-online-decoder.h, which also supports a pruning beam, in case for some reason you want it pruned tighter than the regular lattice beam. We could put that here in future needed.
Definition at line 106 of file lattice-faster-decoder.cc.
Referenced by NnetBatchDecoder::Decode(), kaldi::DecodeUtteranceLatticeFaster(), SingleUtteranceNnet2Decoder::GetLattice(), SingleUtteranceGmmDecoder::GetLattice(), SingleUtteranceNnet2DecoderThreaded::GetLattice(), and DecodeUtteranceLatticeFasterClass::operator()().
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 56 of file lattice-faster-decoder.cc.
Referenced by NnetBatchDecoder::Decode(), SingleUtteranceGmmDecoder::SingleUtteranceGmmDecoder(), SingleUtteranceNnet2Decoder::SingleUtteranceNnet2Decoder(), and SingleUtteranceNnet2DecoderThreaded::SingleUtteranceNnet2DecoderThreaded().
|
protected |
|
inline |
Definition at line 340 of file lattice-faster-decoder.h.
Referenced by SingleUtteranceGmmDecoder::AdvanceDecoding(), SingleUtteranceGmmDecoder::EstimateFmllr(), SingleUtteranceNnet2DecoderThreaded::GetBestPath(), SingleUtteranceGmmDecoder::GetGaussianPosteriors(), SingleUtteranceNnet2DecoderThreaded::GetLattice(), SingleUtteranceNnet2Decoder::NumFramesDecoded(), SingleUtteranceNnet2DecoderThreaded::NumFramesDecoded(), and SingleUtteranceNnet2DecoderThreaded::RunDecoderSearchInternal().
|
protected |
Definition at line 219 of file lattice-faster-decoder.cc.
|
protected |
Processes emitting arcs for one frame.
Propagates from prev_toks_ to cur_toks_. Returns the cost cutoff for subsequent ProcessNonemitting() to use.
Definition at line 714 of file lattice-faster-decoder.cc.
|
protected |
Processes nonemitting (epsilon) arcs for one frame.
Called after ProcessEmitting() on each frame. The cost cutoff is computed by the preceding ProcessEmitting().
Definition at line 820 of file lattice-faster-decoder.cc.
|
protected |
Definition at line 506 of file lattice-faster-decoder.cc.
|
protected |
Definition at line 299 of file lattice-faster-decoder.cc.
|
protected |
Definition at line 376 of file lattice-faster-decoder.cc.
|
protected |
Definition at line 479 of file lattice-faster-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 267 of file lattice-faster-decoder.h.
Referenced by NnetBatchDecoder::Decode(), kaldi::DecodeUtteranceLatticeFaster(), and DecodeUtteranceLatticeFasterClass::operator()().
|
inline |
Definition at line 248 of file lattice-faster-decoder.h.
|
staticprotected |
Definition at line 917 of file lattice-faster-decoder.cc.
|
protected |
Definition at line 461 of file lattice-faster-decoder.h.
|
protected |
Definition at line 477 of file lattice-faster-decoder.h.
|
protected |
Definition at line 473 of file lattice-faster-decoder.h.
|
protected |
decoding_finalized_ is true if someone called FinalizeDecoding().
[note, calling this is optional]. If true, it's forbidden to decode more. Also, if this is set, then the output of ComputeFinalCosts() is in the next three variables. The reason we need to do this is that after FinalizeDecoding() calls PruneTokensForFrame() for the final frame, some of the tokens on the last frame are freed, so we free the list from toks_ to avoid having dangling pointers hanging around.
Definition at line 488 of file lattice-faster-decoder.h.
|
protected |
Definition at line 471 of file lattice-faster-decoder.h.
|
protected |
Definition at line 493 of file lattice-faster-decoder.h.
|
protected |
For the meaning of the next 3 variables, see the comment for decoding_finalized_ above., and ComputeFinalCosts().
Definition at line 491 of file lattice-faster-decoder.h.
|
protected |
Definition at line 492 of file lattice-faster-decoder.h.
|
protected |
Definition at line 468 of file lattice-faster-decoder.h.
|
protected |
Definition at line 478 of file lattice-faster-decoder.h.
|
protected |
Definition at line 464 of file lattice-faster-decoder.h.
|
protected |
Definition at line 465 of file lattice-faster-decoder.h.
Definition at line 459 of file lattice-faster-decoder.h.
|
protected |
Definition at line 479 of file lattice-faster-decoder.h.