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

XLMRobertaTokenizer.detokenize method is not wokring #1282

Closed
onting opened this issue Oct 24, 2023 · 2 comments · Fixed by #1289
Closed

XLMRobertaTokenizer.detokenize method is not wokring #1282

onting opened this issue Oct 24, 2023 · 2 comments · Fixed by #1289
Assignees
Labels
stat:contributions welcome Add this label to feature request issues so they are separated out from bug reporting issues type:Bug Something isn't working

Comments

@onting
Copy link

onting commented Oct 24, 2023

Describe the bug

detokenize method is not available for XLMRobertaTokenizer class

To Reproduce

tokenizer = keras_nlp.models.XLMRobertaTokenizer.from_preset("xlm_roberta_base_multi")
for sentence in tokenizer.detokenize(tokenizer(["한국어 토크나이즈", "This is a bug example"])).numpy():
  print(sentence.decode())

Expected behavior

한국어 토크나이즈
This is a bug example

Additional context

The decode method has been worked with code like below.

def detokenize(self, ids):
        ids = tf.ragged.boolean_mask(ids, tf.not_equal(ids, self.mask_token_id))
        ids = tf.subtract(ids, 1)
        return super().detokenize(ids)

So, it must be related with index mishaps. And it seems like list concatenation mishap like below
https://github.com/keras-team/keras-nlp/blob/2b02bff6d7395898f0ab53476662a972c913f39b/keras_nlp/models/xlm_roberta/xlm_roberta_tokenizer.py#L107-L114
The concatenation increase all indices in previous vocabulary, and it affects on super().detokenize(ids).

@onting onting added the type:Bug Something isn't working label Oct 24, 2023
@mattdangerw mattdangerw added the stat:contributions welcome Add this label to feature request issues so they are separated out from bug reporting issues label Oct 25, 2023
@mattdangerw
Copy link
Member

mattdangerw commented Oct 25, 2023

Good catch! Valid bug, and indeed it looks like we are just not properly reversing the index remapping that is done after sentepiece tokenization (this is just a weird quirk of xlm roberta).

Are you interested in working on a fix? If not will find an owner soon.

@onting
Copy link
Author

onting commented Oct 27, 2023

@mattdangerw I'm not confident in fixing. Other people should manage this one better.
Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stat:contributions welcome Add this label to feature request issues so they are separated out from bug reporting issues type:Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants