Skip to content

Commit

Permalink
Update decoding.py
Browse files Browse the repository at this point in the history
New fix for endless loop problem. I also created a PR for official Whisper: openai/whisper#1155

It is explained in openai/whisper#914 and openai/whisper#924
  • Loading branch information
FernanOrtega authored Mar 27, 2023
1 parent 33dd3b9 commit 79de666
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions whisperx/decoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,13 @@ def apply(self, logits: Tensor, tokens: Tensor):
if timestamps.numel() > 0:
# timestamps shouldn't decrease; forbid timestamp tokens smaller than the last
logits[k, self.tokenizer.timestamp_begin : timestamps[-1]] = -np.inf

# to force that timestamps are strictly increasing
if last_was_timestamp and not penultimate_was_timestamp:
timestamp_last = timestamps[-1]
else:
timestamp_last = timestamps[-1] + 1
logits[k, self.tokenizer.timestamp_begin: timestamp_last] = -np.inf

if tokens.shape[1] == self.sample_begin:
# suppress generating non-timestamp tokens at the beginning
Expand Down

0 comments on commit 79de666

Please sign in to comment.