Skip to content

Fix + Test#8049

Merged
LysandreJik merged 1 commit intomasterfrom
fix-blenderbot-90-tokenizer
Oct 26, 2020
Merged

Fix + Test#8049
LysandreJik merged 1 commit intomasterfrom
fix-blenderbot-90-tokenizer

Conversation

@LysandreJik
Copy link
Copy Markdown
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
Copy Markdown
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!

tokens = token.split(" ")
words = []
for token in tokens:
if not len(token):
Copy link
Copy Markdown
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
Copy Markdown
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
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