| 720 | } |
| 721 | |
| 722 | static std::string decode_gpt2_bpe(const std::string & tok) { |
| 723 | std::string out; |
| 724 | out.reserve(tok.size()); |
| 725 | const char * p = tok.c_str(); |
| 726 | const char * end = p + tok.size(); |
| 727 | while (p < end) { |
| 728 | int cplen; |
| 729 | uint32_t cp = utf8_decode(p, (size_t)(end - p), &cplen); |
| 730 | out.push_back((char)gpt2_unicode_to_byte(cp)); |
| 731 | p += cplen; |
| 732 | } |
| 733 | return out; |
| 734 | } |
| 735 | |
| 736 | std::string Tokenizer::token_text(int32_t id) const { |
| 737 | if (id < 0 || id >= (int32_t)id_to_token_.size()) return ""; |
no test coverage detected