Tokenizers for MoonBit: byte-level BPE and SentencePiece.
let tokenizer = @moontoken.Tokenizer::cl100k(ranks~)
let ids = tokenizer.encode("the world and the thing")text the world and the thing
tokens 8
ids 258 262 261 32 258 32 256 260
bytes 23
decoded the world and the thing
count 8
vocabulary 263| Package | What it is |
|---|---|
| moontoken | The tokenizer: encode, encode_ordinary, decode, count, and the ways to build one |
| split | The pre-tokenizers of the published encodings, written as scanners |
| vocab | A rank table, from the base64 file OpenAI publishes or from pairs |
| bpe | Byte-pair merging: the byte-level model, and the word-level one a tokenizer.json names |
| piece | The SentencePiece model file: both trainer types, and the trie it compiles |
| normalizer | The rule table a model file carries, and the operations a tokenizer.json lists |
| special | The tokens a model reserves, and what may happen to them |
| refused | The one error shape the whole library raises |
tokenizer.encode(text, special=@special.Refuse) // refuse it
tokenizer.encode(text, special=@special.Allow) // take it as the token
tokenizer.encode(text, special=@special.Ignore) // encode it as text
tokenizer.encode(text, special=@special.Only(["<|endoftext|>"]))| What | Rows | Passing |
|---|---|---|
| cl100k_base and o200k_base, over a 600-entry slice of each published table | 84 | 84 |
| The reserved tokens, under each policy | 6 | 6 |
| SentencePiece unigram, BPE, and unigram without the dummy prefix | 258 | 258 |
| Total | 348 | 348 |
| Reference | Encoders | Comparisons | Agreeing |
|---|---|---|---|
| tiktoken 0.14.0 | 4 | 1936 | 1936 |
| sentencepiece 0.2.3 | 3 | 1452 | 1452 |
| tokenizers 0.23.1 | 2 | 968 | 968 |
| Total | 9 | 4356 | 4356 |
moon build --target native
pip install tiktoken==0.14.0 sentencepiece==0.2.3 tokenizers==0.23.1
python scripts/diff_reference.py --preparemoon add moonbitstack/moontokenInstall
Download zipTokenizers for MoonBit: byte-level BPE and SentencePiece.