Skip to content
This repository was archived by the owner on Apr 8, 2026. It is now read-only.

implement an efficient bpe function using stack#339

Open
copyrightly wants to merge 1 commit intoopenai:masterfrom
copyrightly:luwei-branch
Open

implement an efficient bpe function using stack#339
copyrightly wants to merge 1 commit intoopenai:masterfrom
copyrightly:luwei-branch

Conversation

@copyrightly
Copy link
Copy Markdown

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 subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant