| 380 | } |
| 381 | |
| 382 | bool gpt_vocab_init(const std::string & fname, gpt_vocab & vocab) { |
| 383 | printf("%s: loading vocab from '%s'\n", __func__, fname.c_str()); |
| 384 | |
| 385 | vocab.token_to_id = ::json_parse(fname); |
| 386 | |
| 387 | for (const auto & kv : vocab.token_to_id) { |
| 388 | vocab.id_to_token[kv.second] = kv.first; |
| 389 | } |
| 390 | |
| 391 | printf("%s: vocab size = %d\n", __func__, (int) vocab.token_to_id.size()); |
| 392 | |
| 393 | // print the vocabulary |
| 394 | //for (auto kv : vocab.token_to_id) { |
| 395 | // printf("'%s' -> %d\n", kv.first.data(), kv.second); |
| 396 | //} |
| 397 | |
| 398 | return true; |
| 399 | } |
| 400 | |
| 401 | gpt_vocab::id gpt_sample_top_k_top_p( |
| 402 | const gpt_vocab & vocab, |
nothing calls this directly
no test coverage detected