| 154 | } |
| 155 | |
| 156 | std::vector<int> CoreBPE::encode_ordinary(const std::string& text) const { |
| 157 | std::vector<int> result; |
| 158 | // Split text using regex |
| 159 | auto pieces = split_text(text, 0, text.length()); |
| 160 | for (const auto& piece : pieces) { |
| 161 | std::vector<unsigned char> bytes(piece.begin(), piece.end()); |
| 162 | // TODO: check if the bytes exist in the encoder, direct lookup before falling back to BPE. |
| 163 | byte_pair_encode(bytes, encoder, result); |
| 164 | } |
| 165 | |
| 166 | return result; |
| 167 | } |
| 168 | |
| 169 | std::pair<std::vector<int>, int> CoreBPE::encode(const std::string& text, const emhash8::HashSet<std::string>& allowed_special) { |
| 170 | std::vector<int> result; |
no test coverage detected