| 42 | } |
| 43 | |
| 44 | std::string Tokenizer::decode_one(int prev_token, int token) const { |
| 45 | const std::string& piece = vocab[token]; |
| 46 | // if following BOS token, sentencepiece decoder strips any leading whitespace |
| 47 | if (prev_token == bos_id && piece[0] == ' ') { |
| 48 | return piece.substr(1); |
| 49 | } |
| 50 | // return byte piece for byte fallback tokens (<0x00>, <0x01>, ..., <0xFF>) |
| 51 | if (byte_fallback_start >= 0 && token >= byte_fallback_start && (token - byte_fallback_start) < 256) { |
| 52 | return byte_pieces[token - byte_fallback_start]; |
| 53 | } |
| 54 | return piece; |
| 55 | } |
| 56 | |
| 57 | std::vector<int> Tokenizer::encode(const std::string& text, bool encode_bos) const { |
| 58 | std::vector<int> out_tokens; |
no outgoing calls
no test coverage detected