ZeroTokenizer.Core
1.1.0
dotnet add package ZeroTokenizer.Core --version 1.1.0
NuGet\Install-Package ZeroTokenizer.Core -Version 1.1.0
<PackageReference Include="ZeroTokenizer.Core" Version="1.1.0" />
<PackageVersion Include="ZeroTokenizer.Core" Version="1.1.0" />
<PackageReference Include="ZeroTokenizer.Core" />
paket add ZeroTokenizer.Core --version 1.1.0
#r "nuget: ZeroTokenizer.Core, 1.1.0"
#:package ZeroTokenizer.Core@1.1.0
#addin nuget:?package=ZeroTokenizer.Core&version=1.1.0
#tool nuget:?package=ZeroTokenizer.Core&version=1.1.0
🔤 ZeroTokenizer: Sovereign Pure C# BPE & Tiktoken Engine
ZeroTokenizer is an ultra-fast, zero-allocation Byte-Pair Encoding (BPE), WordPiece, and Tiktoken tokenizer engine engineered in 100% pure C# for .NET. Operating within Tier 3 (Perception & AI) of the ZeroPlatform ecosystem, it provides native tokenization for Small Language Models (ZeroLlm) and autonomous agents (ZeroAgent).
⚡ Key Capabilities
- Zero-Allocation Tokenizer Pipeline:
- Direct span-based encoding:
int Encode(ReadOnlySpan<char> text, Span<int> destinationTokenIds). - Fast token counter:
int CountTokens(ReadOnlySpan<char> text)without allocating integer arrays or string chunks. - Streaming decoding:
int Decode(ReadOnlySpan<int> tokenIds, Span<char> destinationText).
- Direct span-based encoding:
- Vietnamese ERP Specialized BPE (
VietnameseErpTokenizer):- Domain-specialized vocabulary with 16,000 subword merges optimized for industrial ERP terminology, warehouse codes, equipment tags, and accented Vietnamese syllables.
- High compression ratio ($< 1.8$ characters/token on Vietnamese ERP text vs $3.5+$ characters/token on generic tokenizers).
- Canonical Special Tokens (
SpecialTokens):- Pre-mapped control tokens for multi-turn dialogues and role framing:
<bos>,<eos>,<pad>,<unk>,<system>,</system>,<user>,</user>,<assistant>,</assistant>,<thought>,</thought>,<tool_call>,</tool_call>,<tool_result>,</tool_result>,<response>,</response>.
- Pre-mapped control tokens for multi-turn dialogues and role framing:
- Serialization & Model Portability:
- Direct binary and plain-text vocabulary persistence (
Save/Load) for fast startup and embedding in deployment artifacts.
- Direct binary and plain-text vocabulary persistence (
- Tiktoken Engine:
- Pre-configured regex patterns for
cl100k_base(OpenAI GPT-4 / ChatGPT) ando200k_base(GPT-4o).
- Pre-configured regex patterns for
- Context Token Budgeter (
TokenBudgeter):- Greedy Knapsack packing algorithm for LLM prompts, ensuring conversation histories, system instructions, and RAG knowledge fragments never overflow the context window.
- Zero External Dependencies & Multi-Targeting:
- Compatible with
.NET 8.0+,.NET Framework 4.6.2+, and.NET Standard 2.0.
- Compatible with
🚀 Quick Start
1. Count Tokens Without Memory Allocations
using ZeroTokenizer.Core.Tiktoken;
var tokenizer = TiktokenTokenizer.CreateCl100kBase();
ReadOnlySpan<char> prompt = "System: Analyze factory vibration telemetry at node 4.";
int tokenCount = tokenizer.CountTokens(prompt);
Console.WriteLine($"Token count: {tokenCount}");
2. Specialized Vietnamese ERP BPE Tokenizer
using ZeroTokenizer.Core.Vietnamese;
var tokenizer = VietnameseErpTokenizer.CreateDefault();
// Encode Vietnamese domain text
int[] tokens = tokenizer.Encode("Kiểm tra tồn kho mặt hàng thép cuộn 10mm tại Kho Tổng");
string decoded = tokenizer.Decode(tokens);
Console.WriteLine($"Vocabulary Size: {tokenizer.VocabularySize}");
Console.WriteLine($"Encoded Tokens Count: {tokens.Length}");
3. Save and Load Custom BPE Vocabularies
using ZeroTokenizer.Core.Bpe;
var bpe = new BpeTokenizer(vocabDict, mergesList);
// Save vocabulary to file
bpe.Save("models/vietnamese_erp.bpe");
// Load trained tokenizer
var loaded = BpeTokenizer.Load("models/vietnamese_erp.bpe");
📄 License
Architected and developed by Phong Võ (kzxl) for the ZeroUniverse / ZeroPlatform ecosystem. Released under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.2
- System.Buffers (>= 4.5.1)
- System.Memory (>= 4.5.5)
- System.Runtime.CompilerServices.Unsafe (>= 6.0.0)
- ZeroPrimitives.Core (>= 1.7.0)
-
.NETStandard 2.0
- System.Buffers (>= 4.5.1)
- System.Memory (>= 4.5.5)
- System.Runtime.CompilerServices.Unsafe (>= 6.0.0)
- ZeroPrimitives.Core (>= 1.7.0)
-
net8.0
- ZeroPrimitives.Core (>= 1.7.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on ZeroTokenizer.Core:
| Package | Downloads |
|---|---|
|
ZeroPrompt.Core
Pure C# Prompt Engineering & Grammar-Constrained Token Decoding Engine (Zero-Allocation Templates, JSON Schema Finite Automata, Logit Masking, and Dynamic Few-Shot Exemplars) for .NET. |
|
|
ZeroAgent.Core
Pure C# enterprise-grade cognitive AI Agent runtime (ReAct loop, tool registry, episodic memory via ZeroVector, and multi-agent swarm) for .NET. |
|
|
ZeroLlm.Core
Pure C# in-process Small Language Model (SLM) runtime, GGUF v2/v3 binary parser, Paged KV-Cache allocator, Transformer decoder (RMSNorm, RoPE, SwiGLU, GQA), and token sampling engine for .NET. |
GitHub repositories
This package is not used by any popular GitHub repositories.