Skip to content

Commit

Permalink
Prevent timestamps from decreasing in Whisper generation (#1063)
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumekln authored Feb 2, 2023
1 parent de7601f commit 111b142
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/models/whisper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,17 @@ namespace ctranslate2 {
} else {
check_timestamps_prob_for_batch.push_back(batch_id);
}

// Timestamps shouldn't decrease: forbid timestamp tokens smaller than the last.
for (dim_t t = step - 1; t >= sample_begin; --t) {
const size_t token = sequences.at<int32_t>({batch_id, t});

if (token >= _timestamp_begin_id) {
for (size_t i = _timestamp_begin_id; i <= token; ++i)
disable_tokens.add(batch_id, i);
break;
}
}
}
}

Expand Down

0 comments on commit 111b142

Please sign in to comment.