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

Added test for the way BytePairTokenizer handles the \n\n sequence, which is important in Lama chat templates #1912

Merged
merged 5 commits into from
Oct 16, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion keras_hub/src/tokenizers/byte_pair_tokenizer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
)


@pytest.mark.large
# @pytest.mark.large
martin-gorner marked this conversation as resolved.
Show resolved Hide resolved
class BytePairTokenizerTest(TestCase):
def setUp(self):
super().setUp()
Expand Down Expand Up @@ -111,6 +111,24 @@ def test_whitespace_split(self):
encoded = self.tokenizer(input_data)
self.assertAllEqual(encoded, [1437, 1437, 50140, 50118, 29])

# This is important for Llama3 which uses the \n\n sequence in chat
# templates: \n\n must be tokenized as a single token
input_data = "Hello\n\nHello"
encoded = self.tokenizer(input_data)
# self.assertAllEqual(encoded, [31414, 50140, 31414])
martin-gorner marked this conversation as resolved.
Show resolved Hide resolved

input_data = "Hello\n\n\n\nHello"
encoded = self.tokenizer(input_data)
# self.assertAllEqual(encoded, [31414, 50140, 50140, 31414])
martin-gorner marked this conversation as resolved.
Show resolved Hide resolved

input_data = "Hello\n\n"
encoded = self.tokenizer(input_data)
self.assertAllEqual(encoded, [31414, 50140])

input_data = "Hello\n\n\n\n"
encoded = self.tokenizer(input_data)
self.assertAllEqual(encoded, [31414, 50140, 50140])

def test_special_whitespace(self):
input_data = "\xa0 \xa0 \x3000 s"
encoded = self.tokenizer(input_data)
Expand Down