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

Optimal algorithm for _encode_chunk(): 20% faster encoding, with 0.5% better COMPRESSION #84

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Majdoddin
Copy link

This PR reimplements RegexTokenizer._encode_chunk() using dynamic programming to return a guaranteed optimal (minimum number of tokens) tokenization of a chunk.

After training, the vocabulary is fixed. During encoding, _encode_chunk() is called for each chunk to get a tokenization of it. Currently, _encode_chunk() uses something similar to the BPE algorithm used in the training (but with the fixed vocabulary) to determine the tokens. However, this approach is slow and does not guarantee an optimal tokenization of the chunk.

Tested on a 1MB text from wikitext_103, the encoding is more than 20% faster, and the compression is improved by about 0.5%.

…f the chunk in terms of the number of tokens. It uses dynamic programming instead of BPE to encode the chunk. The compression is improved by 0.5%, and it is more than 20% faster.
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.

1 participant