All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
FasterDecoder Class Reference

#include <faster-decoder.h>

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 ()
 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< StateIdqueue_
 
std::vector< BaseFloattmp_array_
 
int32 num_frames_decoded_
 

Detailed Description

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

Member Typedef Documentation

typedef fst::StdArc Arc

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

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

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

typedef Arc::Label Label

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

typedef Arc::StateId StateId

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

typedef Arc::Weight Weight

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

Constructor & Destructor Documentation

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_
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:169
~FasterDecoder ( )
inline

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

References HashList< I, T >::Clear(), FasterDecoder::ClearToks(), and FasterDecoder::toks_.

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

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 56 of file faster-decoder.cc.

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

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

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

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

Referenced by FasterDecoder::InitDecoding(), and FasterDecoder::~FasterDecoder().

348  {
349  for (Elem *e = list, *e_tail; e != NULL; e = e_tail) {
350  Token::TokenDelete(e->val);
351  e_tail = e->tail;
352  toks_.Delete(e);
353  }
354 }
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
void Decode ( DecodableInterface decodable)

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

References FasterDecoder::InitDecoding(), DecodableInterface::IsLastFrame(), FasterDecoder::num_frames_decoded_, FasterDecoder::ProcessEmitting(), and FasterDecoder::ProcessNonemitting().

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

48  {
49  InitDecoding();
50  while (!decodable->IsLastFrame(num_frames_decoded_ - 1)) {
51  double weight_cutoff = ProcessEmitting(decodable);
52  ProcessNonemitting(weight_cutoff);
53  }
54 }
void InitDecoding()
As a new alternative to Decode(), you can call InitDecoding and then (possibly multiple times) Advanc...
void ProcessNonemitting(double cutoff)
double ProcessEmitting(DecodableInterface *decodable)
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 87 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(), and FasterDecoder::toks_.

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

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

References FasterDecoderOptions::beam, FasterDecoderOptions::beam_delta, FasterDecoder::config_, count, FasterDecoderOptions::max_active, FasterDecoderOptions::min_active, and FasterDecoder::tmp_array_.

Referenced by FasterDecoder::ProcessEmitting().

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

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 }
void ClearToks(Elem *list)
void Insert(I key, T val)
Insert inserts a new element into the hashtable/stored 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:169
Arc::StateId StateId
KALDI_DISALLOW_COPY_AND_ASSIGN ( FasterDecoder  )
protected
int32 NumFramesDecoded ( ) const
inline

Returns the number of frames already decoded.

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

References FasterDecoder::num_frames_decoded_.

102 { return num_frames_decoded_; }
void PossiblyResizeHash ( size_t  num_toks)
protected

Definition at line 215 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().

215  {
216  size_t new_sz = static_cast<size_t>(static_cast<BaseFloat>(num_toks)
217  * config_.hash_ratio);
218  if (new_sz > toks_.Size()) {
219  toks_.SetSize(new_sz);
220  }
221 }
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:115
double ProcessEmitting ( DecodableInterface decodable)
protected

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

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

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

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

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

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

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

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

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

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

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

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

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

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

References FasterDecoder::config_.

Referenced by kaldi::AlignUtteranceWrapper().

72 { config_ = config; }
FasterDecoderOptions config_

Member Data Documentation

std::vector<StateId> queue_
protected

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

Referenced by FasterDecoder::ProcessNonemitting().

std::vector<BaseFloat> tmp_array_
protected

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

Referenced by FasterDecoder::GetCutoff().


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