From 5f50cbf65affa6c0201260eaaac11ff0dce7d738 Mon Sep 17 00:00:00 2001 From: Askars <19928242+vsd-vector@users.noreply.github.com> Date: Thu, 3 Oct 2024 11:42:09 +0300 Subject: [PATCH] context_state is not set correctly when previous context is passed after reset (#1393) Co-authored-by: vsd-vector --- .../csrc/online-recognizer-transducer-impl.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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