BackoffDeterministicOnDemandFst< Arc > Class Template Reference

This class wraps an Fst, representing a language model, using the interface for "BackoffDeterministicOnDemandFst". More...

#include <deterministic-fst.h>

Inheritance diagram for BackoffDeterministicOnDemandFst< Arc >:
Collaboration diagram for BackoffDeterministicOnDemandFst< Arc >:

Public Types

typedef Arc::Weight Weight
 
typedef Arc::StateId StateId
 
typedef Arc::Label Label
 
- Public Types inherited from DeterministicOnDemandFst< Arc >
typedef Arc::StateId StateId
 
typedef Arc::Weight Weight
 
typedef Arc::Label Label
 

Public Member Functions

 BackoffDeterministicOnDemandFst (const Fst< Arc > &fst)
 
StateId Start ()
 
Weight Final (StateId s)
 
bool GetArc (StateId s, Label ilabel, Arc *oarc)
 Note: ilabel must not be epsilon. More...
 
- Public Member Functions inherited from DeterministicOnDemandFst< Arc >
virtual ~DeterministicOnDemandFst ()
 

Private Member Functions

StateId GetBackoffState (StateId s, Weight *w)
 

Private Attributes

const Fst< Arc > & fst_
 

Detailed Description

template<class Arc>
class fst::BackoffDeterministicOnDemandFst< Arc >

This class wraps an Fst, representing a language model, using the interface for "BackoffDeterministicOnDemandFst".

We expect that backoff arcs in the language model will have the epsilon label (label 0) on the arcs, and that there will be no other epsilons in the language model. We follow the epsilon arcs as long as a particular arc (or a final-prob) is not found at the current state.

Definition at line 100 of file deterministic-fst.h.

Member Typedef Documentation

◆ Label

typedef Arc::Label Label

Definition at line 104 of file deterministic-fst.h.

◆ StateId

typedef Arc::StateId StateId

Definition at line 103 of file deterministic-fst.h.

◆ Weight

typedef Arc::Weight Weight

Definition at line 102 of file deterministic-fst.h.

Constructor & Destructor Documentation

◆ BackoffDeterministicOnDemandFst()

BackoffDeterministicOnDemandFst ( const Fst< Arc > &  fst)
explicit

Definition at line 58 of file deterministic-fst-inl.h.

References BackoffDeterministicOnDemandFst< Arc >::fst_, and KALDI_ASSERT.

59  : fst_(fst) {
60 #ifdef KALDI_PARANOID
61  KALDI_ASSERT(fst_.Properties(kILabelSorted|kIDeterministic, true) ==
62  (kILabelSorted|kIDeterministic) &&
63  "Input FST is not i-label sorted and deterministic.");
64 #endif
65 }
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

Member Function Documentation

◆ Final()

Arc::Weight Final ( StateId  s)
virtual

Implements DeterministicOnDemandFst< Arc >.

Definition at line 48 of file deterministic-fst-inl.h.

References fst::Times().

48  {
49  Weight w = fst_.Final(state);
50  if (w != Weight::Zero()) return w;
51  Weight backoff_w;
52  StateId backoff_state = GetBackoffState(state, &backoff_w);
53  if (backoff_state == kNoStateId) return Weight::Zero();
54  else return Times(backoff_w, this->Final(backoff_state));
55 }
StateId GetBackoffState(StateId s, Weight *w)
LatticeWeightTpl< FloatType > Times(const LatticeWeightTpl< FloatType > &w1, const LatticeWeightTpl< FloatType > &w2)

◆ GetArc()

bool GetArc ( StateId  s,
Label  ilabel,
Arc *  oarc 
)
virtual

Note: ilabel must not be epsilon.

Implements DeterministicOnDemandFst< Arc >.

Definition at line 68 of file deterministic-fst-inl.h.

References BackoffDeterministicOnDemandFst< Arc >::fst_, BackoffDeterministicOnDemandFst< Arc >::GetBackoffState(), KALDI_ASSERT, and fst::Times().

69  {
70  KALDI_ASSERT(ilabel != 0); // We don't allow GetArc for epsilon.
71 
72  SortedMatcher<Fst<Arc> > sm(fst_, MATCH_INPUT, 1);
73  sm.SetState(s);
74  if (sm.Find(ilabel)) {
75  const Arc &arc = sm.Value();
76  *oarc = arc;
77  return true;
78  } else {
79  Weight backoff_w;
80  StateId backoff_state = GetBackoffState(s, &backoff_w);
81  if (backoff_state == kNoStateId) return false;
82  if (!this->GetArc(backoff_state, ilabel, oarc)) return false;
83  oarc->weight = Times(oarc->weight, backoff_w);
84  return true;
85  }
86 }
StateId GetBackoffState(StateId s, Weight *w)
bool GetArc(StateId s, Label ilabel, Arc *oarc)
Note: ilabel must not be epsilon.
LatticeWeightTpl< FloatType > Times(const LatticeWeightTpl< FloatType > &w1, const LatticeWeightTpl< FloatType > &w2)
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ GetBackoffState()

Arc::StateId GetBackoffState ( StateId  s,
Weight w 
)
inlineprivate

Definition at line 33 of file deterministic-fst-inl.h.

Referenced by BackoffDeterministicOnDemandFst< Arc >::GetArc().

34  {
35  ArcIterator<Fst<Arc> > aiter(fst_, s);
36  if (aiter.Done()) // no arcs.
37  return kNoStateId;
38  const Arc &arc = aiter.Value();
39  if (arc.ilabel == 0) {
40  *w = arc.weight;
41  return arc.nextstate;
42  } else {
43  return kNoStateId;
44  }
45 }

◆ Start()

StateId Start ( )
inlinevirtual

Member Data Documentation

◆ fst_


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