Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sensevoice 增加置信度输出 #2083

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions funasr/models/sense_voice/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


from funasr.models.paraformer.search import Hypothesis

import math

class SinusoidalPositionEncoder(torch.nn.Module):
""" """
Expand Down Expand Up @@ -884,7 +884,13 @@ def inference(
for i in range(b):
x = ctc_logits[i, : encoder_out_lens[i].item(), :]
yseq = x.argmax(dim=-1)
yseq_prob = x.max(dim=-1).values
yseq = torch.unique_consecutive(yseq, dim=-1)

token_probs = []
for idx, token in enumerate(yseq):
if token != self.blank_id:
token_probs.append((tokenizer.decode(yseq[idx].tolist()), math.exp(yseq_prob[idx].item())))

ibest_writer = None
if kwargs.get("output_dir") is not None:
Expand All @@ -898,7 +904,7 @@ def inference(
# Change integer-ids to tokens
text = tokenizer.decode(token_int)

result_i = {"key": key[i], "text": text}
result_i = {"key": key[i], "text": text,"token_probs": token_probs}
results.append(result_i)

if ibest_writer is not None:
Expand Down