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

Add an add_prefix_space Arg in BytePairTokenizer #715

Merged
merged 6 commits into from
Feb 3, 2023

Conversation

shivance
Copy link
Collaborator

@shivance shivance commented Feb 2, 2023

Closes #436

cc : @abheesht17

@@ -87,7 +87,7 @@ def remove_strings_from_inputs(tensor, string_to_remove):
return result


def split_strings_for_bpe(inputs):
def split_strings_for_bpe(inputs, add_prefix_space):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Will this work 🤔? We are passing this argument in this function, but not actually doing anything with it inside the function.

I was thinking of doing something along these lines in the tokenize() function:

    def tokenize(self, inputs):
        if not isinstance(inputs, (tf.Tensor, tf.RaggedTensor)):
            inputs = tf.convert_to_tensor(inputs)
        if self.add_prefix_space:
            inputs = tf.strings.join([" ", inputs])
        ...

Trial:

>>> import tensorflow as tf
>>> inputs = tf.constant(["add space at the beginning of every string", "we can use tf.strings.join(...)"])
>>> inputs
<tf.Tensor: shape=(2,), dtype=string, numpy=
array([b' add space at the beginning of every string',
       b' we can use tf.strings.join(...)'], dtype=object)>

CC: @mattdangerw

@shivance
Copy link
Collaborator Author

shivance commented Feb 2, 2023

Not sure why code format check fails

image

Ran format script locally

@abheesht17
Copy link
Collaborator

Not sure why code format check fails

image

Ran format script locally

Upgrade black version.

pip install --upgrade black

@abheesht17
Copy link
Collaborator

@shivance, please add a unit test as well

@shivance
Copy link
Collaborator Author

shivance commented Feb 2, 2023

Thanks @abheesht17 , just found #708

@shivance
Copy link
Collaborator Author

shivance commented Feb 2, 2023

cc: @jbischof
Ready for review

Copy link
Contributor

@chenmoneygithub chenmoneygithub left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Also thanks Abi for the careful review!

@shivance
Copy link
Collaborator Author

shivance commented Feb 2, 2023

Yes , definitely Thanks @abheesht17 !!

Copy link
Member

@mattdangerw mattdangerw left a comment

Choose a reason for hiding this comment

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

This looks good to me! One minor comment on the docstring.

keras_nlp/tokenizers/byte_pair_tokenizer.py Outdated Show resolved Hide resolved
@mattdangerw mattdangerw merged commit 6cec401 into keras-team:master Feb 3, 2023
@mattdangerw
Copy link
Member

Thank you!!

@shivance shivance deleted the add_prefix_space branch February 13, 2023 13:55
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.

Add an add_prefix_space Arg in RobertaPreprocessor
4 participants