Simplest possible decoder, included largely for didactic purposes and as a means to debug more highly optimized decoders. More...
#include <simple-decoder.h>
Classes | |
class | Token |
Public Types | |
typedef fst::StdArc | StdArc |
typedef StdArc::Weight | StdWeight |
typedef StdArc::Label | Label |
typedef StdArc::StateId | StateId |
Public Member Functions | |
SimpleDecoder (const fst::Fst< fst::StdArc > &fst, BaseFloat beam) | |
~SimpleDecoder () | |
bool | Decode (DecodableInterface *decodable) |
Decode this utterance. More... | |
bool | ReachedFinal () const |
bool | GetBestPath (Lattice *fst_out, bool use_final_probs=true) const |
BaseFloat | FinalRelativeCost () const |
*** The next functions are from the "new interface". *** 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, but if max_num_frames is >= 0 it will decode no more than that many frames. More... | |
int32 | NumFramesDecoded () const |
Returns the number of frames already decoded. More... | |
Private Member Functions | |
void | ProcessEmitting (DecodableInterface *decodable) |
void | ProcessNonemitting () |
KALDI_DISALLOW_COPY_AND_ASSIGN (SimpleDecoder) | |
Static Private Member Functions | |
static void | ClearToks (unordered_map< StateId, Token *> &toks) |
static void | PruneToks (BaseFloat beam, unordered_map< StateId, Token *> *toks) |
Private Attributes | |
unordered_map< StateId, Token * > | cur_toks_ |
unordered_map< StateId, Token * > | prev_toks_ |
const fst::Fst< fst::StdArc > & | fst_ |
BaseFloat | beam_ |
int32 | num_frames_decoded_ |
Simplest possible decoder, included largely for didactic purposes and as a means to debug more highly optimized decoders.
See SimpleDecoder: the simplest possible decoder for more information.
Definition at line 37 of file simple-decoder.h.
typedef StdArc::Label Label |
Definition at line 41 of file simple-decoder.h.
typedef StdArc::StateId StateId |
Definition at line 42 of file simple-decoder.h.
typedef fst::StdArc StdArc |
Definition at line 39 of file simple-decoder.h.
typedef StdArc::Weight StdWeight |
Definition at line 40 of file simple-decoder.h.
|
inline |
Definition at line 44 of file simple-decoder.h.
References SimpleDecoder::AdvanceDecoding(), SimpleDecoder::Decode(), SimpleDecoder::FinalRelativeCost(), SimpleDecoder::GetBestPath(), SimpleDecoder::InitDecoding(), SimpleDecoder::ReachedFinal(), and SimpleDecoder::~SimpleDecoder().
~SimpleDecoder | ( | ) |
Definition at line 27 of file simple-decoder.cc.
References SimpleDecoder::ClearToks(), SimpleDecoder::cur_toks_, and SimpleDecoder::prev_toks_.
Referenced by SimpleDecoder::SimpleDecoder().
void AdvanceDecoding | ( | DecodableInterface * | decodable, |
int32 | max_num_frames = -1 |
||
) |
This will decode until there are no more frames ready in the decodable object, but if max_num_frames is >= 0 it will decode no more than that many frames.
If it returns false, then no tokens are alive, which is a kind of error state.
Definition at line 52 of file simple-decoder.cc.
References SimpleDecoder::beam_, SimpleDecoder::ClearToks(), SimpleDecoder::cur_toks_, KALDI_ASSERT, SimpleDecoder::num_frames_decoded_, DecodableInterface::NumFramesReady(), SimpleDecoder::prev_toks_, SimpleDecoder::ProcessEmitting(), SimpleDecoder::ProcessNonemitting(), and SimpleDecoder::PruneToks().
Referenced by SimpleDecoder::Decode(), and SimpleDecoder::SimpleDecoder().
Definition at line 258 of file simple-decoder.cc.
References SimpleDecoder::Token::TokenDelete().
Referenced by SimpleDecoder::AdvanceDecoding(), SimpleDecoder::InitDecoding(), and SimpleDecoder::~SimpleDecoder().
bool Decode | ( | DecodableInterface * | decodable | ) |
Decode this utterance.
Returns true if any tokens reached the end of the file (regardless of whether they are in a final state); query ReachedFinal() after Decode() to see whether we reached a final state.
Definition at line 33 of file simple-decoder.cc.
References SimpleDecoder::AdvanceDecoding(), SimpleDecoder::cur_toks_, and SimpleDecoder::InitDecoding().
Referenced by main(), and SimpleDecoder::SimpleDecoder().
BaseFloat FinalRelativeCost | ( | ) | const |
*** The next functions are from the "new interface". ***
FinalRelativeCost() serves the same function 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.
Definition at line 87 of file simple-decoder.cc.
References SimpleDecoder::cur_toks_, SimpleDecoder::fst_, and KALDI_WARN.
Referenced by SimpleDecoder::SimpleDecoder().
Definition at line 117 of file simple-decoder.cc.
References SimpleDecoder::Token::arc_, SimpleDecoder::Token::cost_, SimpleDecoder::cur_toks_, SimpleDecoder::fst_, rnnlm::i, KALDI_ASSERT, LatticeWeightTpl< BaseFloat >::One(), SimpleDecoder::Token::prev_, SimpleDecoder::ReachedFinal(), and fst::RemoveEpsLocal().
Referenced by main(), and SimpleDecoder::SimpleDecoder().
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 call InitDecoding if you have already decoded an utterance and want to start with a new utterance.
Definition at line 39 of file simple-decoder.cc.
References SimpleDecoder::ClearToks(), SimpleDecoder::cur_toks_, SimpleDecoder::fst_, KALDI_ASSERT, SimpleDecoder::num_frames_decoded_, SimpleDecoder::prev_toks_, and SimpleDecoder::ProcessNonemitting().
Referenced by SimpleDecoder::Decode(), and SimpleDecoder::SimpleDecoder().
|
private |
|
inline |
Returns the number of frames already decoded.
Definition at line 89 of file simple-decoder.h.
References SimpleDecoder::num_frames_decoded_.
|
private |
Definition at line 167 of file simple-decoder.cc.
References SimpleDecoder::Token::arc_, SimpleDecoder::beam_, SimpleDecoder::Token::cost_, SimpleDecoder::cur_toks_, SimpleDecoder::fst_, KALDI_ASSERT, DecodableInterface::LogLikelihood(), SimpleDecoder::num_frames_decoded_, SimpleDecoder::prev_toks_, and SimpleDecoder::Token::TokenDelete().
Referenced by SimpleDecoder::AdvanceDecoding(), and SimpleDecoder::Token::TokenDelete().
|
private |
Definition at line 208 of file simple-decoder.cc.
References SimpleDecoder::Token::arc_, SimpleDecoder::beam_, SimpleDecoder::Token::cost_, SimpleDecoder::cur_toks_, SimpleDecoder::fst_, KALDI_ASSERT, and SimpleDecoder::Token::TokenDelete().
Referenced by SimpleDecoder::AdvanceDecoding(), SimpleDecoder::InitDecoding(), and SimpleDecoder::Token::TokenDelete().
Definition at line 267 of file simple-decoder.cc.
References rnnlm::i, KALDI_VLOG, and SimpleDecoder::Token::TokenDelete().
Referenced by SimpleDecoder::AdvanceDecoding().
bool ReachedFinal | ( | ) | const |
Definition at line 76 of file simple-decoder.cc.
References SimpleDecoder::cur_toks_, and SimpleDecoder::fst_.
Referenced by SimpleDecoder::GetBestPath(), main(), and SimpleDecoder::SimpleDecoder().
|
private |
Definition at line 141 of file simple-decoder.h.
Referenced by SimpleDecoder::AdvanceDecoding(), SimpleDecoder::ProcessEmitting(), and SimpleDecoder::ProcessNonemitting().
Definition at line 138 of file simple-decoder.h.
Referenced by SimpleDecoder::AdvanceDecoding(), SimpleDecoder::Decode(), SimpleDecoder::FinalRelativeCost(), SimpleDecoder::GetBestPath(), SimpleDecoder::InitDecoding(), SimpleDecoder::ProcessEmitting(), SimpleDecoder::ProcessNonemitting(), SimpleDecoder::ReachedFinal(), and SimpleDecoder::~SimpleDecoder().
|
private |
Definition at line 140 of file simple-decoder.h.
Referenced by SimpleDecoder::FinalRelativeCost(), SimpleDecoder::GetBestPath(), SimpleDecoder::InitDecoding(), SimpleDecoder::ProcessEmitting(), SimpleDecoder::ProcessNonemitting(), and SimpleDecoder::ReachedFinal().
|
private |
Definition at line 143 of file simple-decoder.h.
Referenced by SimpleDecoder::AdvanceDecoding(), SimpleDecoder::InitDecoding(), SimpleDecoder::NumFramesDecoded(), and SimpleDecoder::ProcessEmitting().
Definition at line 139 of file simple-decoder.h.
Referenced by SimpleDecoder::AdvanceDecoding(), SimpleDecoder::InitDecoding(), SimpleDecoder::ProcessEmitting(), and SimpleDecoder::~SimpleDecoder().