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

解决中文加入不生效的问题 #66

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion engines/utils/expand_vocab.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import shutil
import sentencepiece as sp
from transformers import AutoTokenizer, AutoModel
from tokenizers import AddedToken


cur_dir = os.path.dirname(os.path.abspath(__file__))
Expand Down Expand Up @@ -67,7 +68,7 @@ def add_new_tokens(logger, tokenizer, save_path):
raw_vocab = [sp_bpe.id_to_piece(id) for id in range(sp_bpe.get_piece_size())]
clean_vocab = list(set(filter(is_chinese, raw_vocab)))

tokenizer.add_tokens(clean_vocab)
tokenizer.add_tokens([AddedToken(token, normalized=False) for token in clean_vocab])
tokenizer.save_pretrained(save_path)
logger.info(f'New tokens added, new tokenizer is saved to {save_path}.')

Expand Down