Language models, retrieval, prompting, and language adaptation · Encoder–decoder and multilingual models · LNG031 · Model
ByT5
Operates on UTF-8 bytes instead of a learned subword tokenizer, reducing dependence on vocabulary segmentation. Byte-level processing is useful when text includes spelling variation, uncommon scripts, or noisy surface…
In CodeSplash
Documented in the Academy only. There's no Set up button.
- Availability
- Explained here
- Code example
- Component demo, not a trained model
- Who ran it
- CodeSplash's own run
- CodeSplash's run
- The reference's example ran in Python and R here, and they agree.
- The reference's record
- Python: The chapter's authors report running it; there is no record for this entry alone. R: Reviewed but not run: R wasn't available to the reference's authors.
Purpose
Operates on UTF-8 bytes instead of a learned subword tokenizer, reducing dependence on vocabulary segmentation. Byte-level processing is useful when text includes spelling variation, uncommon scripts, or noisy surface forms.
Question / objective
Can byte-level modeling reduce brittleness to tokenizer vocabulary and spelling variation?
Architecture / computational structure
A T5-style encoder–decoder consumes byte identifiers and special tokens. Learned byte embeddings and network weights are parameters; byte-span corruption, input budget, and model size are hyperparameters.
Assumptions
Tokenizer removal does not remove preprocessing choices or language imbalance.
Formula / computational definition
Encode text x as byte sequence b_1:T and optimize the T5-style span-corruption objective over bytes. Byte sequence length differs from character count because UTF-8 uses multiple bytes for some characters.
Parameters and notation
Learned parameters: identified in the architecture subsection. Hyperparameters, design and inference choices: Byte vocabulary and special tokens, span lengths measured in bytes, context budget, encoder/decoder capacity, and handling of invalid generated byte sequences.
Fitting, fine-tuning, and adaptation
Adapt on byte-encoded source/target pairs with conditional cross-entropy, using full weights or supported adapters. Keep limits measured consistently in bytes/tokens and test malformed/noisy inputs. Validate cross-script compute and generation validity; lower tokenization dependence does not remove catastrophic forgetting.
How to use and calibrate
Compare clean and perturbed text, language-specific cost, decoding validity, and task quality; report bytes or characters when comparing perplexity across tokenizations. Use development data for settings and an independent test set for the final estimate. Report uncertainty across examples or seeds when the evaluation design supports it; model scores and self-assessments are not automatically calibrated probabilities of correctness.
Example application
Normalize noisy multilingual product descriptions containing misspellings and unusual characters.
Interpretation / pitfalls
Watch out
Longer byte sequences raise computation and can shorten the effective document context, particularly for scripts with multi-byte characters. The code below isolates one stated component; successful execution does not validate model quality or reproduce the cited experiment.
Python and R code examples
Full implementation route: Transformers includes ByT5 support. R can bridge through reticulate; native Python UTF-8 encoding and R charToRaw demonstrate the input representation. The toy byte example is a preprocessing illustration, not model inference.
Example scope: ByT5 input representation: UTF-8 bytes, not Unicode character count.
Dependencies: Python 3 standard library; base R; shared setup above. No model downloads or external services.
Validation: Python component executed in the combined example script; R counterpart supplied but not runtime-tested here. All numbers are synthetic.
Python and R
The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.
Component demo, not a trained model — ByT5 input representation: UTF-8 bytes, not Unicode character count.
Shared setup for this chapter
import math
def softmax(xs):
m = max(xs)
es = [math.exp(x-m) for x in xs]
return [e/sum(es) for e in es]
def dot(a, b):
return sum(x*y for x, y in zip(a, b))
def matvec(matrix, vector):
return [dot(row, vector) for row in matrix]
def meanvec(rows):
return [sum(row[j] for row in rows)/len(rows) for j in range(len(rows[0]))]
def sigmoid(x):
return 1/(1+math.exp(-x))
def nll(probabilities):
return -sum(math.log(p) for p in probabilities)
text = "café"
byte_ids = list(text.encode("utf-8"))
print(byte_ids, len(text), len(byte_ids))
Component demo, not a trained model — ByT5 input representation: UTF-8 bytes, not Unicode character count.
Shared setup for this chapter
softmax <- function(x) {
shifted <- exp(x-max(x))
shifted/sum(shifted)
}
text <- enc2utf8("café")
byte_ids <- as.integer(charToRaw(text))
print(list(bytes=byte_ids, characters=nchar(text,type="chars"), byte_count=length(byte_ids)))
Sources
- Source 1arxiv.org
From the CodeSplash reference, entry LNG031.