fix _retrieve_segment timestamps offset bug#43270
Open
YCmove wants to merge 1 commit into
Open
Conversation
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: whisper |
Contributor
|
View the CircleCI Test Summary for this PR: https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=43270&sha=190852 |
Member
|
cc @ebezzam as well |
This was referenced Apr 29, 2026
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.
What does this PR do?
In Whisper,
model.generate, the function_retrieve_segmentforgets to add back the time offset for the segment which was triggered from the seeking mechanism. Then this whole chunk (concatenated segments) with a false timestamp in its last segment is later processed indef _decode_asrin tokenization_whisper.py.Inside
_decode_asrdepends on the correctlast_timestampof a chunk to confirm the start timestamp of the first chunk (Reference code), thus it relies on the robust concatenated segments from_retrieve_segment.Final output is corrupted and misaligned with the original OpenAI's Whisper model output. The reproduction code is below.
This PR fixes the function
_retrieve_segmentinclass WhisperGenerationMixin. In the case when a chunk only contains a sentence.This bug is well hidden due to:
def _decode_asrcan function properly by luck.retrieve_segment, does add back the time offset set in the case when a chunk contains multiple sentences, but not when it only contains one sentence.Reproduction code on Huggingface Whisper
Input audio is the 4th testing audio hf-internal-testing/librispeech_asr_dummy with 6s of silence added in the beginning. sample_4_6s_silence.flac - GoogleDrive
Code for comparing to the original OpenAI Whisper
Result - When enabling the initial timestamp constraint (Default setting)
Huggingface whisper-large-v3
[0.00---27.82] Linnell's pictures are a sort of Upguards and Adam paintings, and Mason's exquisite idylls are as national as a jingo poem. Mr. Burkett Foster's landscapes smile at one much in the same way that Mr. Carker used to flash his teeth. And Mr. John Collier gives his
[27.82---34.86] sitter a cheerful slap on the back before he says, like a shampooer in a Turkish bath, next man.
OpenAI whisper-medium whisper-large-v3
[0.00---12.76] Linnell's pictures are a sort of Upguards and Adam paintings, and Mason's exquisite
[12.76---17.60] idylls are as national as a jingo poem.
[17.60---23.32] Mr. Burkett Foster's landscapes smile at one much in the same way that Mr. Carker used
[23.32---25.88] to flash his teeth.
[25.88---32.56] And Mr. John Collier gives his sitter a cheerful slap on the back before he says, like a shampooer
[32.56---34.98] in a Turkish bath, Next man!
As we can see, when keeping the default initial timestamp constraint, the start times of the first sentence in both HuggingFace and OpenAI’s Whisper are inaccurate since the input audio has 6 seconds of leading silence.
Result - When disabling the initial timestamp constraint
Huggingface whisper-large-v3
[27.82---34.86] Linnell's pictures are a sort of Upguards and Adam paintings, and Mason's exquisite idylls are as national as a jingo poem. Mr. Burkett Foster's landscapes smile at one much in the same way that Mr. Carker used to flash his teeth. And Mr. John Collier gives his sitter a cheerful slap on the back before he says, like a shampooer in a Turkish bath, next man.
OpenAI whisper-medium whisper-large-v3
[6.56---12.76] Linnell's pictures are a sort of Upguards and Adam paintings, and Mason's exquisite
[12.76---17.60] idylls are as national as a jingo poem.
[17.60---23.32] Mr. Burkett Foster's landscapes smile at one much in the same way that Mr. Carker used
[23.32---25.90] to flash his teeth.
[25.90---32.54] And Mr. John Collier gives his sitter a cheerful slap on the back before he says, like a shampooer
[32.54---34.96] in a Turkish bath, Next man!
Here are the incorrect results from HuggingFace’s Whisper. When disabling the initial timestamp constraint, OpenAI’s whisper-large-v3 model can accurately identify that the actual human voice starts after 6 seconds of leading silence.
Correct timestamp at the start time of the first sentence after this PR fix.
Huggingface whisper-large-v3
[6.56---12.78] Linnell's pictures are a sort of Upguards and Adam paintings, and Mason's exquisite
[12.78---17.60] idylls are as national as a jingo poem.
[17.60---23.32] Mr. Burkett Foster's landscapes smile at one much in the same way that Mr. Carker used
[23.32---27.82] to flash his teeth. Mr. John Collier gives his sitter a cheerful slap in the same way that Mr. Carker used to flash his teeth. And Mr. John Collier gives his
[27.82---34.86] sitter a cheerful slap on the back before he says, like a shampooer in a Turkish bath, next man.
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Just tag some account I have seen in some related issues.
@zucchini-nlp @ArthurZucker @eustlb