Skip to content

Commit b0022b3

Browse files
Update decoding.py (#1155)
* Update decoding.py Following the suggestions of @Jeronymous in #914 and #924, it solves the problem of endless loop. * Removed blank line and whitespaces in empty lines. * Suggested changes according to the linter --------- Co-authored-by: Jong Wook Kim <jongwook@openai.com>
1 parent 76c901a commit b0022b3

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

whisper/decoding.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,13 @@ def apply(self, logits: Tensor, tokens: Tensor):
471471
# timestamps shouldn't decrease; forbid timestamp tokens smaller than the last
472472
logits[k, self.tokenizer.timestamp_begin : timestamps[-1]] = -np.inf
473473

474+
# to force that timestamps are strictly increasing
475+
if last_was_timestamp and not penultimate_was_timestamp:
476+
timestamp_last = timestamps[-1]
477+
else:
478+
timestamp_last = timestamps[-1] + 1
479+
logits[k, self.tokenizer.timestamp_begin : timestamp_last] = -np.inf
480+
474481
if tokens.shape[1] == self.sample_begin:
475482
# suppress generating non-timestamp tokens at the beginning
476483
logits[:, : self.tokenizer.timestamp_begin] = -np.inf

0 commit comments

Comments
 (0)