Byte-level codec¶
trimbed.bytelevel
¶
The GPT-2-style byte-to-unicode mapping used by ByteLevel tokenizers.
bytes_to_unicode
cached
¶
Return the reversible byte -> printable-character map used by ByteLevel.
Borrowed mostly from GPT-2's tokenizer, also see the transformers implementation.
Returns:
| Type | Description |
|---|---|
dict[int, str]
|
A mapping of all 256 byte values to distinct printable characters, e.g.
|
unicode_to_bytes
cached
¶
Return the inverse of bytes_to_unicode.
E.g. "Ġ" -> 32 and "Ċ" -> 10.
byte_level_alphabet
cached
¶
Return the 256 characters a ByteLevel pre-tokenizer can produce.
Every one of them must stay in the vocabulary of a byte-level tokenizer, otherwise some byte sequences become unencodable.
decode_byte_level
¶
Turn a byte-level token back into the text it represents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token
|
str
|
A token as stored in a ByteLevel vocabulary, e.g. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The decoded text, or |