FasterDecoder Class Reference

#include <faster-decoder.h>

Inheritance diagram for FasterDecoder:
Collaboration diagram for FasterDecoder:

Classes

class  Token
 

Public Types

typedef fst::StdArc Arc
 
typedef Arc::Label Label
 
typedef Arc::StateId StateId
 
typedef Arc::Weight Weight
 

Public Member Functions

 FasterDecoder (const fst::Fst< fst::StdArc > &fst, const FasterDecoderOptions &config)
 
void SetOptions (const FasterDecoderOptions &config)
 
 ~FasterDecoder ()
 
void Decode (DecodableInterface *decodable)
 
bool ReachedFinal () const
 Returns true if a final state was active on the last frame. More...
 
bool GetBestPath (fst::MutableFst< LatticeArc > *fst_out, bool use_final_probs=true)
 GetBestPath gets the decoding traceback. More...
 
void InitDecoding ()
 As a new alternative to Decode(), you can call InitDecoding and then (possibly multiple times) 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...
 

Protected Types

typedef HashList< StateId, Token * >::Elem Elem
 

Protected Member Functions

double GetCutoff (Elem *list_head, size_t *tok_count, BaseFloat *adaptive_beam, Elem **best_elem)
 Gets the weight cutoff. Also counts the active tokens. More...
 
void PossiblyResizeHash (size_t num_toks)
 
double ProcessEmitting (DecodableInterface *decodable)
 
void ProcessNonemitting (double cutoff)
 
void ClearToks (Elem *list)
 
 KALDI_DISALLOW_COPY_AND_ASSIGN (FasterDecoder)
 

Protected Attributes

HashList< StateId, Token * > toks_
 
const fst::Fst< fst::StdArc > & fst_
 
FasterDecoderOptions config_
 
std::vector< const Elem *> queue_
 
std::vector< BaseFloattmp_array_
 
int32 num_frames_decoded_
 

Detailed Description

Definition at line 62 of file faster-decoder.h.

Member Typedef Documentation

◆ Arc

typedef fst::StdArc Arc

Definition at line 64 of file faster-decoder.h.

◆ Elem

typedef HashList<StateId, Token*>::Elem Elem
protected

Definition at line 150 of file faster-decoder.h.

◆ Label

typedef Arc::Label Label

Definition at line 65 of file faster-decoder.h.

◆ StateId

typedef Arc::StateId StateId

Definition at line 66 of file faster-decoder.h.

◆ Weight

typedef Arc::Weight Weight

Definition at line 67 of file faster-decoder.h.

Constructor & Destructor Documentation

◆ FasterDecoder()

FasterDecoder ( const fst::Fst< fst::StdArc > &  fst,
const FasterDecoderOptions config 
)

Definition at line 26 of file faster-decoder.cc.

References FasterDecoder::config_, FasterDecoderOptions::hash_ratio, KALDI_ASSERT, FasterDecoderOptions::max_active, FasterDecoderOptions::min_active, HashList< I, T >::SetSize(), and FasterDecoder::toks_.

