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

  1. Normalise — lower-case and strip combining accent characters.
  2. Word segmentation — delegate to the Tokenizer supplied at construction time. RegExpTokenizer is used by default; IcuTokenizer from package:betto_icu can be substituted as a drop-in replacement for superior Unicode coverage.
  3. WordPiece — split each word into sub-word pieces and look up IDs in the vocabulary loaded from vocab.txt. Unknown pieces map to [UNK].
  4. Assemble — prepend [CLS] (101), append [SEP] (102), and pad to maxLength with [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 text into 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 vocabPath and 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 than maxLength.
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.