MCPcopy Create free account
hub / github.com/Luce-Org/lucebox-hub / encode_gpt2_bpe

Function encode_gpt2_bpe

server/src/server/tokenizer.cpp:354–361  ·  view source on GitHub ↗

Convert a raw UTF-8 text piece to GPT-2 byte-encoded form for BPE lookup.

Source from the content-addressed store, hash-verified

352
353// Convert a raw UTF-8 text piece to GPT-2 byte-encoded form for BPE lookup.
354static std::string encode_gpt2_bpe(const std::string & text) {
355 std::string out;
356 out.reserve(text.size() * 2); // GPT-2 encoding may expand
357 for (uint8_t b : text) {
358 out += byte_to_gpt2_unicode(b);
359 }
360 return out;
361}
362
363// Encode a single pre-tokenized piece using BPE merges.
364std::vector<int32_t> Tokenizer::bpe_encode_piece(const std::string & piece) const {

Callers 1

bpe_encode_pieceMethod · 0.85

Calls 2

byte_to_gpt2_unicodeFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected