31 template <
typename FST>
33 bool use_final_probs)
const {
39 StateId state = olat->AddState();
41 while (!iter.
Done()) {
43 iter = TraceBackBestPath(iter, &arc);
44 arc.nextstate = state;
45 StateId new_state = olat->AddState();
46 olat->AddArc(new_state, arc);
49 olat->SetStart(state);
53 template <
typename FST>
57 if (this->decoding_finalized_ && !use_final_probs)
58 KALDI_ERR <<
"You cannot call FinalizeDecoding() and then call " 59 <<
"BestPathEnd() with use_final_probs == false";
61 "You cannot call BestPathEnd if no frames were decoded.");
63 unordered_map<Token*, BaseFloat> final_costs_local;
65 const unordered_map<Token*, BaseFloat> &final_costs =
66 (this->decoding_finalized_ ? this->final_costs_ :final_costs_local);
67 if (!this->decoding_finalized_ && use_final_probs)
68 this->ComputeFinalCosts(&final_costs_local, NULL, NULL);
72 BaseFloat best_cost = std::numeric_limits<BaseFloat>::infinity();
74 Token *best_tok = NULL;
75 for (
Token *tok = this->active_toks_.back().toks;
76 tok != NULL; tok = tok->
next) {
77 BaseFloat cost = tok->tot_cost, final_cost = 0.0;
78 if (use_final_probs && !final_costs.empty()) {
81 typename unordered_map<Token*, BaseFloat>::const_iterator
82 iter = final_costs.find(tok);
83 if (iter != final_costs.end()) {
84 final_cost = iter->second;
87 cost = std::numeric_limits<BaseFloat>::infinity();
90 if (cost < best_cost) {
93 best_final_cost = final_cost;
96 if (best_tok == NULL) {
101 if (final_cost_out == NULL)
102 *final_cost_out = best_final_cost;
107 template <
typename FST>
113 if (tok->backpointer != NULL) {
115 for (link = tok->backpointer->links;
116 link != NULL; link = link->
next) {
119 oarc->olabel = link->
olabel;
123 KALDI_ASSERT(static_cast<size_t>(cur_t) < this->cost_offsets_.size());
124 acoustic_cost -= this->cost_offsets_[cur_t];
132 KALDI_ERR <<
"Error tracing best-path back (likely " 133 <<
"bug in token-pruning algorithm)";
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
fst::ArcTpl< LatticeWeight > LatticeArc
static const LatticeWeightTpl One()
LatticeIncrementalOnlineDecoderTpl is as LatticeIncrementalDecoderTpl but also supports an efficient ...
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::LatticeWeightTpl< BaseFloat > LatticeWeight
fst::VectorFst< LatticeArc > Lattice
typename Arc::StateId StateId
#define KALDI_ASSERT(cond)
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.