core/data/wordpiece_tokenizer library
BERT WordPiece tokenizer (uncased BERT / MiniLM / all-MiniLM-L6-v2
style). Faithful enough to reproduce HuggingFace BertTokenizer
output on the vast majority of English text.
Pipeline (matches BertTokenizer with do_lower_case=true):
- Clean text: strip control chars, collapse whitespace.
- Lowercase; strip common accents (NFD -> drop Mn).
- Split punctuation into their own tokens.
- Whitespace-split into words.
- For each word: greedy-longest WordPiece match against the
vocab, with
##-prefixed continuation pieces; unknown ->[UNK].
Not implemented (kept simple; falls back to sensible defaults):
- Chinese-character forced splitting.
never_splitlist.- Special-token protection (they are recovered by the vocab lookup itself).
Classes
Functions
-
debugPreview(
List< int> ids, int max) → String -
Utility for callers:
List<int> -> jsonEncode(...)doesn't hit arg limits, but a helper avoids duplicating this everywhere in bin/ demos.