Class Gpt2ByteMap
java.lang.Object
smile.llm.tokenizer.Gpt2ByteMap
GPT-2 / HuggingFace byte-level BPE mapping between raw bytes and the
printable Unicode characters used as
tokenizer.json vocab keys.
HF stores each vocab entry as a string of these mapped characters.
Tiktoken-style BPE operates on raw UTF-8 bytes, so keys must be converted
with vocabTokenToBytes(String) when loading an HF vocab.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic charbyteToUnicode(int unsignedByte) Maps a raw byte to its GPT-2 vocab character (for tests / debugging).static BytesvocabTokenToBytes(String token) Converts an HF vocab token string (GPT-2 unicode-mapped) into the raw byte sequence Tiktoken BPE expects.
-
Method Details
-
vocabTokenToBytes
Converts an HF vocab token string (GPT-2 unicode-mapped) into the raw byte sequence Tiktoken BPE expects. Falls back to UTF-8 oftokenif any character is outside the GPT-2 map (e.g. unusual added tokens).- Parameters:
token- vocab key fromtokenizer.json/vocab.json.- Returns:
- raw bytes for the rank map.
-
byteToUnicode
public static char byteToUnicode(int unsignedByte) Maps a raw byte to its GPT-2 vocab character (for tests / debugging).- Parameters:
unsignedByte- byte value in[0, 255].- Returns:
- the GPT-2 unicode code unit for that byte.
-