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

Function bpe_initial_pieces

src/models/voxcpm2/tokenizer_text.cpp:83–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81}
82
83std::vector<std::string> bpe_initial_pieces(
84 std::string_view normalized_text,
85 const std::unordered_map<std::string, int32_t> & vocab) {
86 std::vector<std::string> pieces;
87 for (size_t offset = 0; offset < normalized_text.size();) {
88 const size_t start = offset;
89 (void) next_utf8_codepoint(normalized_text, offset);
90 std::string piece(normalized_text.substr(start, offset - start));
91 if (vocab.find(piece) != vocab.end()) {
92 pieces.push_back(std::move(piece));
93 continue;
94 }
95 for (size_t i = start; i < offset; ++i) {
96 pieces.push_back(byte_fallback_token(static_cast<unsigned char>(normalized_text[i])));
97 }
98 }
99 return pieces;
100}
101
102bool is_cjk_codepoint(uint32_t codepoint) {
103 return (codepoint >= 0x4E00 && codepoint <= 0x9FFF) ||

Callers 1

bpeMethod · 0.85

Calls 5

next_utf8_codepointFunction · 0.85
byte_fallback_tokenFunction · 0.85
sizeMethod · 0.45
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected