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

Fix repeated characters handling in BPE tokenization (e.g., 'RR' in 'Strawberry') #336

Conversation

Sachleens
Copy link

Fix repeated characters handling in BPE tokenization (e.g., 'RR' in 'Strawberry')

  • Resolved an issue in _byte_pair_merge where repeated characters like 'RR' in 'Strawberry' were incorrectly handled.

  • Updated the logic in _byte_pair_merge to ensure missing pairs are logged and handled properly.

  • Added a test case test_repeated_r_in_strawberry to verify correct tokenization.

2024-09-05 22_22_10-bug-fix

…Strawberry')

- Resolved an issue in `_byte_pair_merge` where repeated characters like 'RR' in 'Strawberry' were not correctly handled.

- Updated the logic in `_byte_pair_merge` to ensure missing pairs are logged and handled properly.

- Added a test case `test_repeated_r_in_strawberry` to verify correct tokenization.
Copy link

@RahulVadisetty91 RahulVadisetty91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ju

nstead of making the ranks.get call twice (once for unwrap_or and again for unwrap_or_else), it would be better to store the result in a variable and then use it.

let rank = ranks.get(&piece[i..i + 2]).unwrap_or_else(|| {
eprintln!("Missing pair: {:?}", &piece[i..i + 2]);
&Rank::MAX
});
let rank = *rank;

@hauntsaninja
Copy link
Collaborator

Thanks, but there isn't a bug here

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.

3 participants