Skip to content
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

Feature Extractor: Wav2Vec2 & Speech2Text - Allow truncation + padding=longest #13600

Conversation

patrickvonplaten
Copy link
Contributor

@patrickvonplaten patrickvonplaten commented Sep 16, 2021

What does this PR do?

For training is speech it's quite important that we are able to make use of the padding="longest" a.k.a dynamic batching in PyTorch on GPU since speech inputs can vary from 2 seconds to up to 30 seconds. We also want to be able to use truncation with padding="longest" in such a case. This PR enables using truncation (i.e. cutting sequences to a max length of x seconds) with the padding="longest" mode.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@patrickvonplaten patrickvonplaten changed the title correct Feature Extractor: Wav2Vec2 & Speech2Text - Allow truncation + padding=longest Sep 16, 2021
raise ValueError(
"When setting ``truncation=True``, make sure that ``max_length`` is defined and ``padding='max_length'``"
)
raise ValueError("When setting ``truncation=True``, make sure that ``max_length`` is defined.")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we do allow truncation=True + padding="longest"

Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this and nice new tests!

src/transformers/feature_extraction_sequence_utils.py Outdated Show resolved Hide resolved
Copy link
Member

@anton-l anton-l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for catching the bug :)

Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
@patrickvonplaten patrickvonplaten merged commit 4d5b4c7 into huggingface:master Sep 16, 2021
@patrickvonplaten patrickvonplaten deleted the correct_sequence_feat_extractor_truncation branch September 16, 2021 18:03
Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Albertobegue pushed a commit to Albertobegue/transformers that referenced this pull request Jan 13, 2022
…g=longest (huggingface#13600)

* correct

* add tests

* Update src/transformers/feature_extraction_sequence_utils.py

Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>

Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
Albertobegue pushed a commit to Albertobegue/transformers that referenced this pull request Jan 27, 2022
…g=longest (huggingface#13600)

* correct

* add tests

* Update src/transformers/feature_extraction_sequence_utils.py

Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>

Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants