Example 1
Arguments: [
"Hi",
256
]
Expected result: [
72,
105,
256
]H and i encode to bytes 72 and 105; EOS 256 follows.
Tokenization and attention · Easy
Problem 11 of 50 · Python and NumPy
Encode text as UTF-8 bytes and return their integer values followed by exactly one EOS token. EOS lies outside the byte vocabulary. Preserve whitespace and Unicode exactly; do not split on words or append EOS per character.
def byte_tokenize(text, eos_id):Arguments: [
"Hi",
256
]
Expected result: [
72,
105,
256
]H and i encode to bytes 72 and 105; EOS 256 follows.
Arguments: [
"é",
257
]
Expected result: [
195,
169,
257
]é occupies two UTF-8 bytes, 195 and 169, then EOS 257.