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 PreTrainedTokenizer.pad when first inputs are empty #9018

Merged
merged 2 commits into from
Dec 11, 2020
Merged

Conversation

sgugger
Copy link
Collaborator

@sgugger sgugger commented Dec 9, 2020

What does this PR do?

Currently, PreTrainedTokenizer.pad errors when the first input_ids are empty (because it tries to guess the type of the tokens by looking at the first element). This PR slightly changes the behavior to loop until we find a non empty list.

Fixes #8674 (not the initial issue but the one mentioned at the end)

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.

This seems reasonable to me, but I would still wait for @thomwolf's review before merging just to be sure.

while len(encoded_inputs["input_ids"][index]) == 0:
index += 1
if index < len(encoded_inputs["input_ids"]):
first_element = encoded_inputs["input_ids"][index][0]
Copy link
Member

Choose a reason for hiding this comment

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

This will still error out if encoded_inputs["input_ids"] is fully empty (while in theory in this case we don't really need to error out but can just return a no-op).

Maybe update the following line (if not isinstance(first_element, int):) to be if not isinstance(first_element, (list, tuple, int)):?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, clever! Will do with a comment on why.

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.

Even better!

@sgugger sgugger merged commit 70527ba into master Dec 11, 2020
@sgugger sgugger deleted the fix_8674 branch December 11, 2020 15:25
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.

Issues Fine-tuning XLNET
3 participants