class
WhitespaceTokenizerFast
extends
_FastVocabTokenizerWhitespaceTokenizerFast(vocab: dict[str, int] | None = None, special_tokens: SpecialTokens | None = None)C++-backed whitespace tokenizer; bit-identical to
WhitespaceTokenizer.
Same vocab format + OOV-dropping contract as
WhitespaceTokenizer; the encode loop runs in C++ via
the engine WhitespaceTokenizer binding.
Parameters
vocabdict[str, int]= NonePre-built word → id map. Empty = call
train first.Special-token registry.
Examples
>>> from lucid.utils.tokenizer import WhitespaceTokenizerFast
>>> tok = WhitespaceTokenizerFast()
>>> tok.train(["the quick brown fox", "the lazy dog sleeps"],
... vocab_size=64)
>>> tok.encode("the quick dog")
[0, 1, 5]Used by 1
Constructors
1dunder
__init__
→None__init__(vocab: dict[str, int] | None = None, special_tokens: SpecialTokens | None = None)Construct a C++-backed whitespace tokenizer.
Parameters
vocabdict[str, int] or None= NonePre-built word → id map.
None or empty constructs
an empty C++ backend; call train to populate.Special-token registry.
Properties
2Class methods
1Instance methods
4Return a shallow copy of the token → id map.
Return the surface string for token_id or None.
Persist as vocab.txt + unified tokenizer.json.
Collect unique whitespace-split words via the C++ trainer.
Parameters
corpusiterable of strDocuments to scan. Materialised into a list before
crossing into C++.
vocab_ sizeint= 30 000Maximum number of distinct words to retain.
Notes
Mutates _vocab / _id_to_token in place after the C++
side finishes; re-resolves special-token ids against the
new vocab.