Hugging Face tokenizer.json files in pure .NET, with the same token ids, offsets and decoded text as the Python and Rust tokenizers library, checked case by case.
using Starlings.Tokenizers; Tokenizer tokenizer = Tokenizer.FromFile("tokenizer.json"); TokenEncoding encoding = tokenizer.Encode("Hello, world!"); string text = tokenizer.Decode(encoding.Ids.AsSpan(), skipSpecialTokens: true);
- Faithful. Every supported tokenizer has a profile: a pinned
tokenizer.json(full commit SHA and SHA-256) with reference outputs from huggingface/tokenizers for multilingual text, emoji, combining marks, control characters, pairs, truncation and padding. CI fails on any difference. - Explicit. A
tokenizer.jsonthat uses a component this library does not implement fails at load withUnsupportedTokenizerComponentException, naming the JSON path. Nothing is approximated, and unknown fields are rejected rather than ignored. - Plain .NET. No native code, no package dependencies,
net10.0, Native AOT and trimming compatible. Instances are immutable and thread-safe. Large vocabularies load two to three times faster than in the Pythontokenizerslibrary, and with Native AOT every pinned file loads faster than in Python (measurements).
Part of Starling, .NET implementations of AI models with reproducible evidence of what works.
0.x. The public API can still change between minor versions. A profile's status is in its file under
profiles/; the Starling model profiles that use a profile pin the exact tokenizer version they were qualified with.
dotnet add package Starlings.Tokenizers
using Starlings.Tokenizers; Tokenizer tokenizer = Tokenizer.FromFile("tokenizer.json") // also FromStream, FromUtf8Json .WithTruncation(new TruncationOptions(MaxLength: 512)) .WithPadding(new PaddingOptions(PadId: 1, PadToken: "<pad>")); // no FixedLength: pad to the batch's longest TokenEncoding one = tokenizer.Encode("query: how much protein should a female eat"); TokenEncoding pair = tokenizer.Encode("What is the capital of France?", "Paris is the capital of France."); IReadOnlyList<TokenEncoding> batch = tokenizer.EncodeBatch(["first text", "second, longer text"]); int[] ids = [.. one.Ids]; // also Tokens, TypeIds, AttentionMask, SpecialTokensMask, SequenceIds TokenOffset span = one.Offsets[1]; // UTF-16 code units: slice the C# string with these TokenOffset scalars = one.ScalarOffsets[1]; // Unicode scalar values: the unit Python tokenizers reports string decoded = tokenizer.Decode(one.Ids.AsSpan(), skipSpecialTokens: true); int? eos = tokenizer.TokenToId("</s>");
WithTruncationandWithPaddingreturn new instances that share the loaded pipeline. Without them, the file's owntruncationandpaddingsections apply.Encode(text, addSpecialTokens: false)skips the post-processor's special tokens. Special tokens written in the input text are still matched as added tokens.- Input containing unpaired UTF-16 surrogates is rejected with
ArgumentException. tokenizer.Componentslists the pipeline stages the file uses, for examplemodel:BPE.
A model is supported when its tokenizer.json uses only supported components. A profile is the evidence: one pinned file and the cases it matches.
| Profile | Model | Algorithm | Evidence |
|---|---|---|---|
xlmr-unigram-e5 |
intfloat/multilingual-e5-small |
SentencePiece Unigram | 49/49 cases exact, with truncation and padded batch |
xlmr-unigram-paraphrase-multilingual |
sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2 |
SentencePiece Unigram, WhitespaceSplit | 49/49 cases exact, with and without special tokens, the file's truncation (128) and padding |
gliner2-base-v1-unigram |
fastino/gliner2-base-v1 |
SentencePiece Unigram (DeBERTa-v3) | per-word and 10 whole-text cases; offsets, pairs and decode untested |
qwen2-bpe-kev |
jaredpalmer/kev-0.8b (Qwen2/Qwen3 regex) |
byte-level BPE | 137/137 cases exact, 0 mismatches in 1.15 M randomized encodes |
qwen35-bpe-chat |
Qwen/Qwen3.5-0.8B |
byte-level BPE | 137/137 cases exact, 0 mismatches in 1.15 M randomized encodes |
gemma-bpe-embeddinggemma2 |
google/embeddinggemma-2 |
SentencePiece-style BPE, byte fallback | 49/49 cases exact, 0 mismatches in 1.7 M randomized encodes |
qwen3-bpe-embedding |
Qwen/Qwen3-Embedding-0.6B (appends <|endoftext|>) |
byte-level BPE | 137/137 cases exact, with and without special tokens, truncation and padded batches |
qwen3-bpe-chat |
Qwen/Qwen3-Reranker-0.6B (same file as Qwen/Qwen3-0.6B) |
byte-level BPE | 137/137 cases exact, with truncation and padded batches |
lfm3-bpe-chat |
LiquidAI/LFM3-1.7B |
byte-level BPE, Llama 3 regex | 137/137 cases exact, with truncation and padded batches |
clover-bpe-chat |
Diffuspace/Clover-35B-A3B-Preview (<|mask|> at id 151669) |
byte-level BPE | 137/137 cases exact, with truncation and padded batches |
phi4-bpe-chat |
microsoft/Phi-4-mini-instruct (rstrip role and tool tags) |
byte-level BPE, o200k regex | 137/137 cases exact, with truncation and padded batches; 1,500 randomized strings with the Phi-4 tags exact |
whisper-bpe |
openai/whisper-large-v3-turbo (1,609 added tokens: languages, tasks, timestamps) |
byte-level BPE, GPT-2 regex | 49/49 cases exact, with and without special tokens; decode with and without skipping them |
modernbert-bpe-gte-reranker |
Alibaba-NLP/gte-reranker-modernbert-base (ModernBERT, [CLS]/[SEP] templates) |
byte-level BPE, GPT-2 regex | 137/137 cases exact, with and without special tokens, truncation and padded batches |
All thirteen are experimental. BERT-family WordPiece files (for example sentence-transformers/all-MiniLM-L6-v2 and BAAI/bge-small-en-v1.5) load and pass component-level reference cases, but have no profile yet. Other files may load and work too. Without a profile, matching the reference is untested, not promised.
The full list of components and options, and what fails at load, is in docs/supported-components.md. Not offered: pre-tokenized input, word ids, overflowing windows (truncation stride), incremental (streaming) decode, and chat templates.
Need a tokenizer that is not here? Open a tokenizer request with the error Tokenizer.FromFile gives you.
Cold load in a fresh process: Tokenizer.FromFile with the default JIT and in an application published with Native AOT, against Tokenizer.from_file in Python tokenizers 0.23.3 (the Rust library's Python binding). Measured on 2026-11-14 on a RunPod CPU pod (AMD EPYC 9575F, every process on the same core), as medians of 30 fresh processes per build, run in rotation:
tokenizer.json |
Size | .NET (JIT) | .NET (Native AOT) | Python |
|---|---|---|---|---|
google/embeddinggemma-2 |
32 MB | 202 ms | 171 ms | 525 ms |
Qwen/Qwen3.5-0.8B |
20 MB | 116 ms | 83 ms | 331 ms |
intfloat/multilingual-e5-small |
17 MB | 127 ms | 87 ms | 325 ms |
microsoft/Phi-4-mini-instruct |
16 MB | 95 ms | 65 ms | 235 ms |
openai/whisper-large-v3-turbo |
2.7 MB | 47 ms | 10 ms | 33 ms |
sentence-transformers/all-MiniLM-L6-v2 |
0.5 MB | 37 ms | 4.4 ms | 8.8 ms |
With the JIT, files under about 3 MB load slower than in Python: the first call compiles the loader, which costs about 30 ms whatever the file size (the load itself takes about 3 ms for MiniLM). An application published with Native AOT has no such cost, and every one of the 16 pinned files loads in 0.25 to 0.52 of Python's time. All three gave the same ids on every file. All rows, first-encode and process times, and the method are in docs/performance.md.
| Page | Contents |
|---|---|
| Supported components | Every tokenizer.json component and option, byte fallback and regex details |
| Adding a tokenizer | From a new model's tokenizer.json to a released profile |
| Architecture | How the interpreter is built and where each stage lives |
| Performance | Cold-start load times against Python tokenizers, earlier load and encode records |
| Releasing | Versions, the tag-to-NuGet workflow, one-time setup |
| Changelog | What changed in each version |
llms.txt |
A compact guide for language models and coding assistants using this library |
See CONTRIBUTING.md. Coding agents should read AGENTS.md first.
Copyright (c) 2026 StarlingHq. Licensed under either of
at your option. Use it in open-source or commercial software, modify it, and ship it without releasing your own code. Apache-2.0 adds an explicit patent grant. Unless you state otherwise, any contribution you submit for inclusion is dual-licensed the same way, with no additional terms.
Some files are ported or adopted from huggingface/tokenizers, SentencePiece and spm_precompiled (Apache-2.0), dotnet/machinelearning (MIT), darts-clone (BSD 2-Clause), serde_json and unicode-normalization-alignments (MIT OR Apache-2.0), and Unicode data (Unicode License V3). All of these are permissive, and none of them adds conditions beyond keeping their notices. The notices are in THIRD-PARTY-NOTICES.md, which ships inside the package, so distributing the package as-is satisfies them. File-by-file origins are in PROVENANCE.md. Each model's tokenizer.json keeps its owner's terms and is never included in the package.