| 248 | } |
| 249 | |
| 250 | void build_cjk_split_map(VoxCPM2TextTokenizer::Impl & impl) { |
| 251 | for (const auto & [id, token] : impl.id_to_token) { |
| 252 | const std::string clean = strip_sentencepiece_prefix(token); |
| 253 | if (!is_pure_multichar_cjk(clean)) { |
| 254 | continue; |
| 255 | } |
| 256 | std::vector<int32_t> char_ids; |
| 257 | for (const auto & ch : utf8_codepoints(clean)) { |
| 258 | const auto it = impl.vocab.find(ch); |
| 259 | if (it == impl.vocab.end()) { |
| 260 | char_ids.clear(); |
| 261 | break; |
| 262 | } |
| 263 | char_ids.push_back(it->second); |
| 264 | } |
| 265 | if (!char_ids.empty()) { |
| 266 | impl.cjk_split_map.emplace(id, std::move(char_ids)); |
| 267 | } |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | std::shared_ptr<const VoxCPM2TextTokenizer::Impl> load_impl(const VoxCPM2Assets & assets) { |
| 272 | auto impl = std::make_shared<VoxCPM2TextTokenizer::Impl>(); |
no test coverage detected