Buckets:

rhtse's picture
download
raw
884 Bytes
"""The canonical ByT5 byte table (fixed, no vocab files).
Stock google/byt5 tokenizers map UTF-8 byte b to id b+3 and append
EOS(1); pad=0, unk=2. Ids are NOT raw byte values — feeding text.bytes
directly produces silent garbage on real models.
"""
from __future__ import annotations
BYTE_OFFSET = 3
PAD_ID = 0
EOS_ID = 1
UNK_ID = 2
def encode(text: str) -> list[int]:
"""Canonical byte-level tokenization (byte+3 table, trailing EOS)."""
return [b + BYTE_OFFSET for b in text.encode("utf-8")] + [EOS_ID]
def decode(token_ids: list[int]) -> str:
"""Token ids -> text; stops at EOS, maps id-3 back to a byte."""
out = bytearray()
for token in token_ids:
if token == EOS_ID:
break
if token in (PAD_ID, UNK_ID):
continue
out.append((token - BYTE_OFFSET) % 256)
return out.decode("utf-8", errors="replace")

Xet Storage Details

Size:
884 Bytes
·
Xet hash:
accd33d6d416f737b80b69fc5b4ba27913db456918ba1e09b400d3c42eb20a69

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.