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

Adding hugging-face tokenizer #3270

Merged
merged 5 commits into from
Mar 17, 2023
Merged

Conversation

arunppsg
Copy link
Contributor

Pull Request Template

Description

I am adding support for using huggingface tokenizers in DeepChem in this pull request. To this end, I have added a class HuggingFaceFeaturizer which allows use of hugging-face tokenizers with a has-a relationship model. Corresponding tests have also been added.

Type of change

Please check the option that is related to your PR.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
    • In this case, we recommend to discuss your modification on GitHub issues before creating the PR
  • Documentations (modification for documents)

Checklist

  • My code follows the style guidelines of this project
    • Run yapf -i <modified file> and check no errors (yapf version must be 0.32.0)
    • Run mypy -p deepchem and check no errors
    • Run flake8 <modified file> --count and check no errors
    • Run python -m doctest <modified file> and check no errors
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New unit tests pass locally with my changes
  • I have checked my code and corrected any misspellings

Copy link
Member

@rbharath rbharath 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 minor comments

deepchem/feat/huggingface_featurizer.py Show resolved Hide resolved
deepchem/feat/huggingface_featurizer.py Outdated Show resolved Hide resolved


def testHuggingFaceFeaturizer():
# NOTE: The test depends on the sanity of the pretrained tokenizer,
Copy link
Member

Choose a reason for hiding this comment

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

How fast is this test to run? If the download is fast, this is probably OK.

Copy link
Member

Choose a reason for hiding this comment

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

Can you explain more what the comment means? That the sanity of the pretrained tokenizer isn't guaranteed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The download took ~5 second.

By sanity, if the vocabulary is modified or deleted (which can be since we are depending on an external resource), the test might fail.

Copy link
Member

Choose a reason for hiding this comment

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

Can you update the comment to have the explanation you gave? sanity is an ambiguous term while your explanation here is clearer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated comment in 607baf5

Copy link
Member

@rbharath rbharath left a comment

Choose a reason for hiding this comment

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

One more minor comment and should be good to go soon



def testHuggingFaceFeaturizer():
# NOTE: The test depends on the sanity of the pretrained tokenizer,
Copy link
Member

Choose a reason for hiding this comment

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

Can you update the comment to have the explanation you gave? sanity is an ambiguous term while your explanation here is clearer

Copy link
Member

@rbharath rbharath left a comment

Choose a reason for hiding this comment

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

Almost good to go. One minor request for clarification


def __init__(
self,
tokenizer: 'transformers.tokenization_utils_fast.PreTrainedTokenizerFast'
Copy link
Member

Choose a reason for hiding this comment

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

I am not familiar with this notation. The type of the tokenizer is set to a string? Is this something using in type checking to avoid a circular import?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

transformers is an expensive module for import (takes about 3-4 seconds in my machine).

In the above module, we need to import the transformers module only for type checking purpose. Hence, I have enclosed it in strings so that it is hided from the interpreter runtime, thereby reducing import time of the module. During type check, it gets imported because the variable TYPE_CHECKING (used here) will be True.

I found this usage from python docs (ref) and I have also seen a similar usage in other projects.

Copy link
Member

@rbharath rbharath left a comment

Choose a reason for hiding this comment

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

LGTM. Feel free to merge in once CI looks good

@arunppsg arunppsg merged commit ee8430c into deepchem:master Mar 17, 2023
@arunppsg arunppsg deleted the hf-tokenizer branch April 11, 2023 09:20
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

2 participants