From 5ca0ff8811c39d746990265783755513eca7a893 Mon Sep 17 00:00:00 2001 From: Peng He <34941901+kamirdin@users.noreply.github.com> Date: Mon, 18 Sep 2023 10:43:04 +0800 Subject: [PATCH] Fix LogAdd (#316) Using 0 as the initial value, should not perform addition when both values are 0 --- sherpa-onnx/csrc/hypothesis.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sherpa-onnx/csrc/hypothesis.cc b/sherpa-onnx/csrc/hypothesis.cc index 3dbd33ba..9f5c680f 100644 --- a/sherpa-onnx/csrc/hypothesis.cc +++ b/sherpa-onnx/csrc/hypothesis.cc @@ -18,8 +18,10 @@ void Hypotheses::Add(Hypothesis hyp) { } else { it->second.log_prob = LogAdd()(it->second.log_prob, hyp.log_prob); - it->second.lm_log_prob = + if (it->second.lm_log_prob != 0 && hyp.lm_log_prob != 0){ + it->second.lm_log_prob = LogAdd()(it->second.lm_log_prob, hyp.lm_log_prob); + } } }