27  :
28  fst_(fst), config_(opts), num_frames_decoded_(-1) {
29  KALDI_ASSERT(config_.hash_ratio >= 1.0); // less doesn't make much sense.
32  toks_.SetSize(1000); // just so on the first frame we do something reasonable.
33 }
FasterDecoderOptions config_
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
const fst::Fst< fst::StdArc > & fst_
void SetSize(size_t sz)
SetSize tells the object how many hash buckets to allocate (should typically be at least twice the nu...
Definition: hash-list-inl.h:37
HashList< StateId, Token * > toks_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ ~FasterDecoder()

~FasterDecoder ( )
inline

Definition at line 74 of file faster-decoder.h.

74 { ClearToks(toks_.Clear()); }
void ClearToks(Elem *list)
Elem * Clear()
Clears the hash and gives the head of the current list to the user; ownership is transferred to the u...
Definition: hash-list-inl.h:46
HashList< StateId, Token * > toks_

Member Function Documentation

◆ AdvanceDecoding()

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.

Definition at line 53 of file faster-decoder.cc.

References KALDI_ASSERT, FasterDecoder::num_frames_decoded_, DecodableInterface::NumFramesReady(), FasterDecoder::ProcessEmitting(), and FasterDecoder::ProcessNonemitting().

Referenced by FasterDecoder::Decode().

54  {
56  "You must call InitDecoding() before AdvanceDecoding()");
57  int32 num_frames_ready = decodable->NumFramesReady();
58  // num_frames_ready must be >= num_frames_decoded, or else
59  // the number of frames ready must have decreased (which doesn't
60  // make sense) or the decodable object changed between calls
61  // (which isn't allowed).
62  KALDI_ASSERT(num_frames_ready >= num_frames_decoded_);
63  int32 target_frames_decoded = num_frames_ready;
64  if (max_num_frames >= 0)
65  target_frames_decoded = std::min(target_frames_decoded,
66  num_frames_decoded_ + max_num_frames);
67  while (num_frames_decoded_ < target_frames_decoded) {
68  // note: ProcessEmitting() increments num_frames_decoded_
69  double weight_cutoff = ProcessEmitting(decodable);
70  ProcessNonemitting(weight_cutoff);
71  }
72 }
kaldi::int32 int32
void ProcessNonemitting(double cutoff)
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
double ProcessEmitting(DecodableInterface *decodable)

◆ ClearToks()

void ClearToks ( Elem list)
protected

Definition at line 343 of file faster-decoder.cc.

References HashList< I, T >::Delete(), FasterDecoder::Token::TokenDelete(), and FasterDecoder::toks_.

Referenced by FasterDecoder::InitDecoding(), and OnlineFasterDecoder::ResetDecoder().

343  {
344  for (Elem *e = list, *e_tail; e != NULL; e = e_tail) {
345  Token::TokenDelete(e->val);
346  e_tail = e->tail;
347  toks_.Delete(e);
348  }
349 }
static void TokenDelete(Token *tok)
HashList< StateId, Token * > toks_
HashList< StateId, Token * >::Elem Elem
void Delete(Elem *e)
Think of this like delete().
Definition: hash-list-inl.h:66

◆ Decode()

void Decode ( DecodableInterface decodable)

Definition at line 48 of file faster-decoder.cc.

References FasterDecoder::AdvanceDecoding(), and FasterDecoder::InitDecoding().

Referenced by kaldi::AlignUtteranceWrapper(), DecodeUtterance(), and main().

48  {
49  InitDecoding();
50  AdvanceDecoding(decodable);
51 }
void InitDecoding()
As a new alternative to Decode(), you can call InitDecoding and then (possibly multiple times) Advanc...
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 ...

◆ GetBestPath()

bool GetBestPath ( fst::MutableFst< LatticeArc > *  fst_out,
bool  use_final_probs = true 
)

GetBestPath gets the decoding traceback.

If "use_final_probs" is true AND we reached a final state, it limits itself to final states; otherwise it gets the most likely token not taking into account final-probs. Returns true if the output best path was not the empty FST (will only return false in unusual circumstances where no tokens survived).

Definition at line 84 of file faster-decoder.cc.

References FasterDecoder::Token::arc_, FasterDecoder::Token::cost_, FasterDecoder::fst_, HashList< I, T >::GetList(), rnnlm::i, KALDI_ASSERT, LatticeWeightTpl< BaseFloat >::One(), FasterDecoder::Token::prev_, FasterDecoder::ReachedFinal(), fst::RemoveEpsLocal(), HashList< I, T >::Elem::tail, and FasterDecoder::toks_.

Referenced by kaldi::AlignUtteranceWrapper(), DecodeUtterance(), and main().

