[tokenizers] Ensure that add_prefix_space is propagated to backend_tokenizer.pre_tokenizer#35593
Merged
tomaarsen merged 4 commits intoJan 9, 2025
Conversation
…okenizer in PreTrainedTokenizerFast, rather than relying on subclasses to take care of this.
https://github.com/huggingface/tokenizers/blob/862d1a346a99183017b1eb5ad1aa3133b466784f/bindings/python/src/pre_tokenizers.rs#L672 produces the Exception. They're triggered by the roformer tests, as the RoFormerTokenizerFast uses a custom PreTokenizer.
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
ArthurZucker
approved these changes
Jan 9, 2025
ArthurZucker
left a comment
Collaborator
There was a problem hiding this comment.
Thanks! Kinda long due 🤗
5 tasks
Contributor
|
Thank you @tomaarsen and I agree that this PR well works when the |
Collaborator
|
This was already not working before! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello!
Pull Request overview
add_prefix_spaceis propagated tobackend_tokenizer.pre_tokenizerWhat does this PR do?
This is an extrapolation of #35537, which was a fix to ensure that if
AutoTokenizer.from_pretrained("...", add_prefix_space=True), then the underlyingByteLevelpre-tokenizer (atbackend_tokenizer.pre_tokenizer) is also updated withadd_prefix_space=True.The PR is as simple as moving the patch, which looks like the following snippet, to the end of the
PreTrainedTokenizerFast.__init__method.The if-statement should only be True if the pre-tokenizer accepts "add_prefix_space" as an argument, and I assume that it's safer to override the pre_tokenizer with a new one than updating the
add_prefix_spaceattribute on the pre-tokenizer, as it's all Rust-based behind the scenes.I also added a test that should trigger for all tokenizers where the Rust-based tokenizer should be tested.
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Discussed with @ArthurZucker outside of GitHub.
Who can review?
@ArthurZucker