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 + Test #8049

Merged
merged 1 commit into from
Oct 26, 2020
Merged

Fix + Test #8049

merged 1 commit into from
Oct 26, 2020

Conversation

LysandreJik
Copy link
Member

Fix an edge case of the blenderbot-90 tokenizer.

Closes #8029

Context

If the blenderbot-90 tokenizer is used to tokenize the following sequence:

sequence = "Ok ."

It will split it in two tokens at first:

split_tokens.extend([t for t in self.bpe(token).split(" ")])

Those two tokens will be ['Ok', '.']

The issue is that, when passed the second token, the bpe method will convert it from '.' to ' .' here:

token = re.sub("([.,!?()])", r" \1", token)

This then gets split on spaces here:

This is where the issue lies, as it creates two strings: ["", "."], the first one being empty.

It then crashes a bit further as we try to index the empty string:

word = tuple(list(word[:-1]) + [word[-1] + "</w>"])

Proposal

Ensure that the token has a length > 0 before trying to manage it, otherwise ignore that token.

Added a test.

@LysandreJik LysandreJik requested a review from sshleifer October 26, 2020 13:21
Copy link
Contributor

@sshleifer sshleifer left a comment

Choose a reason for hiding this comment

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

Great catch!

@@ -166,6 +166,9 @@ def bpe(self, token: str) -> str:
tokens = token.split(" ")
words = []
for token in tokens:
if not len(token):
Copy link
Contributor

Choose a reason for hiding this comment

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

if not token also works

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right!

@LysandreJik LysandreJik merged commit cbad90d into master Oct 26, 2020
@LysandreJik LysandreJik deleted the fix-blenderbot-90-tokenizer branch October 26, 2020 16:32
fabiocapsouza pushed a commit to fabiocapsouza/transformers that referenced this pull request Nov 15, 2020
fabiocapsouza added a commit to fabiocapsouza/transformers that referenced this pull request Nov 15, 2020
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.

BlenderbotSmallTokenizer throws tuple index out of range error for stopword
2 participants