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

whisper : improve beam search candidate diversity #1947

Merged
merged 1 commit into from
Mar 10, 2024
Merged
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
15 changes: 14 additions & 1 deletion whisper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4759,6 +4759,19 @@ static void whisper_process_logits(
#endif
}

static bool whisper_sequence_tokens_equal(const whisper_sequence & a, const whisper_sequence & b) {
if (a.tokens.size() != b.tokens.size()) {
return false;
}
// sequences are more likely to diverge at the end
for (int i = a.tokens.size() - 1; i >= 0; i--) {
if (a.tokens[i].id != b.tokens[i].id) {
return false;
}
}
return true;
}

static whisper_token_data whisper_sample_token(
whisper_context & ctx,
const whisper_decoder & decoder,
Expand Down Expand Up @@ -5378,7 +5391,7 @@ int whisper_full_with_state(

auto & cur = beam_candidates[cur_c++];

while (beam_candidates.size() > cur_c && beam_candidates[cur_c].sequence.sum_logprobs_all == cur.sequence.sum_logprobs_all && i > 0) {
while (beam_candidates.size() > cur_c && whisper_sequence_tokens_equal(beam_candidates[cur_c].sequence, cur.sequence) && i > 0) {
++cur_c;
}

Expand Down
Loading