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

implement an efficient bpe function using stack #339

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

Conversation

copyrightly
Copy link

The original bpe function looks for the bigram with the smallest bpe_ranks value in a word then merge this bigram, and repeating this process in a while loop.

We use a stack to implement the process in a linear O(n) complexity, and the code is also much simpler than before.

See the performance comparison below:
text is from https://www.reedbeta.com/blog/programmers-intro-to-unicode/
my_enc.encode represents the encode function using the original bpe fucntion, and my_enc.my_encode represents the encode function using the modified bpe function
Screenshot 2024-05-25 at 11 03 48 PM

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