@@ -86,11 +86,11 @@ Token* BucketQueue<Token>::Pop() {
8686 if (!buckets_[next_vec_index].empty ()) break ;
8787 }
8888 vec_index = next_vec_index;
89+ first_occupied_vec_index_ = vec_index;
8990 }
9091
9192 if (tok->in_queue ) { // This is a effective token
9293 tok->in_queue = false ;
93- first_occupied_vec_index_ = vec_index;
9494 return tok;
9595 }
9696 }
@@ -103,11 +103,7 @@ void BucketQueue<Token>::Clear() {
103103 buckets_[i].clear ();
104104 }
105105 first_occupied_vec_index_ = buckets_.size ();
106- }
107-
108- template <typename Token>
109- void BucketQueue<Token>::SetBegin(BaseFloat best_cost_estimate) {
110- bucket_storage_begin_ = std::floor ((best_cost_estimate - 15 ) * cost_scale_);
106+ bucket_storage_begin_ = -15 * cost_scale_;
111107}
112108
113109// instantiate this class once for each thing you have to decode.
@@ -161,8 +157,9 @@ void LatticeFasterDecoderCombineTpl<FST, Token>::InitDecoding() {
161157 active_toks_[0 ].toks = start_tok;
162158 cur_toks_[start_state] = start_tok; // initialize current tokens map
163159 num_toks_++;
164- best_token_in_next_frame_ = start_tok;
165160 adaptive_beam_ = config_.beam ;
161+ cost_offsets_.resize (1 );
162+ cost_offsets_[0 ] = 0.0 ;
166163
167164}
168165
@@ -793,9 +790,7 @@ void LatticeFasterDecoderCombineTpl<FST, Token>::ProcessForFrame(
793790 }
794791 }
795792
796- KALDI_ASSERT (best_token_in_next_frame_);
797793 cur_queue_.Clear ();
798- cur_queue_.SetBegin (best_token_in_next_frame_->tot_cost );
799794 // Add tokens to queue
800795 for (Token* tok = active_toks_[frame].toks ; tok != NULL ; tok = tok->next ) {
801796 cur_queue_.Push (tok);
@@ -814,14 +809,7 @@ void LatticeFasterDecoderCombineTpl<FST, Token>::ProcessForFrame(
814809 BaseFloat next_cutoff = std::numeric_limits<BaseFloat>::infinity ();
815810 // "cost_offset" contains the acoustic log-likelihoods on current frame in
816811 // order to keep everything in a nice dynamic range. Reduce roundoff errors.
817- BaseFloat cost_offset = - best_token_in_next_frame_->tot_cost ;
818-
819- best_token_in_next_frame_ = NULL ;
820- // Store the offset on the acoustic likelihoods that we're applying.
821- // Could just do cost_offsets_.push_back(cost_offset), but we
822- // do it this way as it's more robust to future code changes.
823- cost_offsets_.resize (frame + 1 , 0.0 );
824- cost_offsets_[frame] = cost_offset;
812+ BaseFloat cost_offset = cost_offsets_[frame];
825813
826814 // Iterator the "cur_queue_" to process non-emittion and emittion arcs in fst.
827815 Token *tok = NULL ;
@@ -831,7 +819,9 @@ void LatticeFasterDecoderCombineTpl<FST, Token>::ProcessForFrame(
831819 num_toks_processed++) {
832820 BaseFloat cur_cost = tok->tot_cost ;
833821 StateId state = tok->state_id ;
834- if (cur_cost > cur_cutoff) { // Don't bother processing successors.
822+ if (cur_cost > cur_cutoff &&
823+ num_toks_processed < config_.min_active ) { // Don't bother processing
824+ // successors.
835825 break ; // This is a priority queue. The following tokens will be worse
836826 } else if (cur_cost + adaptive_beam < cur_cutoff) {
837827 cur_cutoff = cur_cost + adaptive_beam; // a tighter boundary
@@ -840,7 +830,6 @@ void LatticeFasterDecoderCombineTpl<FST, Token>::ProcessForFrame(
840830 // because we're about to regenerate them. This is a kind
841831 // of non-optimality (remember, this is the simple decoder),
842832 DeleteForwardLinks (tok); // necessary when re-visiting
843- tok->links = NULL ;
844833 for (fst::ArcIterator<FST> aiter (*fst_, state);
845834 !aiter.Done ();
846835 aiter.Next ()) {
@@ -881,14 +870,17 @@ void LatticeFasterDecoderCombineTpl<FST, Token>::ProcessForFrame(
881870 // list
882871 tok->links = new ForwardLinkT (next_tok, arc.ilabel , arc.olabel ,
883872 graph_cost, ac_cost, tok->links );
884- if (best_token_in_next_frame_ == NULL ||
885- next_tok->tot_cost < best_token_in_next_frame_->tot_cost ) {
886- best_token_in_next_frame_ = next_tok;
887- }
888873 }
889874 } // for all arcs
890875 } // end of while loop
891876
877+ // Store the offset on the acoustic likelihoods that we're applying.
878+ // Could just do cost_offsets_.push_back(cost_offset), but we
879+ // do it this way as it's more robust to future code changes.
880+ // Set the cost_offset_ for next frame, it equals "- best_cost_on_next_frame".
881+ cost_offsets_.resize (frame + 2 , 0.0 );
882+ cost_offsets_[frame + 1 ] = adaptive_beam - next_cutoff;
883+
892884 { // This block updates adaptive_beam_
893885 BaseFloat beam_used_this_frame = adaptive_beam;
894886 Token *tok = cur_queue_.Pop ();
@@ -936,9 +928,7 @@ void LatticeFasterDecoderCombineTpl<FST, Token>::ProcessNonemitting(
936928 tmp_toks = &cur_toks_;
937929 }
938930
939- KALDI_ASSERT (best_token_in_next_frame_);
940931 cur_queue_.Clear ();
941- cur_queue_.SetBegin (best_token_in_next_frame_->tot_cost );
942932 for (Token* tok = active_toks_[frame].toks ; tok != NULL ; tok = tok->next ) {
943933 cur_queue_.Push (tok);
944934 }
@@ -958,7 +948,9 @@ void LatticeFasterDecoderCombineTpl<FST, Token>::ProcessNonemitting(
958948 num_toks_processed++) {
959949 BaseFloat cur_cost = tok->tot_cost ;
960950 StateId state = tok->state_id ;
961- if (cur_cost > cur_cutoff) { // Don't bother processing successors.
951+ if (cur_cost > cur_cutoff &&
952+ num_toks_processed < config_.min_active ) { // Don't bother processing
953+ // successors.
962954 break ; // This is a priority queue. The following tokens will be worse
963955 } else if (cur_cost + adaptive_beam < cur_cutoff) {
964956 cur_cutoff = cur_cost + adaptive_beam; // a tighter boundary
@@ -967,7 +959,6 @@ void LatticeFasterDecoderCombineTpl<FST, Token>::ProcessNonemitting(
967959 // because we're about to regenerate them. This is a kind
968960 // of non-optimality (remember, this is the simple decoder),
969961 DeleteForwardLinks (tok); // necessary when re-visiting
970- tok->links = NULL ;
971962 for (fst::ArcIterator<FST> aiter (*fst_, state);
972963 !aiter.Done ();
973964 aiter.Next ()) {
0 commit comments