MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / encode_marked_text

Function encode_marked_text

src/models/chatterbox/text_tokenizer.cpp:241–275  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

239 pos += width;
240 }
241 return trim_spaces(std::move(out));
242}
243
244const 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
250std::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 }

Calls 9

bpe_encode_segmentFunction · 0.85
read_utf8_codepoint_atFunction · 0.85
starts_with_atFunction · 0.70
sizeMethod · 0.45
emptyMethod · 0.45
endMethod · 0.45
beginMethod · 0.45
clearMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected