| 49 | */ |
| 50 | |
| 51 | struct Tokenizer { |
| 52 | // vector where the index is the token id and the value is the token string |
| 53 | std::vector<std::string> vocab; |
| 54 | // trie mapping token strings to token ids |
| 55 | TokenTrie vocab_trie; |
| 56 | |
| 57 | int bos_id = -1; |
| 58 | int eos_id = -1; |
| 59 | int eot_id = -1; |
| 60 | // start index of the byte fallback range (256 tokens). -1 if none. |
| 61 | int byte_fallback_start = -1; |
| 62 | |
| 63 | // convenience array containing the decodings for the fixed 256 byte fallbacks '{0x00}\0', '{0x01}\0', ..., '{0xFF}\0'. |
| 64 | // TODO: use constexpr? |
| 65 | std::string byte_pieces[256]; |
| 66 | |
| 67 | Tokenizer(const YALMData& data); |
| 68 | |
| 69 | std::vector<int> encode(const std::string& text, bool encode_bos) const; |
| 70 | std::string decode_one(int prev_token, int token) const; |
| 71 | std::string encoding_to_debug_string(const std::vector<int>& encoding) const; |
| 72 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected