-
Notifications
You must be signed in to change notification settings - Fork 31.3k
Add dithering to the Speech2TextFeatureExtractor API.
#34638
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
696c984
Add dithering to the `Speech2TextFeatureExtractor` API.
KarelVesely84 9d9382b
update the PR
KarelVesely84 b9a39a7
add unit-tests for dithering, fix docstrings
KarelVesely84 c2087ea
ruff
KarelVesely84 2422fdb
utils/check_copies.py --fix_and_overwrite
KarelVesely84 042699d
Merge remote-tracking branch 'origin/main' into add_dither
KarelVesely84 8658a70
update code, add seed to unit-test
KarelVesely84 dda4695
Merge branch 'main' into add_dither
KarelVesely84 c182442
adding explanation of dithering
KarelVesely84 2fd31df
Merge remote-tracking branch 'origin/main' into add_dither
KarelVesely84 7264638
Merge remote-tracking branch 'origin/main' into add_dither
KarelVesely84 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 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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -144,6 +144,40 @@ def test_call(self): | |
| for enc_seq_1, enc_seq_2 in zip(encoded_sequences_1, encoded_sequences_2): | ||
| self.assertTrue(np.allclose(enc_seq_1, enc_seq_2, atol=1e-3)) | ||
|
|
||
| def test_dither(self): | ||
| np.random.seed(42) # seed the dithering randn() | ||
|
|
||
| # Tests that features with and without little dithering are similar, but not the same | ||
|
Contributor
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. Let's set the seed here, to ensure reproducibility. |
||
| dict_no_dither = self.feat_extract_tester.prepare_feat_extract_dict() | ||
| dict_no_dither["dither"] = 0.0 | ||
|
|
||
| dict_dither = self.feat_extract_tester.prepare_feat_extract_dict() | ||
| dict_dither["dither"] = 1.0 | ||
|
|
||
| feature_extractor_no_dither = self.feature_extraction_class(**dict_no_dither) | ||
| feature_extractor_dither = self.feature_extraction_class(**dict_dither) | ||
|
|
||
| # create three inputs of length 800, 1000, and 1200 | ||
| speech_inputs = [floats_list((1, x))[0] for x in range(800, 1400, 200)] | ||
| np_speech_inputs = [np.asarray(speech_input) for speech_input in speech_inputs] | ||
|
|
||
| # compute features | ||
| input_features_no_dither = feature_extractor_no_dither( | ||
| np_speech_inputs, padding=True, return_tensors="np" | ||
| ).input_features | ||
| input_features_dither = feature_extractor_dither( | ||
| np_speech_inputs, padding=True, return_tensors="np" | ||
| ).input_features | ||
|
|
||
| # test there is a difference between features (there's added noise to input signal) | ||
| diff = input_features_dither - input_features_no_dither | ||
|
|
||
| # features are not identical | ||
| self.assertTrue(np.abs(diff).mean() > 1e-5) | ||
| # features are not too different | ||
| self.assertTrue(np.abs(diff).mean() <= 1e-3) | ||
| self.assertTrue(np.abs(diff).max() <= 1e-2) | ||
|
Comment on lines
+178
to
+179
Contributor
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. Great! |
||
|
|
||
| def test_cepstral_mean_and_variance_normalization(self): | ||
| feature_extractor = self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()) | ||
| speech_inputs = [floats_list((1, x))[0] for x in range(800, 1400, 200)] | ||
|
|
||
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
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.
let's add the comment about "this can help for hard audio in ASR" 😉
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.
ok, added the explanatory comments, thanks!