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

扩展词表代码需优化 #65

Closed
tiandiweizun opened this issue Oct 25, 2023 · 0 comments
Closed

扩展词表代码需优化 #65

tiandiweizun opened this issue Oct 25, 2023 · 0 comments

Comments

@tiandiweizun
Copy link

tiandiweizun commented Oct 25, 2023

expand_vocab里面的add_new_tokens,会把token加到tokens_trie, 仅适用于slow tokenizer,因为fast模式尽管添加了,但是在tokenize的时候直接调用encode_plus,会调用rust,这就会出问题。即如果下载了llama2-xxx-hf的情况下。
model=AutoTokenizer.from_pretrained("d:/models/Llama-2-7b-chat-hf")
model.add_tokens("谁")
print(model.tokenize("你是谁"))
会发现不生效

建议修改:任选其一

  1. AutoTokenizer.from_pretrained("d:/models/Llama-2-7b-chat-hf",use_fast=False)
  2. merge_tokenize过程参见https://github.com/ymcui/Chinese-LLaMA-Alpaca/blob/main/scripts/merge_tokenizer/merge_tokenizers.py
  3. tokenizer.add_tokens(AddedToken(token, normalized=False))

#66

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

No branches or pull requests

1 participant