-
Notifications
You must be signed in to change notification settings - Fork 27.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
Sentence start got unexpected space #25285
Comments
2 things that could be problematic here
I checked and token 12968 does not have prefix space so it is not 1. |
@chris-ha458 Thanks for taking look. I depart this problem and digged a little bit, this is what I found: Encode one sentence in 2 part (such as question + answer) without any space in them, and then concat the ids, compare with ecnoder the whole sentence at once, THEY ARE NOT SAME. I don't know if this is expected, but this is out of my expecetations. For detail, please run this script on any llama tokeizer: from transformers import LlamaTokenizer
# any LLama tokenizer
tokenizer = LlamaTokenizer.from_pretrained("checkpoints/BiLLa-7B-LLM/tokenizer.model")
def test1():
prefix = "Human:\n用 python 写一段快排\n\nAssistant:"
output = "OK, I will do for u!"
sentence_ids = tokenizer.encode(prefix, add_special_tokens=False)
# b = tokenizer.decode(sentence_ids)
print(sentence_ids)
d = tokenizer.encode(output, add_special_tokens=False)
print(d)
input_ids = sentence_ids + d
# input_ids += [tokenizer.eos_token_id]
o = tokenizer.decode(input_ids)
print(input_ids)
print(o)
def test2():
print('---------------- test2')
prefix = "Human:\n用 python 写一段快排\n\nAssistant:"
output = "OK, I will do for u!"
sentence = prefix + output
sentence_ids = tokenizer.encode(sentence, add_special_tokens=False)
b = tokenizer.decode(sentence_ids)
print(sentence_ids)
print(b)
c = tokenizer.decode([12968])
print(c)
c = tokenizer.decode([9280])
print(c)
c = tokenizer.decode([8949])
print(c)
if __name__ == '__main__':
test1()
test2() Here is interesting thing: the 2 way to encode same sentence got different ids:
And I decode the different ids that might caused space, they actually same character....... So I am totally missed here.... |
Hey! This issue has nothing to do with |
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread. Please note that issues that do not follow the contributing guidelines are likely to be ignored. |
I got some iput_ids which encoded, after append some tgt_ids to input_ids, the new decoded sentences added weired spaces.
Here is the code:
My output:
As you can see, both before Human and OK, there is an space, but actually not expected.
Why?
The text was updated successfully, but these errors were encountered: