diff --git a/sherpa-onnx/csrc/online-recognizer-transducer-impl.h b/sherpa-onnx/csrc/online-recognizer-transducer-impl.h index 50af6b987..475a90185 100644 --- a/sherpa-onnx/csrc/online-recognizer-transducer-impl.h +++ b/sherpa-onnx/csrc/online-recognizer-transducer-impl.h @@ -382,13 +382,6 @@ class OnlineRecognizerTransducerImpl : public OnlineRecognizerImpl { // s->SetStates(model_->GetEncoderInitStates()); auto r = decoder_->GetEmptyResult(); - if (config_.decoding_method == "modified_beam_search" && - nullptr != s->GetContextGraph()) { - for (auto it = r.hyps.begin(); it != r.hyps.end(); ++it) { - it->second.context_state = s->GetContextGraph()->Root(); - } - } - auto last_result = s->GetResult(); // if last result is not empty, then // preserve last tokens as the context for next result @@ -401,6 +394,13 @@ class OnlineRecognizerTransducerImpl : public OnlineRecognizerImpl { r.tokens = std::move(context); } + if (config_.decoding_method == "modified_beam_search" && + nullptr != s->GetContextGraph()) { + for (auto it = r.hyps.begin(); it != r.hyps.end(); ++it) { + it->second.context_state = s->GetContextGraph()->Root(); + } + } + s->SetResult(r); // Note: We only update counters. The underlying audio samples