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

[ASR] whisper fix got ValueError in decoding, test=asr #2825

Merged
merged 1 commit into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions paddlespeech/s2t/models/whisper/tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ def decode(self,
if ids < len(self.tokenizer):
ids_list.append(ids)
token_ids = ids_list
elif len(token_ids) == 1:
token_ids = token_ids[0]
else:
raise ValueError(f"token_ids {token_ids} load error.")

return self.tokenizer.decode(token_ids, **kwargs)

Expand Down
14 changes: 7 additions & 7 deletions paddlespeech/s2t/models/whisper/whipser.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
import numpy as np
import paddle
import paddle.nn.functional as F
import paddlespeech.s2t.modules.align as paddlespeech_nn
import soundfile
import tqdm
from paddle import nn
from paddle.distribution import Categorical

import paddlespeech.s2t.modules.align as paddlespeech_nn
from paddlespeech.s2t.models.whisper import utils
from paddlespeech.s2t.models.whisper.tokenizer import get_tokenizer
from paddlespeech.s2t.models.whisper.tokenizer import LANGUAGES
Expand Down Expand Up @@ -771,8 +770,10 @@ def update(self,
if temperature == 0:
next_tokens = paddle.argmax(logits, axis=-1)
else:
next_tokens = Categorical(logits=logits / temperature).sample(
shape=logits.shape)
next_tokens = Categorical(logits=logits / temperature).sample([1])
next_tokens = paddle.reshape(next_tokens, [
next_tokens.shape[0] * next_tokens.shape[1],
])

logprobs = F.log_softmax(logits, axis=-1, dtype=paddle.float32)
current_logprobs = logprobs[paddle.arange(logprobs.shape[0]),
Expand Down Expand Up @@ -1205,9 +1206,8 @@ def run(self, mel: paddle.Tensor) -> List[DecodingResult]:
DecodingResult(
audio_features=features,
language=language,
language_probs=probs)
for features, language, probs in zip(audio_features, languages,
language_probs)
language_probs=probs) for features, language, probs in
zip(audio_features, languages, language_probs)
]

# repeat the audio & text tensors by the group size, for beam search or best-of-n sampling
Expand Down