85  {
86  // GetBestPath gets the decoding output. If "use_final_probs" is true
87  // AND we reached a final state, it limits itself to final states;
88  // otherwise it gets the most likely token not taking into
89  // account final-probs. fst_out will be empty (Start() == kNoStateId) if
90  // nothing was available. It returns true if it got output (thus, fst_out
91  // will be nonempty).
92  fst_out->DeleteStates();
93  Token *best_tok = NULL;
94  bool is_final = ReachedFinal();
95  if (!is_final) {
96  for (const Elem *e = toks_.GetList(); e != NULL; e = e->tail)
97  if (best_tok == NULL || *best_tok < *(e->val) )
98  best_tok = e->val;
99  } else {
100  double infinity = std::numeric_limits<double>::infinity(),
101  best_cost = infinity;
102  for (const Elem *e = toks_.GetList(); e != NULL; e = e->tail) {
103  double this_cost = e->val->cost_ + fst_.Final(e->key).Value();
104  if (this_cost < best_cost && this_cost != infinity) {
105  best_cost = this_cost;
106  best_tok = e->val;
107  }
108  }
109  }
110  if (best_tok == NULL) return false; // No output.
111 
112  std::vector<LatticeArc> arcs_reverse; // arcs in reverse order.
113 
114  for (Token *tok = best_tok; tok != NULL; tok = tok->prev_) {
115  BaseFloat tot_cost = tok->cost_ -
116  (tok->prev_ ? tok->prev_->cost_ : 0.0),
117  graph_cost = tok->arc_.weight.Value(),
118  ac_cost = tot_cost - graph_cost;
119  LatticeArc l_arc(tok->arc_.ilabel,
120  tok->arc_.olabel,
121  LatticeWeight(graph_cost, ac_cost),
122  tok->arc_.nextstate);
123  arcs_reverse.push_back(l_arc);
124  }
125  KALDI_ASSERT(arcs_reverse.back().nextstate == fst_.Start());
126  arcs_reverse.pop_back(); // that was a "fake" token... gives no info.
127 
128  StateId cur_state = fst_out->AddState();
129  fst_out->SetStart(cur_state);
130  for (ssize_t i = static_cast<ssize_t>(arcs_reverse.size())-1; i >= 0; i--) {
131  LatticeArc arc = arcs_reverse[i];
132  arc.nextstate = fst_out->AddState();
133  fst_out->AddArc(cur_state, arc);
134  cur_state = arc.nextstate;
135  }
136  if (is_final && use_final_probs) {
137  Weight final_weight = fst_.Final(best_tok->arc_.nextstate);
138  fst_out->SetFinal(cur_state, LatticeWeight(final_weight.Value(), 0.0));
139  } else {
140  fst_out->SetFinal(cur_state, LatticeWeight::One());
141  }
142  RemoveEpsLocal(fst_out);
143  return true;
144 }
fst::ArcTpl< LatticeWeight > LatticeArc
Definition: kaldi-lattice.h:40
static const LatticeWeightTpl One()
void RemoveEpsLocal(MutableFst< Arc > *fst)
RemoveEpsLocal remove some (but not necessarily all) epsilons in an FST, using an algorithm that is g...
fst::LatticeWeightTpl< BaseFloat > LatticeWeight
Definition: kaldi-lattice.h:32
const fst::Fst< fst::StdArc > & fst_
float BaseFloat
Definition: kaldi-types.h:29
const Elem * GetList() const
Gives the head of the current list to the user.
Definition: hash-list-inl.h:61
HashList< StateId, Token * > toks_
HashList< StateId, Token * >::Elem Elem
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
Arc::StateId StateId
bool ReachedFinal() const
Returns true if a final state was active on the last frame.

◆ GetCutoff()

double GetCutoff ( Elem list_head,
size_t tok_count,
BaseFloat adaptive_beam,
Elem **  best_elem 
)
protected

Gets the weight cutoff. Also counts the active tokens.

Definition at line 148 of file faster-decoder.cc.

