Shape Unicode-heavy inventories
Retain frequent adjacent Unicode pairs and split unproductive boundaries before BPE training. The measured cutoff travels with the inventory.
Rust corePython API
Fast and faithful byte-pair encoding for large, multilingual corpora—without approximating the model.
pip install ffbpe
Input stream
[你][好]
48,392
[token][izer]
31,705
freq ≥ measured boundary
exact
One release run · 64 MiB Chinese fixture · not a universal speed claim.
Designed for the hard part
FFBPE separates corpus shaping, counting, training, and encoding so each stage can scale without quietly changing the learned model.
Retain frequent adjacent Unicode pairs and split unproductive boundaries before BPE training. The measured cutoff travels with the inventory.
An optional hot-pair window bounds persistent occurrence postings while preserving global frequencies and deterministic winners.
Feed replayable Python iterables into bounded Rust batches, merge partitioned counters, and avoid a corpus-sized Python dictionary.
Save self-describing models, use GPT-2 or lossless Unicode files, and bring existing integrations through a tiktoken-shaped API.
Five-minute path
The high-level Python API covers the common path. Drop down to explicit counters and trainers only when the corpus demands it.
Read the Python quickstartfrom ffbpe import BpeEncoder, train_bpe
model = train_bpe(
["hello world", "hello tokenizer"],
vocab_size=280,
special_tokens=["<|endoftext|>"],
)
ids = model.encode("hello world")
assert model.decode(ids) == "hello world"
model.save_pretrained("my-tokenizer")
encoder = BpeEncoder.from_pretrained("my-tokenizer")
Scroll horizontally to see the complete example
Measured, qualified, reproducible
This comparison measures FFBPE inventory shaping. Segmentation changes, so it is not a model-parity claim. Always benchmark representative text.
Read the benchmark contractStart exact