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

fix showing unknown token at gpt_tokenize #801

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

katsu560
Copy link
Contributor

As for current implementation, gpt_tokenize() shows each byte of multi bytes character if unknown token is existed, like below

test_gpt_tokenizer : 0 tests failed out of 0 tests.
gpt_tokenize: unknown token ' '
gpt_tokenize: unknown token ' '
gpt_tokenize: unknown token ' '
main: number of tokens in prompt = 6
main: token[0] =   5619, 日本で
main: token[1] =   3300, 一番
main: token[2] =   1737, 高い
main: token[3] =  14218, 山は
main: token[4] =  37814, 何で
main: token[5] =  24250, すか

I fixed with stopping show each bytes as below.

test_gpt_tokenizer : 0 tests failed out of 0 tests.
gpt_tokenize: unknown token '?'
main: number of tokens in prompt = 6
main: token[0] =   5619, 日本で
main: token[1] =   3300, 一番
main: token[2] =   1737, 高い
main: token[3] =  14218, 山は
main: token[4] =  37814, 何で
main: token[5] =  24250, すか

please confirm this.

-- detail --
original:
$ ./240407up/gpt-neox.org --repeat-last-n 256 --repeat-penalty 1.2 -m models/cyberagent/ggml-calm-1b-q4_0.bin -s 7654321 -p "日本で一番高い山は何ですか?"
main: seed = 7654321
gpt_neox_model_load: loading model from 'models/cyberagent/ggml-calm-1b-q4_0.bin' - please wait ...
gpt_neox_model_load: n_vocab = 52096
gpt_neox_model_load: n_ctx = 2048
gpt_neox_model_load: n_embd = 2048
gpt_neox_model_load: n_head = 16
gpt_neox_model_load: n_layer = 24
gpt_neox_model_load: n_rot = 128
gpt_neox_model_load: par_res = 0
gpt_neox_model_load: ftype = 2002
gpt_neox_model_load: qntvr = 2
gpt_neox_model_load: ggml ctx size = 1917.12 MB
gpt_neox_model_load: memory_size = 384.00 MB, n_mem = 49152
gpt_neox_model_load: .................................... done
gpt_neox_model_load: model size = 764.92 MB / num tensors = 292
extract_tests_from_file : No test file found.
test_gpt_tokenizer : 0 tests failed out of 0 tests.
gpt_tokenize: unknown token ' '
gpt_tokenize: unknown token ' '
gpt_tokenize: unknown token ' '
main: number of tokens in prompt = 6
main: token[0] = 5619, 日本で
main: token[1] = 3300, 一番
main: token[2] = 1737, 高い
main: token[3] = 14218, 山は
main: token[4] = 37814, 何で
main: token[5] = 24250, すか

日本で一番高い山は何ですか?」。そんな質問を何度か受けてきましたが、 ...

fixed:
$ ./240407up/gpt-neox.mod --repeat-last-n 256 --repeat-penalty 1.2 -m models/cyberagent/ggml-calm-1b-q4_0.bin -s 7654321 -p "日本で一番高い山は何ですか?"
main: seed = 7654321
gpt_neox_model_load: loading model from 'models/cyberagent/ggml-calm-1b-q4_0.bin' - please wait ...
gpt_neox_model_load: n_vocab = 52096
gpt_neox_model_load: n_ctx = 2048
gpt_neox_model_load: n_embd = 2048
gpt_neox_model_load: n_head = 16
gpt_neox_model_load: n_layer = 24
gpt_neox_model_load: n_rot = 128
gpt_neox_model_load: par_res = 0
gpt_neox_model_load: ftype = 2002
gpt_neox_model_load: qntvr = 2
gpt_neox_model_load: ggml ctx size = 1917.12 MB
gpt_neox_model_load: memory_size = 384.00 MB, n_mem = 49152
gpt_neox_model_load: .................................... done
gpt_neox_model_load: model size = 764.92 MB / num tensors = 292
extract_tests_from_file : No test file found.
test_gpt_tokenizer : 0 tests failed out of 0 tests.
gpt_tokenize: unknown token '?'
main: number of tokens in prompt = 6
main: token[0] = 5619, 日本で
main: token[1] = 3300, 一番
main: token[2] = 1737, 高い
main: token[3] = 14218, 山は
main: token[4] = 37814, 何で
main: token[5] = 24250, すか

日本で一番高い山は何ですか?」。そんな質問を何度か受けてきましたが、 ...

Copy link
Owner

@ggerganov ggerganov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be simplified - see comments

Comment on lines +343 to +344
auto unk = word.substr(i, 1).data();
unknown.push_back(*unk);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this just:

Suggested change
auto unk = word.substr(i, 1).data();
unknown.push_back(*unk);
unknown.push_back(word[i]);

Comment on lines +351 to +352
std::string unkstr(unknown.begin(), unknown.end());
fprintf(stderr, "%s: unknown token '%s'\n", __func__, unkstr.data());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::string unkstr(unknown.begin(), unknown.end());
fprintf(stderr, "%s: unknown token '%s'\n", __func__, unkstr.data());
fprintf(stderr, "%s: unknown token '%s'\n", __func__, unknown.data());

Comment on lines +334 to +335
std::string unkstr(unknown.begin(), unknown.end());
fprintf(stderr, "%s: unknown token '%s'\n", __func__, unkstr.data());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::string unkstr(unknown.begin(), unknown.end());
fprintf(stderr, "%s: unknown token '%s'\n", __func__, unkstr.data());
fprintf(stderr, "%s: unknown token '%s'\n", __func__, unknown.data());

Comment on lines +323 to +325
// unknown token
std::vector<char> unknown;
unknown.clear();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// unknown token
std::vector<char> unknown;
unknown.clear();
// unknown token
std::vector<char> unknown;

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

Successfully merging this pull request may close these issues.

2 participants