feat: add initial prompt (prompt_ids) support for Whisper generation#1540
Open
jhlee111 wants to merge 1 commit intohuggingface:mainfrom
Open
feat: add initial prompt (prompt_ids) support for Whisper generation#1540jhlee111 wants to merge 1 commit intohuggingface:mainfrom
jhlee111 wants to merge 1 commit intohuggingface:mainfrom
Conversation
Implement prompt_ids handling in WhisperForConditionalGeneration.generate() to support initial prompt conditioning, matching the Python transformers library behavior. When prompt_ids is provided via generation config, it is prepended to init_tokens following the Whisper training format: [<|startofprev|>, ...prompt_text..., <|startoftranscript|>, <|lang|>, <|task|>, ...] The prompt tokens are stripped from output sequences after generation to prevent them from appearing in transcription results. Closes huggingface#923 Closes huggingface#1028
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #923
Closes #1028
Summary
Add
prompt_idssupport toWhisperForConditionalGeneration.generate(), enabling initial prompt conditioning for Whisper transcription. This is a long-requested feature (both issues are from 2024) that matches the behavior of the Pythontransformerslibrary.What this does
When
prompt_ids(an array of token IDs, typically starting with<|startofprev|>) is provided via generation config, it is prepended toinit_tokensfollowing the Whisper training format:After generation, the prompt tokens are stripped from the output sequences so they don't appear in the transcription results.
Usage
Changes
packages/transformers/src/models/whisper/modeling_whisper.js— 1 file, ~20 lines addedprompt_idstoinit_tokenswhen providedNo breaking changes — when
prompt_idsis not provided, behavior is identical to before.Checklist
pnpm build)pnpm format:check)