ByteLevelBPETokenizerFast
_ByteLevelDecodeMixinBPETokenizerFastByteLevelBPETokenizerFast(vocab: dict[str, int], merges: list[tuple[str, str]], add_prefix_space: bool = False, normalizer: Normalizer | None = None, special_tokens: SpecialTokens | None = None)C++-backed byte-level BPE tokenizer.
Identical configuration semantics to
ByteLevelBPETokenizer; uses the engine BPE binding
for the merge hot loop and the same ByteLevel
pre-tokenizer in Python.
Encode outputs are bit-identical to the pure-Python flavour for
the same vocab + same merges.
It takes the parameters of ByteLevelBPETokenizer.
Examples
>>> from lucid.utils.tokenizer import ByteLevelBPETokenizerFast
>>> tok = ByteLevelBPETokenizerFast(vocab={}, merges=[])
>>> tok.train(["the quick brown fox", "the lazy dog sleeps"],
... vocab_size=300)
>>> tok.decode(tok.encode("the quick dog"))
'the quick dog'See Also
ByteLevelBPETokenizer—Pure-Python reference; same vocab format.
Used by 2
Constructors
1__init__
→None__init__(vocab: dict[str, int], merges: list[tuple[str, str]], add_prefix_space: bool = False, normalizer: Normalizer | None = None, special_tokens: SpecialTokens | None = None)Construct a C++-backed byte-level BPE tokenizer.
Parameters
vocabdict[str, int]mergeslist of (str, str)add_ prefix_ spacebool= FalseFalse; RoBERTa default True).normalizer(Normalizer or None, optional, keyword - only)= NoneNFC.Notes
Fixes the pre-tokenizer to ByteLevel and forwards to
BPETokenizerFast.__init__ — which constructs the C++
BPE backend and caches it on _cpp.
Properties
1Class methods
1Instance methods
4Return a shallow copy of the token → id map.
Look up the surface string for a token id.
Persist as both legacy (vocab.json + merges.txt)
AND unified (tokenizer.json) formats.
Re-train in C++ via the parent
BPETokenizerFast.train.
The ByteLevel pre-tokenizer normalizes every byte to its printable form before the corpus reaches the C++ training loop, so the resulting vocab is in byte-mapped form (Hugging Face GPT-2 compatible).
Note: the C++ BPE::train does its OWN whitespace split
on the raw input, so we pre-encode the corpus through the
ByteLevel pre-tokenizer here in Python before handing off —
otherwise the training would learn merges on raw bytes
rather than byte-mapped codepoints.
Parameters
corpusiterable of strvocab_ sizeint= 50 000