34 Arc dummy_arc(0, 0, Weight::One(), start_state);
35 Token *dummy_token =
new Token(dummy_arc, NULL);
47 fst::MutableFst<LatticeArc> *out_fst)
const {
48 out_fst->DeleteStates();
49 if (start == NULL)
return;
50 bool is_final =
false;
51 double this_cost = start->
cost_ +
fst_.Final(start->
arc_.nextstate).Value();
52 if (this_cost != std::numeric_limits<double>::infinity())
54 std::vector<LatticeArc> arcs_reverse;
55 for (
const Token *tok = start; tok != end; tok = tok->
prev_) {
57 (tok->prev_ ? tok->prev_->cost_ : 0.0),
58 graph_cost = tok->arc_.weight.Value(),
59 ac_cost = tot_cost - graph_cost;
64 arcs_reverse.push_back(l_arc);
66 if(arcs_reverse.back().nextstate ==
fst_.Start()) {
67 arcs_reverse.pop_back();
69 StateId cur_state = out_fst->AddState();
70 out_fst->SetStart(cur_state);
71 for (ssize_t
i = static_cast<ssize_t>(arcs_reverse.size())-1;
i >= 0;
i--) {
73 arc.nextstate = out_fst->AddState();
74 out_fst->AddArc(cur_state, arc);
75 cur_state = arc.nextstate;
79 out_fst->SetFinal(cur_state,
LatticeWeight(final_weight.Value(), 0.0));
88 unordered_set<Token*> emitting;
91 while (tok != NULL && tok->
arc_.ilabel == 0)
96 Token* the_one = NULL;
98 if (emitting.size() == 1) {
99 the_one = *(emitting.begin());
102 if (emitting.size() == 0)
104 unordered_set<Token*> prev_emitting;
105 unordered_set<Token*>::iterator it;
106 for (it = emitting.begin(); it != emitting.end(); ++it) {
109 while ((prev_token != NULL) && (prev_token->
arc_.ilabel == 0))
110 prev_token = prev_token->
prev_;
111 if (prev_token == NULL)
113 prev_emitting.insert(prev_token);
115 emitting = prev_emitting;
117 if (the_one != NULL) {
137 Token *best_tok = NULL;
141 if (best_tok == NULL || *best_tok < *(e->val) )
144 double best_cost = std::numeric_limits<double>::infinity();
146 double this_cost = e->val->cost_ +
fst_.Final(e->key).Value();
147 if (this_cost != std::numeric_limits<double>::infinity() &&
148 this_cost < best_cost) {
149 best_cost = this_cost;
160 fst::MutableFst<LatticeArc> *out_fst) {
161 Token *best_tok = NULL;
163 if (best_tok == NULL || *best_tok < *(e->val) )
165 if (best_tok == NULL) {
166 out_fst->DeleteStates();
170 bool is_final =
false;
171 double this_cost = best_tok->
cost_ +
172 fst_.Final(best_tok->
arc_.nextstate).Value();
174 if (this_cost != std::numeric_limits<double>::infinity())
176 std::vector<LatticeArc> arcs_reverse;
177 for (
Token *tok = best_tok; (tok != NULL) && (nframes > 0); tok = tok->
prev_) {
178 if (tok->arc_.ilabel != 0)
181 (tok->prev_ ? tok->prev_->cost_ : 0.0);
182 BaseFloat graph_cost = tok->arc_.weight.Value();
183 BaseFloat ac_cost = tot_cost - graph_cost;
187 tok->arc_.nextstate);
188 arcs_reverse.push_back(larc);
190 if(arcs_reverse.back().nextstate ==
fst_.Start())
191 arcs_reverse.pop_back();
192 StateId cur_state = out_fst->AddState();
193 out_fst->SetStart(cur_state);
194 for (ssize_t
i = static_cast<ssize_t>(arcs_reverse.size())-1;
i >= 0;
i--) {
196 arc.nextstate = out_fst->AddState();
197 out_fst->AddArc(cur_state, arc);
198 cur_state = arc.nextstate;
202 out_fst->SetFinal(cur_state,
LatticeWeight(final_weight.Value(), 0.0));
211 fst::VectorFst<LatticeArc> trace;
214 std::vector<int32> isymbols;
216 static_cast<std::vector<int32>*
>(0),
217 static_cast<LatticeArc::Weight*>(0));
218 std::vector<std::vector<int32> > split;
220 for (
size_t i = 0;
i < split.size();
i++) {
235 int32 batch_frame = 0;
244 BaseFloat elapsed = (tend - tstart) * 1000;
248 if (factor > 1 || factor < min_factor) {
257 if (batch_frame != 0 && (
frame_ % 200) == 0)
261 << ((timer.
Elapsed() - tstart_batch) * 1000) / (batch_frame*10)
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
fst::ArcTpl< LatticeWeight > LatticeArc
Elem * Insert(I key, T val)
Insert inserts a new element into the hashtable/stored list.
BaseFloat max_beam_update
bool PartialTraceback(fst::MutableFst< LatticeArc > *out_fst)
DecodableInterface provides a link between the (acoustic-modeling and feature-processing) code and th...
void ClearToks(Elem *list)
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...
BaseFloat & effective_beam_
virtual bool IsLastFrame(int32 frame) const =0
Returns true if this is the last frame.
DecodeState Decode(DecodableInterface *decodable)
const BaseFloat max_beam_
bool GetLinearSymbolSequence(const Fst< Arc > &fst, std::vector< I > *isymbols_out, std::vector< I > *osymbols_out, typename Arc::Weight *tot_weight_out)
GetLinearSymbolSequence gets the symbol sequence from a linear FST.
fst::LatticeWeightTpl< BaseFloat > LatticeWeight
bool SplitToPhones(const TransitionModel &trans_model, const std::vector< int32 > &alignment, std::vector< std::vector< int32 > > *split_alignment)
SplitToPhones splits up the TransitionIds in "alignment" into their individual phones (one vector per...
Token * prev_immortal_tok_
const fst::Fst< fst::StdArc > & fst_
void FinishTraceBack(fst::MutableFst< LatticeArc > *fst_out)
void MakeLattice(const Token *start, const Token *end, fst::MutableFst< LatticeArc > *out_fst) const
void ProcessNonemitting(double cutoff)
void UpdateImmortalToken()
const Elem * GetList() const
Gives the head of the current list to the user.
const ConstIntegerSet< int32 > silence_set_
Elem * Clear()
Clears the hash and gives the head of the current list to the user; ownership is transferred to the u...
HashList< StateId, Token * > toks_
void ResetDecoder(bool full)
#define KALDI_ASSERT(cond)
void TracebackNFrames(int32 nframes, fst::MutableFst< LatticeArc > *out_fst)
const TransitionModel & trans_model_
double ProcessEmitting(DecodableInterface *decodable)
double Elapsed() const
Returns time in seconds.
int32 TransitionIdToPhone(int32 trans_id) const
bool ReachedFinal() const
Returns true if a final state was active on the last frame.
const OnlineFasterDecoderOpts opts_