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

Fix RobertaFeaturizer #3476 #3898

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

quincylin1
Copy link
Contributor

@quincylin1 quincylin1 commented Mar 15, 2024

Description

Fix #3476

Convert datapoints to List if it is a pd.Series and add padding to pad the embeddings to the same length

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

@arunppsg
Copy link
Contributor

Hey, it seems there are some failing tests (see here). Could you take a look at it?

@quincylin1
Copy link
Contributor Author

Hey, it seems there are some failing tests (see here). Could you take a look at it?

Modified the unit tests in test_roberta_tokenizer.py slightly. Please let me know if there's any issue :)

@arunppsg
Copy link
Contributor

The changes looks good to me and the failures are not related to this PR. I request @rbharath for a second pass.

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.

I have a few questions on the changes below

def __call__(self, *args, **kwargs) -> Dict[str, List[int]]:
return super().__call__(*args, **kwargs)
def __call__(self,
datapoints,
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 add a type annotation here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please see the latest commit

def __call__(self,
datapoints,
padding: bool = True,
**kwargs) -> Dict[str, List[int]]:
Copy link
Member

Choose a reason for hiding this comment

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

Given we are not directly calling the superclass, let's add a brief docstring here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please see the latest commit

@@ -16,8 +16,7 @@ def test_smiles_call():
add_special_tokens=True,
truncation=True)
for emb in [embedding, embedding_long]:
assert 'input_ids' in emb.keys() and 'attention_mask' in emb.keys()
Copy link
Member

Choose a reason for hiding this comment

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

Why are we removing asserts here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the __call__ function in RobertaFeaturizer now returns the input_ids only, which are the actual embeddings of the molecules. The reason is that _featurize_shard() inCSVLoader is later called, in which the features List needs the embeddings only but not the attention masks (see here). This is actually why I modified the __call__ in RobertaFeaturizer so that it returns the input_ids only, unlike the __call__ in the inherited HuggingFace's RobertaTokenizerFast, which returns the whole dict (input_ids and attention_mask).

So the asserts are removed since attention_mask are not returned anymore, and the test asserts that the lists of input_ids for all the molecules all have the same length after specifying padding=True.

@quincylin1
Copy link
Contributor Author

@arunppsg @rbharath any chance to review this PR? Thanks!

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.

How to use RobertaFeaturizer in data loading
3 participants