BertTokenizer class
A BERT WordPiece tokenizer backed by a vocab.txt file.
Converts arbitrary text into BERT token IDs suitable for feeding into the BGE Small En v1.5 ONNX model via OnnxSession.run.
Pipeline
- Normalise — lower-case and strip combining accent characters.
- Word segmentation — delegate to the Tokenizer supplied at
construction time. RegExpTokenizer is used by default;
IcuTokenizerfrompackage:betto_icucan be substituted as a drop-in replacement for superior Unicode coverage. - WordPiece — split each word into sub-word pieces and look up IDs in
the vocabulary loaded from
vocab.txt. Unknown pieces map to[UNK]. - Assemble — prepend
[CLS](101), append[SEP](102), and pad tomaxLengthwith[PAD](0).
Token ID space
BERT token IDs are entirely distinct from the stemmed token strings produced by the lexical search pipeline (FtsManager / BM25). They must not be interchanged.
IcuTokenizer
import 'package:betto_icu/betto_icu.dart';
final tokenizer = await BertTokenizer.load(vocabPath,
tokenizer: IcuTokenizer());
- Implemented types
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
decode(
List< int> ids) → List<String> - Decodes a list of token IDs back to vocabulary strings.
-
encode(
String text) → TokenizerOutput -
Encodes
textinto a TokenizerOutput ready for ONNX inference.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
load(
String vocabPath, {int maxLength = 512, Tokenizer? tokenizer}) → Future< BertTokenizer> -
Loads the vocabulary from
vocabPathand returns a BertTokenizer.
Constants
- clsId → const int
-
[CLS]token ID — always the first token in BERT input sequences. - padId → const int
-
[PAD]token ID — used to fill sequences shorter thanmaxLength. - sepId → const int
-
[SEP]token ID — marks the end of a segment in BERT input sequences. - unkId → const int
-
[UNK]token ID — substituted for vocabulary entries not found in WordPiece decomposition.