-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[Tokenizer] Support for loading added_tokens_decoder #8997
Merged
DrownFish19
merged 10 commits into
PaddlePaddle:develop
from
DrownFish19:dev_20240823_fix_added_tokens_decoder_load
Aug 28, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f8d0347
fix added_tokens_decoder load
DrownFish19 8af6aeb
fix decode
DrownFish19 5c0d201
Merge remote-tracking branch 'paddlenlp/develop' into dev_20240823_fi…
DrownFish19 c2e8689
fix saving and loading added_token_decoder
DrownFish19 f669c10
fix mamba
DrownFish19 a0efe46
fix special_tokens_map_file load
DrownFish19 228f9ed
fix gemma tokenizer
DrownFish19 45925e2
fix llama tokenzier
DrownFish19 8388aec
revert llama tokenizer
DrownFish19 d6f2f38
fix _decode
DrownFish19 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,18 @@ def vocab_size(self): | |
"""Returns vocab size""" | ||
return self.sp_model.get_piece_size() | ||
|
||
def __len__(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 解决无法添加token的问题 |
||
""" | ||
Returns the vocabulary size. added_tokens_encoder has to be added in the sp_model | ||
""" | ||
added_size = 0 | ||
|
||
for id in self.added_tokens_decoder: | ||
if id >= self.sp_model.get_piece_size(): | ||
added_size += 1 | ||
|
||
return self.vocab_size + added_size | ||
|
||
@property | ||
def bos_token_id(self) -> Optional[int]: | ||
return self.sp_model.bos_id() | ||
|
@@ -104,7 +116,7 @@ def _convert_token_to_id(self, token): | |
|
||
def _convert_id_to_token(self, index): | ||
"""Converts an index (integer) in a token (str) using the vocab.""" | ||
token = self.sp_model.IdToPiece(index) | ||
token = self.sp_model.id_to_piece(index) | ||
return token | ||
|
||
def convert_tokens_to_string(self, tokens): | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,6 +158,12 @@ def vocab_size(self): | |
""" | ||
return len(self.encoder) | ||
|
||
def __len__(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mamba tokenizer的added_tokens_decoder中包含 [0,1]两个重复tokens,之前的计算方式会重复计算这两个token |
||
""" | ||
Size of the full vocabulary with the added tokens. | ||
""" | ||
return len(dict(self.encoder, **self.added_tokens_encoder)) | ||
|
||
def bpe(self, token): | ||
if token in self.cache: | ||
return self.cache[token] | ||
|
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
解决无法添加token的问题