kitoken
Library Listed
Fast tokenizer for language models, supporting BPE, Unigram and WordPiece tokenization
- Downloads
- 2,949
- Dependents
- 3
- Stars
- 62
- Forks
- 2
- Contributors
- 1
- Commits
- 67
- Latest release
- 0.11.1 ·
About
Tokenizer for language models.
Tokenize text for Llama, Gemini, GPT-5, DeepSeek, Mistral and many others; in the web, on the client and any platform.
use kitoken::Kitoken;
let encoder = Kitoken::from_web("hf:Qwen/Qwen3.5-9B")?;
let tokens = encoder.encode("Your future belongs to me.", true)?;
let string = String::from_utf8(encoder.decode(&tokens, true)?)?;
assert!(string == "Your future belongs to me.");
Overview
Kitoken is a fast and versatile tokenizer for language models compatible with SentencePiece, HuggingFace Tokenizers, OpenAI Tiktoken and Mistral Tekken, supporting BPE, Unigram and WordPiece tokenization.
- Fast and efficient tokenization
Faster than most other tokenizers in both common and uncommon scenarios; see the benchmarks for comparisons with different datasets. - Runs in all environments
Native in Rust and with bindings for Web, Node and Python; see kitoken.dev for a web demo. - Supports input and output processing
Including unicode-aware normalization, pre-tokenization and post-processing options. - Compact data encoding
Definitions are stored in an efficient binary format and without merge list.
See also kitoken-cli for Kitoken in the command line.
Read the full README
Compatibility
Kitoken can load and convert most existing tokenizer formats. Every supported format is tested against the original implementation across a wide variety of inputs to ensure correctness and compatibility.
[!NOTE] Most models on Hugging Face are supported. Just take the
tokenizer.jsonorspiece.modeland load it into Kitoken.
Kitoken aims to be output-identical with existing implementations for all models. See the notes below for differences in specific cases.
SentencePiece
let encoder = Kitoken::from_file("models/gemma.model")?;
Kitoken can convert and initialize with SentencePiece models in BPE and Unigram format.
BPEmodels are converted toBytePairdefinitions in character mode. A merge list is generated and sorted using the token scores, which is then used to sort the vocabulary by merge priority. The scores and the merge list are then discarded.Unigrammodels are converted toUnigramdefinitions retaining the token scores.
If the model does not contain a trainer definition, Unigram is assumed as the default encoding mode. Normalization options and the unicode normalization scheme are taken from the contained normalizer definition and converted to the respective Kitoken configurations.
Notes
- SentencePiece uses different
nfkcnormalization rules in thenmt_nfkcandnmt_nfkc_cfschemes than during regularnfkcnormalization, preventing the normalization of~to~. Kitoken uses the regularnfkcnormalization rules fornmt_nfkcandnmt_nfkc_cf. - SentencePiece's implementation of Unigram merges pieces with the same merge priority in a different order depending on preceding non-encodable pieces. Kitoken always merges pieces with the same merge priority in the same order, matching the behavior of Tokenizers.
Tokenizers
let encoder = Kitoken::from_file("models/llama4.json")?;
Kitoken can convert and initialize with HuggingFace Tokenizers definitions for BPE, Unigram and WordPiece models.
BPEmodels are converted toBytePairdefinitions. The included merge list is used to sort the vocabulary by merge priority and is then discarded.Unigrammodels are converted toUnigramdefinitions retaining the token scores.WordPiecemodels are converted toWordPiecedefinitions.
Normalization, pre-tokenization, post-processing and decoding options contained in the definition are converted to the respective Kitoken configurations.
Some normalization, post-processing and decoding options used by Tokenizers are used for converting alternative token-byte representations during encoding and decoding. Kitoken always stores and operates on tokens as byte sequences, and will use these options to pre-normalize the vocabulary during conversion.
Notes
- Tokenizers skips over non-encodable pieces and attempts to merge the surrounding ones when using an incomplete vocabulary without an
unktoken. Kitoken always considers non-encodable pieces as un-mergeable and encodes the surrounding pieces individually. This can affect models that exploit the behavior of Tokenizers with a deliberately restricted vocabulary. - Tokenizers normalizes inputs character-by-character, while Kitoken normalizes inputs as one. This can result in differences during case-folding in some cases. For example, greek letter
Σhas two lowercase forms,σfor within-word andςfor end-of-word use. Tokenizers will always lowercaseΣtoσ, while Kitoken will lowercase it to either depending on the context. - Tokenizers doesn't merge Metaspace replacement characters in inputs with spaces during encoding. Kitoken merges both as the same, matching the behavior of SentencePiece.
Tiktoken
let encoder = Kitoken::from_file("models/o200k_base.tiktoken")?;
Tiktoken is a BPE tokenizer used by OpenAI for GPT-3 and newer models and uses BytePair tokenization in byte mode.
Tiktoken definitions contain a sorted vocabulary of base64 encoded bytes and corresponding token ids without any additional metadata. Special tokens and the split regex are expected to be provided separately, but will be inferred from the data for common models including GPT-3, GPT-4, GPT-4o, GPT-5 and others including Kimi and Llama 4. For other models, or depending on the data and requirements, these values can be adjusted manually.
Tekken
let encoder = Kitoken::from_file("models/mistral.json")?;
Tekken is a BPE tokenizer based on Tiktoken, used by Mistral for NeMo and newer models and uses BytePair tokenization in byte mode.
Tekken definitions contain a sorted vocabulary of base64 encoded bytes and corresponding token ids, as well as metadata including the split regex and special tokens.
Performance
Kitoken uses merge-list-free variations of the BPE algorithm and a reversed variation of the Unigram algorithm. The basis for the merge-list-free BPE algorithm was inspired by Tiktoken, which has similarly good performance characteristics with common tokenization inputs. However, Kitoken can be much faster with inputs that fail to split during pre-tokenization by falling back to a priority-queue-based implementation when optimal.
The core tokenization functions are optimized for multiple CPU architectures and make use of SIMD instructions where available. Kitoken also avoids memory allocations and copying of data to great extent, and most operations are performed in-place and buffers are reused where possible.
Benchmarks
Benchmarks were performed on a MacBook Pro M4 Max using each libraries Python bindings with tokenizer-bench.
Gemma 3
Encoding throughput
Llama 4
Encoding throughput
Datasets
Pride and Prejudice: A text document containing Pride and Prejudice by Jane Austen. This data is a good representation for common English-language inputs containing a mix of short and long paragraphs.
UTF-8 Sequence: A text document containing a single-line UTF-8 sequence. This data is a good representation of inputs that stress pre-tokenization.
Wagahai: A text document containing Wagahai wa Neko de Aru by Natsume Sōseki. This data is a good representation for Japanese-language inputs containing many long paragraphs.
Compatibility
- Runs on
- GPU support unknown
What shows it
- no dependency or feature matches a backend row
- Native code
- None found
- No native code found
- Python bindings
- No Python binding crate found
- License
- BSD-2-Clause
Compare with similar projects
Order: strongest tier first, then most downloads, then name, with unmeasured values last. A library counts downloads over 30 days. An app counts binary downloads per release. An app with none counts its crate downloads over 30 days. ML Rust runs this catalogue, so its closest project always gets a row.
| Project | Downloads | Dependents | Stars | Latest release | Runs on (GPU) | Native code | License |
|---|---|---|---|---|---|---|---|
|
Fast tokenizer for language models, supporting BPE, Unigram and WordPiece tokenization |
2,949 downloads over 30 days | 3 | 62 | 0.11.1 | GPU support unknown | No native code found | BSD-2-Clause |
|
whatlang-rs Featured
Fast and lightweight language identification library for Rust. |
882,019 downloads over 30 days | 74 | 1,087 | 0.18.0 | GPU support unknown | No native code found | MIT |
|
whichlang Listed
A blazingly fast and lightweight language detection library for Rust. |
52,880 downloads over 30 days | 11 | 464 | 0.1.1 | GPU support unknown | No native code found | MIT |
|
splintr Listed
Tokenizer for Rust and Python: pure Rust by default, with 18 bundled vocabularies and four backends covering BPE, SentencePiece and WordPiece. Its output matches Hugging Face tokenizers id for id on 14 model families, including GPT-2, Qwen, Whisper, T5 and BERT. Python bindings |
8,204 downloads over 30 days | 7 | 63 | 0.22.2 | GPU support unknown | Binds native code: pcre2-sys (feature pcre2) | MIT |
|
shimmytok Listed
Pure Rust tokenizer for GGUF models with llama.cpp compatibility (SentencePiece + BPE + WPM + UGM + RWKV) |
914 downloads over 30 days | 2 | 26 | 0.8.5 | GPU support unknown | No native code found | Apache-2.0 OR MIT |
|
tokie Listed
Blazingly fast tokenizer - 50x faster tokenization, 10x smaller model files, 100% accurate drop-in replacement for HuggingFace |
711 downloads over 30 days | 3 | 56 | 0.1.4 | GPU support unknown | No native code found | Apache-2.0 OR MIT |
Why ListedNo archive, New or Featured rule places it, so it is Listed.
What it lacks for Featured
- It has 3 active dependents and 3 new dependents in 365 days. Featured needs 11 active dependents or 9 new dependents in 365 days. The repository route reads 62 stars, 2 forks and 1 contributor. It needs 4,539 stars, 434 forks and 79 contributors together.
What else the check found
- The last activity is on 26 Oct 2026, 14 days ago. The rules expect an update within 365 days. Dormancy rule
Exact rules: Listed, Featured library. The check on applied thresholds version 9.
Every rule outcome, as the check records it
expected-interval: version 0.11.1 base 300, capped at 4 releases = 200, raised to the 365-day floor: E = 365 daysdormancy: last activity 2026-10-26, 14 days ago, E = 365: activefeatured: not featured: active_users 3 < 11 and new_adopters 3 < 9 and repository route stars 62 (needs 4539), forks 2 (needs 434), contributors 1 (needs 79)listed: listed: no archive, new or featured rule applies
Measurements and sources
Each signal row shows the raw value, its source and the fetch date. The Sources list gathers every distinct source on this page. Movement needs more history.
Sources6 sources
- Description: the crates.io description
- crates.io database dump, fetched
- RustSec advisory database, fetched
- GitHub repository, fetched
- crates.io package, fetched
- GitHub contributors, fetched
Adoption3 active dependents, 3 new dependents in 365 days1 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Active dependents | 3 | crates.io database dump | Yes | |
| New dependents (365 days) | 3 | crates.io database dump | Yes | |
| Peak active dependents | 3 | crates.io database dump | Yes | |
| Active dependents as a share of the peak | 1 | crates.io database dump | Yes | |
| Binary downloads per release | Not measured | Yes |
MaintenanceLatest human commit: 14 days ago3 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Latest human commit | 2026-10-26 | GitHub repository | Yes | |
| Latest release | 2026-10-26 | crates.io database dump | Yes | |
| First release | 2024-12-16 | crates.io database dump | Yes | |
| Latest version | 0.11.1 | crates.io database dump | Yes | |
| Days the oldest outside issue waits for a reply | 0 | GitHub repository | Yes | |
| Maintainer replies over 365 days | 2 | GitHub repository | Yes | |
| Repository archived | false | GitHub repository | Yes | |
| Repository gone | false | GitHub repository | Yes | |
| Release commit or manifest in the repo | true | crates.io package | Yes | |
| Published docs | true | crates.io database dump | Yes | |
| Latest release fails cargo check | Not measured | Yes | ||
| Build check date | Not measured | Yes | ||
| Build check toolchain | Not measured | Yes |
SecurityUnpatched vulnerabilities: none
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Unpatched vulnerabilities past the grace window | none | RustSec advisory database | Yes | |
| RustSec unmaintained advisory | none | RustSec advisory database | Yes | |
| Deprecation notice | none | crates.io database dump | Yes | |
| Deprecated requirement | none | crates.io database dump | Yes |
Distribution4 releases, 2,949 downloads over 30 days5 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Releases | 4 | crates.io database dump | Yes | |
| Downloads over 30 days | 2949 | crates.io database dump | Yes | |
| Binary downloads over the last 3 releases | Not measured | Yes | ||
| Homebrew installs on request over 365 days | Not measured | Yes | ||
| Repology repository families | Not measured | Yes | ||
| Docker pull growth over 90 days | Not measured | Yes | ||
| Docker pulls at the growth baseline | Not measured | Yes | ||
| Every version a prerelease | false | crates.io database dump | Yes | |
| Every version 0.0.x | false | crates.io database dump | Yes | |
| Every version yanked | false | crates.io database dump | Yes | |
| Crate deleted from crates.io | false | crates.io database dump | Yes |
Repository62 stars, 2 forks, 1 contributors, 67 commits. Stars alone never qualify a project.
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| GitHub stars | 62 | GitHub repository | Yes — one part of the repository route | |
| GitHub forks | 2 | GitHub repository | Yes — one part of the repository route | |
| Contributors with a GitHub account | 1 | GitHub contributors | Yes — one part of the repository route | |
| Commits on the default branch | 67 | GitHub repository | No | |
| Repository's main crate left out of the entry | none | crates.io database dump | Yes |
Facts that never count
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| License | BSD-2-Clause | crates.io database dump | No | |
| Runs on, from listed crates and their direct dependencies | GPU support unknown | crates.io database dump | No | |
| What shows each backend | no dependency or feature matches a backend row | crates.io database dump | No | |
| Native code, from listed crates and their dependencies | No native code found | crates.io database dump | No | |
| Python bindings, from direct dependencies of listed crates | No Python binding crate found | crates.io database dump | No | |
| Crates that depend on a listed crate directly | 3 | crates.io database dump | No |
Corrections and review history
No correction applies to this entry.
Judgments
A judgment enters only through an approved issue and a merged pull request.
No judgment applies to this entry.