References FasterDecoderOptions::beam, FasterDecoderOptions::beam_delta, FasterDecoder::config_, count, FasterDecoderOptions::max_active, FasterDecoderOptions::min_active, HashList< I, T >::Elem::tail, and FasterDecoder::tmp_array_.

Referenced by FasterDecoder::ProcessEmitting().

149  {
150  double best_cost = std::numeric_limits<double>::infinity();
151  size_t count = 0;
152  if (config_.max_active == std::numeric_limits<int32>::max() &&
153  config_.min_active == 0) {
154  for (Elem *e = list_head; e != NULL; e = e->tail, count++) {
155  double w = e->val->cost_;
156  if (w < best_cost) {
157  best_cost = w;
158  if (best_elem) *best_elem = e;
159  }
160  }
161  if (tok_count != NULL) *tok_count = count;
162  if (adaptive_beam != NULL) *adaptive_beam = config_.beam;
163  return best_cost + config_.beam;
164  } else {
165  tmp_array_.clear();
166  for (Elem *e = list_head; e != NULL; e = e->tail, count++) {
167  double w = e->val->cost_;
168  tmp_array_.push_back(w);
169  if (w < best_cost) {
170  best_cost = w;
171  if (best_elem) *best_elem = e;
172  }
173  }
174  if (tok_count != NULL) *tok_count = count;
175  double beam_cutoff = best_cost + config_.beam,
176  min_active_cutoff = std::numeric_limits<double>::infinity(),
177  max_active_cutoff = std::numeric_limits<double>::infinity();
178 
179  if (tmp_array_.size() > static_cast<size_t>(config_.max_active)) {
180  std::nth_element(tmp_array_.begin(),
181  tmp_array_.begin() + config_.max_active,
182  tmp_array_.end());
183  max_active_cutoff = tmp_array_[config_.max_active];
184  }
185  if (max_active_cutoff < beam_cutoff) { // max_active is tighter than beam.
186  if (adaptive_beam)
187  *adaptive_beam = max_active_cutoff - best_cost + config_.beam_delta;
188  return max_active_cutoff;
189  }
190  if (tmp_array_.size() > static_cast<size_t>(config_.min_active)) {
191  if (config_.min_active == 0) min_active_cutoff = best_cost;
192  else {
193  std::nth_element(tmp_array_.begin(),
194  tmp_array_.begin() + config_.min_active,
195  tmp_array_.size() > static_cast<size_t>(config_.max_active) ?
196  tmp_array_.begin() + config_.max_active :
197  tmp_array_.end());
198  min_active_cutoff = tmp_array_[config_.min_active];
199  }
200  }
201  if (min_active_cutoff > beam_cutoff) { // min_active is looser than beam.
202  if (adaptive_beam)
203  *adaptive_beam = min_active_cutoff - best_cost + config_.beam_delta;
204  return min_active_cutoff;
205  } else {
206  *adaptive_beam = config_.beam;
207  return beam_cutoff;
208  }
209  }
210 }
FasterDecoderOptions config_
const size_t count
HashList< StateId, Token * >::Elem Elem
std::vector< BaseFloat > tmp_array_

◆ InitDecoding()

void InitDecoding ( )

As a new alternative to Decode(), you can call InitDecoding and then (possibly multiple times) AdvanceDecoding().

Definition at line 36 of file faster-decoder.cc.

References HashList< I, T >::Clear(), FasterDecoder::ClearToks(), FasterDecoder::fst_, HashList< I, T >::Insert(), KALDI_ASSERT, FasterDecoder::num_frames_decoded_, FasterDecoder::ProcessNonemitting(), and FasterDecoder::toks_.

Referenced by FasterDecoder::Decode(), and main().

