From 025df72c1002c0891d8ce6e37346724f69bfbdae Mon Sep 17 00:00:00 2001
From: haoneng.lhn <haoneng.lhn@alibaba-inc.com>
Date: 星期四, 18 五月 2023 21:10:16 +0800
Subject: [PATCH] update
---
funasr/bin/asr_infer.py | 21 +++++++++++++--------
1 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/funasr/bin/asr_infer.py b/funasr/bin/asr_infer.py
index 5946271..acb5fd8 100644
--- a/funasr/bin/asr_infer.py
+++ b/funasr/bin/asr_infer.py
@@ -488,15 +488,20 @@
nbest_hyps = nbest_hyps[: self.nbest]
else:
- yseq = am_scores.argmax(dim=-1)
- score = am_scores.max(dim=-1)[0]
- score = torch.sum(score, dim=-1)
- # pad with mask tokens to ensure compatibility with sos/eos tokens
- yseq = torch.tensor(
- [self.asr_model.sos] + yseq.tolist() + [self.asr_model.eos], device=yseq.device
- )
+ if pre_token_length[i] == 0:
+ yseq = torch.tensor(
+ [self.asr_model.sos] + [self.asr_model.eos], device=yseq.device
+ )
+ score = torch.tensor(0.0, device=yseq.device)
+ else:
+ yseq = am_scores.argmax(dim=-1)
+ score = am_scores.max(dim=-1)[0]
+ score = torch.sum(score, dim=-1)
+ # pad with mask tokens to ensure compatibility with sos/eos tokens
+ yseq = torch.tensor(
+ [self.asr_model.sos] + yseq.tolist() + [self.asr_model.eos], device=yseq.device
+ )
nbest_hyps = [Hypothesis(yseq=yseq, score=score)]
-
for hyp in nbest_hyps:
assert isinstance(hyp, (Hypothesis)), type(hyp)
--
Gitblit v1.9.1