| 239 | pos += width; |
| 240 | } |
| 241 | return trim_spaces(std::move(out)); |
| 242 | } |
| 243 | |
| 244 | const std::unordered_set<std::string> & supported_chatterbox_languages() { |
| 245 | static const std::vector<std::string> codes = supported_chatterbox_language_codes(); |
| 246 | static const std::unordered_set<std::string> languages(codes.begin(), codes.end()); |
| 247 | return languages; |
| 248 | } |
| 249 | |
| 250 | std::vector<int32_t> encode_marked_text( |
| 251 | const ChatterboxEnglishTokenizerModel & tokenizer, |
| 252 | const std::string & marked) { |
| 253 | std::vector<int32_t> ids; |
| 254 | std::string segment; |
| 255 | for (size_t pos = 0; pos < marked.size();) { |
| 256 | bool matched_special = false; |
| 257 | for (const auto & special : tokenizer.special_tokens) { |
| 258 | if (!starts_with_at(marked, pos, special)) { |
| 259 | continue; |
| 260 | } |
| 261 | if (!segment.empty()) { |
| 262 | const auto segment_ids = bpe_encode_segment(tokenizer, segment); |
| 263 | ids.insert(ids.end(), segment_ids.begin(), segment_ids.end()); |
| 264 | segment.clear(); |
| 265 | } |
| 266 | const auto it = tokenizer.vocab.find(special); |
| 267 | ids.push_back(it != tokenizer.vocab.end() ? it->second : tokenizer.unk_id); |
| 268 | pos += special.size(); |
| 269 | matched_special = true; |
| 270 | break; |
| 271 | } |
| 272 | if (matched_special) { |
| 273 | continue; |
| 274 | } |
| 275 | const auto [_, width] = read_utf8_codepoint_at(marked, pos); |
| 276 | segment.append(marked, pos, width); |
| 277 | pos += width; |
| 278 | } |
no test coverage detected