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

Batch encoding decoding #22

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

ezzaldeeen
Copy link

Batch encoding and decoding:

from minbpe import BasicTokenizer
tokenizer = BasicTokenizer()
tokenizer.train(very_long_training_string, vocab_size=4096)
tokenizer.encode_batch(["hello world", "bye world"]) # list[string] -> list[tokens]
tokenizer.decode_batch([[1000, 2000, 3000], [1000, 2000, 3000]]) # list[tokens] -> list[string]
from minbpe import RegexTokenizer
tokenizer = RegexTokenizer()
tokenizer.train(very_long_training_string, vocab_size=32768)
tokenizer.encode_batch(["hello world", "bye world"]) # list[string] -> list[tokens]
tokenizer.decode_batch([[1000, 2000, 3000], [1000, 2000, 3000]]) # list[tokens] -> list[string]

@ezzaldeeen ezzaldeeen marked this pull request as draft February 20, 2024 14:42
@karpathy
Copy link
Owner

Is this part of some official API of tokenizers somewhere that you're trying to match? Otherwise if it's just a 2-line wrapper it's best done outside, in code and manually?

@ezzaldeeen
Copy link
Author

agree with you. did it just to match the behavior of tiktoken

@ezzaldeeen ezzaldeeen marked this pull request as ready for review February 20, 2024 15:40
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.

2 participants