36  {
37  // clean up from last time:
39  StateId start_state = fst_.Start();
40  KALDI_ASSERT(start_state != fst::kNoStateId);
41  Arc dummy_arc(0, 0, Weight::One(), start_state);
42  toks_.Insert(start_state, new Token(dummy_arc, NULL));
43  ProcessNonemitting(std::numeric_limits<float>::max());
45 }
Elem * Insert(I key, T val)
Insert inserts a new element into the hashtable/stored list.
void ClearToks(Elem *list)
const fst::Fst< fst::StdArc > & fst_
void ProcessNonemitting(double cutoff)
Elem * Clear()
Clears the hash and gives the head of the current list to the user; ownership is transferred to the u...
Definition: hash-list-inl.h:46
HashList< StateId, Token * > toks_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
Arc::StateId StateId

◆ KALDI_DISALLOW_COPY_AND_ASSIGN()

KALDI_DISALLOW_COPY_AND_ASSIGN ( FasterDecoder  )
protected

◆ NumFramesDecoded()

int32 NumFramesDecoded ( ) const
inline

Returns the number of frames already decoded.

Definition at line 102 of file faster-decoder.h.

102 { return num_frames_decoded_; }

◆ PossiblyResizeHash()

void PossiblyResizeHash ( size_t  num_toks)
protected

Definition at line 212 of file faster-decoder.cc.

References FasterDecoder::config_, FasterDecoderOptions::hash_ratio, HashList< I, T >::SetSize(), HashList< I, T >::Size(), and FasterDecoder::toks_.

Referenced by FasterDecoder::ProcessEmitting().

