-
Notifications
You must be signed in to change notification settings - Fork 27.5k
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
Fix ASR pipelines from local directories with wav2vec models that have language models attached #15590
Merged
Merged
Fix ASR pipelines from local directories with wav2vec models that have language models attached #15590
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c357455
Fix loading pipelines with wav2vec models with lm when in local paths
versae 193826e
Adding tests
versae 87d1f9a
Fix test
versae af7d0e4
Adding tests
versae bd72739
Merge
versae ca48dc6
Flake8 fixes
versae 334b494
Removing conflict files :(
versae c912d62
Adding task type to test
versae b7f1880
Remove unnecessary test and imports
versae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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 |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
from transformers.pipelines.automatic_speech_recognition import apply_stride, chunk_iter | ||
from transformers.testing_utils import ( | ||
is_pipeline_test, | ||
is_pyctcdecode_available, | ||
is_torch_available, | ||
nested_simplify, | ||
require_pyctcdecode, | ||
|
@@ -47,6 +48,10 @@ | |
import torch | ||
|
||
|
||
if is_pyctcdecode_available(): | ||
from huggingface_hub import snapshot_download | ||
|
||
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. You can remove
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. Awesome. Thanks! |
||
|
||
# We can't use this mixin because it assumes TF support. | ||
# from .test_pipelines_common import CustomInputPipelineCommonMixin | ||
|
||
|
@@ -368,6 +373,27 @@ def test_with_lm_fast(self): | |
self.assertEqual(output, [{"text": ANY(str)}]) | ||
self.assertEqual(output[0]["text"][:6], "<s> <s") | ||
|
||
@require_torch | ||
@require_pyctcdecode | ||
def test_with_local_lm_fast(self): | ||
local_dir = snapshot_download("hf-internal-testing/processor_with_lm") | ||
speech_recognizer = pipeline( | ||
task="automatic-speech-recognition", | ||
model=local_dir, | ||
) | ||
self.assertEqual(speech_recognizer.type, "ctc_with_lm") | ||
|
||
ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation").sort("id") | ||
audio = ds[40]["audio"]["array"] | ||
|
||
n_repeats = 2 | ||
audio_tiled = np.tile(audio, n_repeats) | ||
|
||
output = speech_recognizer([audio_tiled], batch_size=2) | ||
|
||
self.assertEqual(output, [{"text": ANY(str)}]) | ||
self.assertEqual(output[0]["text"][:6], "<s> <s") | ||
|
||
@require_torch | ||
@slow | ||
def test_chunking(self): | ||
|
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
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.
This is not needed, since you've added the test directly to the processor (which is better 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.
Will remove it then since it's testing twice the same thing.