Skip to content

Added tokenize keyword arguments to feature extraction pipeline #19382

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 3 commits into from
Oct 11, 2022

Conversation

quancore
Copy link
Contributor

@quancore quancore commented Oct 6, 2022

What does this PR do?

The PR adds keyword arguments for the tokenizer for the feature extraction pipeline. Fixes: #19374

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.
@LysandreJik
@Narsil

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Oct 6, 2022

The documentation is not available anymore as the PR was closed or merged.

@LysandreJik LysandreJik requested a review from Narsil October 6, 2022 18:18
Copy link
Contributor

@Narsil Narsil 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 this.

Thanks for the tests too !
I added a remark to keep from breaking anything in user code.

preprocess_params = {}
if truncation is not None:
preprocess_params["truncation"] = truncation
def _sanitize_parameters(self, tokenize_kwargs=None, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately we have to keep truncation in there since it was already allowed in order to NOT break anything.

Something like:

def _sanitize_parameters(self, truncation=None, tokenize_kwargs=None, **kwargs):
    # handle tokenize_kwargs first
    if truncation is not None:
         if 'truncation' in tokenize_kwargs:
             raise ValueError("This is defined twice")
         tokenize_kwargs["truncation"] = truncation
    

Copy link
Contributor Author

@quancore quancore Oct 7, 2022

Choose a reason for hiding this comment

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

@Narsil But the problem is truncation is already a parameter of the tokenizer, why the parameter should be kept separately?

Copy link
Contributor

Choose a reason for hiding this comment

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

Because it was there before, hence users might (and probably HAVE) started using it.
And since we cannot break user code, we have to keep backward compatibility with it.

@Narsil
Copy link
Contributor

Narsil commented Oct 7, 2022

After checking, the broken tests are exactly broken by the lack of truncation support.

Also for quality you should be able to to

pip install -e .[dev] #  or pip install transformers[dev]
make fixup

Cheers.

@quancore
Copy link
Contributor Author

@Narsil I made the changes you indicate.

Copy link
Contributor

@Narsil Narsil left a comment

Choose a reason for hiding this comment

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

LGTM.

@sgugger

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.

A couple of nits, but LGTM otherwise! Thanks a lot for working on this!

@quancore
Copy link
Contributor Author

@sgugger I have moved the import to top.

@sgugger
Copy link
Collaborator

sgugger commented Oct 11, 2022

Thanks a lot!

@sgugger sgugger merged commit 70a058b into huggingface:main Oct 11, 2022
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.

Feature extraction pipeline not consider parameters
4 participants