212  {
213  size_t new_sz = static_cast<size_t>(static_cast<BaseFloat>(num_toks)
214  * config_.hash_ratio);
215  if (new_sz > toks_.Size()) {
216  toks_.SetSize(new_sz);
217  }
218 }
FasterDecoderOptions config_
float BaseFloat
Definition: kaldi-types.h:29
void SetSize(size_t sz)
SetSize tells the object how many hash buckets to allocate (should typically be at least twice the nu...
Definition: hash-list-inl.h:37
HashList< StateId, Token * > toks_
size_t Size()
Returns current number of hash buckets.
Definition: hash-list.h:113

◆ ProcessEmitting()

double ProcessEmitting ( DecodableInterface decodable)
protected

Definition at line 221 of file faster-decoder.cc.

References FasterDecoder::Token::arc_, HashList< I, T >::Clear(), FasterDecoder::Token::cost_, HashList< I, T >::Delete(), FasterDecoder::fst_, FasterDecoder::GetCutoff(), HashList< I, T >::Insert(), KALDI_ASSERT, KALDI_VLOG, HashList< I, T >::Elem::key, DecodableInterface::LogLikelihood(), FasterDecoder::num_frames_decoded_, FasterDecoder::PossiblyResizeHash(), FasterDecoder::Token::TokenDelete(), FasterDecoder::toks_, and HashList< I, T >::Elem::val.

Referenced by FasterDecoder::AdvanceDecoding(), and OnlineFasterDecoder::Decode().

221  {
222  int32 frame = num_frames_decoded_;
223  Elem *last_toks = toks_.Clear();
224  size_t tok_cnt;
225  BaseFloat adaptive_beam;
226  Elem *best_elem = NULL;
227  double weight_cutoff = GetCutoff(last_toks, &tok_cnt,
228  &adaptive_beam, &best_elem);
229  KALDI_VLOG(3) << tok_cnt << " tokens active.";
230  PossiblyResizeHash(tok_cnt); // This makes sure the hash is always big enough.
231 
232  // This is the cutoff we use after adding in the log-likes (i.e.
233  // for the next frame). This is a bound on the cutoff we will use
234  // on the next frame.
235  double next_weight_cutoff = std::numeric_limits<double>::infinity();
236 
237  // First process the best token to get a hopefully
238  // reasonably tight bound on the next cutoff.
239  if (best_elem) {
240  StateId state = best_elem->key;
241  Token *tok = best_elem->val;
242  for (fst::ArcIterator<fst::Fst<Arc> > aiter(fst_, state);
243  !aiter.Done();
244  aiter.Next()) {
245  const Arc &arc = aiter.Value();
246  if (arc.ilabel != 0) { // we'd propagate..
247  BaseFloat ac_cost = - decodable->LogLikelihood(frame, arc.ilabel);
248  double new_weight = arc.weight.Value() + tok->cost_ + ac_cost;
249  if (new_weight + adaptive_beam < next_weight_cutoff)
250  next_weight_cutoff = new_weight + adaptive_beam;
251  }
252  }
253  }
254 
255  // int32 n = 0, np = 0;
256 
257  // the tokens are now owned here, in last_toks, and the hash is empty.
258  // 'owned' is a complex thing here; the point is we need to call TokenDelete
259  // on each elem 'e' to let toks_ know we're done with them.
260  for (Elem *e = last_toks, *e_tail; e != NULL; e = e_tail) { // loop this way
261  // n++;
262  // because we delete "e" as we go.
263  StateId state = e->key;
264  Token *tok = e->val;
265  if (tok->cost_ < weight_cutoff) { // not pruned.
266  // np++;
267  KALDI_ASSERT(state == tok->arc_.nextstate);
268  for (fst::ArcIterator<fst::Fst<Arc> > aiter(fst_, state);
269  !aiter.Done();
270  aiter.Next()) {
271  Arc arc = aiter.Value();
272  if (arc.ilabel != 0) { // propagate..
273  BaseFloat ac_cost = - decodable->LogLikelihood(frame, arc.ilabel);
274  double new_weight = arc.weight.Value() + tok->cost_ + ac_cost;
275  if (new_weight < next_weight_cutoff) { // not pruned..
276  Token *new_tok = new Token(arc, ac_cost, tok);
277  Elem *e_found = toks_.Insert(arc.nextstate, new_tok);
278  if (new_weight + adaptive_beam < next_weight_cutoff)
279  next_weight_cutoff = new_weight + adaptive_beam;
280  if (e_found->val != new_tok) {
281  if (*(e_found->val) < *new_tok) {
282  Token::TokenDelete(e_found->val);
283  e_found->val = new_tok;
284  } else {
285  Token::TokenDelete(new_tok);
286  }
287  }
288  }
289  }
290  }
291  }
292  e_tail = e->tail;
293  Token::TokenDelete(e->val);
294  toks_.Delete(e);
295  }
297  return next_weight_cutoff;
298 }
Elem * Insert(I key, T val)
Insert inserts a new element into the hashtable/stored list.
kaldi::int32 int32
void PossiblyResizeHash(size_t num_toks)
static void TokenDelete(Token *tok)
const fst::Fst< fst::StdArc > & fst_
double GetCutoff(Elem *list_head, size_t *tok_count, BaseFloat *adaptive_beam, Elem **best_elem)
Gets the weight cutoff. Also counts the active tokens.
float BaseFloat
Definition: kaldi-types.h:29
Elem * Clear()
Clears the hash and gives the head of the current list to the user; ownership is transferred to the u...
Definition: hash-list-inl.h:46
HashList< StateId, Token * > toks_
HashList< StateId, Token * >::Elem Elem
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
#define KALDI_VLOG(v)
Definition: kaldi-error.h:156
Arc::StateId StateId
void Delete(Elem *e)
Think of this like delete().
Definition: hash-list-inl.h:66

◆ ProcessNonemitting()

void ProcessNonemitting ( double  cutoff)
protected

Definition at line 301 of file faster-decoder.cc.

References FasterDecoder::Token::arc_, FasterDecoder::Token::cost_, FasterDecoder::fst_, HashList< I, T >::GetList(), HashList< I, T >::Insert(), KALDI_ASSERT, HashList< I, T >::Elem::key, FasterDecoder::queue_, HashList< I, T >::Elem::tail, FasterDecoder::Token::TokenDelete(), FasterDecoder::toks_, and HashList< I, T >::Elem::val.

Referenced by FasterDecoder::AdvanceDecoding(), OnlineFasterDecoder::Decode(), and FasterDecoder::InitDecoding().

301  {
302  // Processes nonemitting arcs for one frame.
303  KALDI_ASSERT(queue_.empty());
304  for (const Elem *e = toks_.GetList(); e != NULL; e = e->tail)
305  queue_.push_back(e);
306  while (!queue_.empty()) {
307  const Elem* e = queue_.back();
308  queue_.pop_back();
309  StateId state = e->key;
310  Token *tok = e->val; // would segfault if state not
311  // in toks_ but this can't happen.
312  if (tok->cost_ > cutoff) { // Don't bother processing successors.
313  continue;
314  }
315  KALDI_ASSERT(tok != NULL && state == tok->arc_.nextstate);
316  for (fst::ArcIterator<fst::Fst<Arc> > aiter(fst_, state);
317  !aiter.Done();
318  aiter.Next()) {
319  const Arc &arc = aiter.Value();
320  if (arc.ilabel == 0) { // propagate nonemitting only...
321  Token *new_tok = new Token(arc, tok);
322  if (new_tok->cost_ > cutoff) { // prune
323  Token::TokenDelete(new_tok);
324  } else {
325  Elem *e_found = toks_.Insert(arc.nextstate, new_tok);
326  if (e_found->val == new_tok) {
327  queue_.push_back(e_found);
328  } else {
329  if (*(e_found->val) < *new_tok) {
330  Token::TokenDelete(e_found->val);
331  e_found->val = new_tok;
332  queue_.push_back(e_found);
333  } else {
334  Token::TokenDelete(new_tok);
335  }
336  }
337  }
338  }
339  }
340  }
341 }
Elem * Insert(I key, T val)
Insert inserts a new element into the hashtable/stored list.
static void TokenDelete(Token *tok)
const fst::Fst< fst::StdArc > & fst_
const Elem * GetList() const
Gives the head of the current list to the user.
Definition: hash-list-inl.h:61
HashList< StateId, Token * > toks_
HashList< StateId, Token * >::Elem Elem
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
Arc::StateId StateId
std::vector< const Elem *> queue_

◆ ReachedFinal()

bool ReachedFinal ( ) const

Returns true if a final state was active on the last frame.

Definition at line 75 of file faster-decoder.cc.

References FasterDecoder::fst_, HashList< I, T >::GetList(), HashList< I, T >::Elem::tail, and FasterDecoder::toks_.

Referenced by kaldi::AlignUtteranceWrapper(), DecodeUtterance(), OnlineFasterDecoder::FinishTraceBack(), FasterDecoder::GetBestPath(), and main().

75  {
76  for (const Elem *e = toks_.GetList(); e != NULL; e = e->tail) {
77  if (e->val->cost_ != std::numeric_limits<double>::infinity() &&
78  fst_.Final(e->key) != Weight::Zero())
79  return true;
80  }
81  return false;
82 }
const fst::Fst< fst::StdArc > & fst_
const Elem * GetList() const
Gives the head of the current list to the user.
Definition: hash-list-inl.h:61
HashList< StateId, Token * > toks_
HashList< StateId, Token * >::Elem Elem

◆ SetOptions()

void SetOptions ( const FasterDecoderOptions config)
inline

Definition at line 72 of file faster-decoder.h.

Referenced by kaldi::AlignUtteranceWrapper().

72 { config_ = config; }
FasterDecoderOptions config_

Member Data Documentation

◆ config_

◆ fst_

◆ num_frames_decoded_

int32 num_frames_decoded_
protected

◆ queue_

std::vector<const Elem* > queue_
protected

Definition at line 173 of file faster-decoder.h.

Referenced by FasterDecoder::ProcessNonemitting().

◆ tmp_array_

std::vector<BaseFloat> tmp_array_
protected

Definition at line 174 of file faster-decoder.h.

Referenced by FasterDecoder::GetCutoff().

◆ toks_


The documentation for this class was generated from the following files: