-
Notifications
You must be signed in to change notification settings - Fork 301
Handle OOV token in XLMRoBERTaTokenizer's token_to_id function #968
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
Conversation
"""Convert a string token to an integer id.""" | ||
|
||
# OOV token | ||
if token not in self.get_vocabulary(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does sentencepiece not handle the oov token in this case? If we can just remap the output that would be better.
This would require loading the full vocab list into a python list and then iterating over it in its entirety. That's probably quite slow!
return self._vocabulary_prefix.index(token) | ||
|
||
return int(self._sentence_piece.string_to_id(token).numpy()) + 1 | ||
spm_token_id = int(self._sentence_piece.string_to_id(token).numpy()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's compare in tensor space, convert to int at the end?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
/gcbrun |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm! thanks
No description provided.