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
Adding chunking for whisper (all seq2seq actually). Very crude matching algorithm. #20104
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
20af9b4
Very crude matching algorithm.
Narsil 01e833c
Fixing tests.
Narsil 4127c84
Removing comments
Narsil 1019536
Adding warning + fix short matches.
Narsil 5db3432
Cleanup tests.
Narsil bd13f54
Quality.
Narsil 035c2bc
Less noisy.
Narsil 8b9f1f2
Fixup.
Narsil File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,12 +144,8 @@ def test_small_model_pt(self): | |
waveform = np.tile(np.arange(1000, dtype=np.float32), 34) | ||
output = speech_recognizer(waveform) | ||
self.assertEqual(output, {"text": "(Applaudissements)"}) | ||
with self.assertRaises(ValueError) as v: | ||
_ = speech_recognizer(waveform, chunk_length_s=10) | ||
self.assertEqual( | ||
str(v.exception), | ||
"`chunk_length_s` is only valid for CTC models, use other chunking options for other models", | ||
) | ||
output = speech_recognizer(waveform, chunk_length_s=10) | ||
self.assertEqual(output, {"text": "(Applaudissements)"}) | ||
|
||
# Non CTC models cannot use return_timestamps | ||
with self.assertRaises(ValueError) as v: | ||
|
@@ -261,6 +257,22 @@ def test_torch_large(self): | |
output = speech_recognizer(filename) | ||
self.assertEqual(output, {"text": "A MAN SAID TO THE UNIVERSE SIR I EXIST"}) | ||
|
||
@require_torch | ||
@slow | ||
def test_torch_whisper(self): | ||
speech_recognizer = pipeline( | ||
task="automatic-speech-recognition", | ||
model="openai/whisper-tiny", | ||
framework="pt", | ||
) | ||
ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation").sort("id") | ||
filename = ds[40]["file"] | ||
output = speech_recognizer(filename) | ||
self.assertEqual(output, {"text": " A man said to the universe, Sir, I exist."}) | ||
|
||
output = speech_recognizer([filename], chunk_length_s=5, batch_size=4) | ||
self.assertEqual(output, [{"text": " A man said to the universe, Sir, I exist."}]) | ||
Comment on lines
+273
to
+274
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIce |
||
|
||
@require_torch | ||
@slow | ||
def test_torch_speech_encoder_decoder(self): | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add some logic to only throw this warning once? Users are complaining Transformers is too verbose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there already a created way to do that ?
Otherwise I can create some tool for it.
Any other location we could add this "single" warning ? (Will add in a different PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use a dict in the state like this one. No need to overengineer another solution IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.