Merged
Conversation
|
The documentation is not available anymore as the PR was closed or merged. |
…to nit-added-tokens
ArthurZucker
commented
Oct 2, 2023
| # TODO: Ensure the modified attributes (those are also in the __init__ kwargs) will give identical tokenizers | ||
| # target_keys = self.init_kwargs.keys() | ||
| target_keys = ["model_max_length", "clean_up_tokenization_spaces", "additional_special_tokens"] | ||
| target_keys = list(self.init_kwargs.keys()) |
Collaborator
Author
There was a problem hiding this comment.
when saving; we should overwrite the init_kwargs with the content of self. Don't know why it was not the case before
| with open(added_tokens_file, encoding="utf-8") as added_tokens_handle: | ||
| added_tok_encoder = json.load(added_tokens_handle) | ||
| # legacy: we have to init with (rstrip=True, lstrip=True) | ||
| # legacy: we have to init with (rstrip=True, lstrip=True) (if the token is new? Failing test) |
Collaborator
Author
There was a problem hiding this comment.
Might have to update this. The tests are shitty and the default is biting us
Comment on lines
+2202
to
+2204
| if str(token) in additional_special_tokens: | ||
| # at this point if the token is in `additional_special_tokens` as an str, should be updated | ||
| additional_special_tokens.remove(str(token)) |
Collaborator
Author
There was a problem hiding this comment.
Only use the default legacy values for AddedToken if the token is not already in the added tokens decoder
LysandreJik
approved these changes
Oct 3, 2023
Collaborator
Author
|
A small benchmark on the from transformers import AutoTokenizer
import time
tokenizer = AutoTokenizer.from_pretrained("facebook/nllb-moe-54b")
start = time.time();tokenizer.get_added_vocab();print(time.time()-start)
>>> 0.17021536827087402
start = time.time();{k.content: v for v, k in sorted(tokenizer.added_tokens_decoder.items(), key=lambda item: item[0])};print(time.time()-start)
>>> 0.0054759979248046875
start = time.time();tokenizer.added_tokens_decoder;print(time.time()-start)
0.0007669925689697266will update rust to make |
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. |
This was referenced Oct 3, 2023
ArthurZucker
commented
Oct 3, 2023
Comment on lines
+2204
to
+2208
| if str(token) in additional_special_tokens: | ||
| # at this point the token is in `additional_special_tokens` as an str, let's add the AddedToken info | ||
| additional_special_tokens.remove(str(token)) | ||
| if token.special and token not in additional_special_tokens: | ||
| additional_special_tokens.append(token) |
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.
What does this PR do?
Fixes #26500, fixes #26536