Trainer¶
ffbpe.trainer.BpeTrainer
¶
BpeTrainer(special_tokens, *, unit='byte', initial_alphabet=None, tie_break=None, parallel_merge_min_occurs_in=None, hot_pair_window_size=None, bigram_cutoff_freq=None)
Train a BPE model from a word-frequency inventory.
This wraps the Rust trainer classes exposed via the extension module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
special_tokens
|
Sequence[str]
|
Sequence of tokens reserved in the vocabulary. |
required |
unit
|
Unit
|
Primary segmentation unit. Unicode models may include UTF-8 byte fallback merges. |
'byte'
|
hot_pair_window_size
|
int | None
|
If set, retain occurrence postings for an exact top-K candidate window. Smaller values reduce memory but may require additional inventory scans. |
None
|
bigram_cutoff_freq
|
int | None
|
Inclusive minimum frequency for pair merges performed by automatic
training. Manual |
None
|
Source code in python/ffbpe/trainer.py
hot_pair_window_stats
property
¶
Diagnostics for the bounded pair-posting window, if enabled.
add_words
¶
Add training data.
Accepts either a mapping {word: freq} or an explicit sequence of (word, freq) pairs.
Source code in python/ffbpe/trainer.py
add_word_counter
¶
Replace the training inventory by consuming an exact native word counter.
The counter is empty and reusable after this call. Unlike words(), this
transfer does not construct a Python dictionary.
Source code in python/ffbpe/trainer.py
init_training
¶
train
¶
Train until the vocab reaches vocab_size entries or no eligible pair remains.
Training may finish below the requested size when the inventory is
exhausted or the next pair frequency is below bigram_cutoff_freq.
A target smaller than the current vocabulary is rejected.
Source code in python/ffbpe/trainer.py
train_with_bbpe_fallback
¶
Train a Unicode model with a terminal byte-BPE fallback phase.
primary_vocab_ratio allocates a fraction of learned slots to the initial
Unicode phase. The mandatory 256-byte alphabet and special tokens are
excluded; unused fallback slots return to primary training. A fallback pass
must start before ordinary vocabulary growth and finalizes the trainer, so
create a new trainer for further training. A ratio of 1.0 delegates to
ordinary training and remains extendable; a target at or below the base
vocabulary is a no-op. The pair-frequency cutoff may leave the final
vocabulary below vocab_size.
Source code in python/ffbpe/trainer.py
step
¶
validate_model
¶
Validate the trainer state and return an immutable model snapshot.
save
¶
Validate a snapshot and save it under name.
Source code in python/ffbpe/trainer.py
save_files
¶
Validate a snapshot and save its files.