Darkspyre.ML.Tokenizers
2.0.1.1
Prefix Reserved
dotnet add package Darkspyre.ML.Tokenizers --version 2.0.1.1
NuGet\Install-Package Darkspyre.ML.Tokenizers -Version 2.0.1.1
<PackageReference Include="Darkspyre.ML.Tokenizers" Version="2.0.1.1" />
<PackageVersion Include="Darkspyre.ML.Tokenizers" Version="2.0.1.1" />
<PackageReference Include="Darkspyre.ML.Tokenizers" />
paket add Darkspyre.ML.Tokenizers --version 2.0.1.1
#r "nuget: Darkspyre.ML.Tokenizers, 2.0.1.1"
#:package Darkspyre.ML.Tokenizers@2.0.1.1
#addin nuget:?package=Darkspyre.ML.Tokenizers&version=2.0.1.1
#tool nuget:?package=Darkspyre.ML.Tokenizers&version=2.0.1.1
Darkspyre fork
Darkspyre.ML.Tokenizers is a source-compatible fork of Microsoft's tokenizer library. Version
2.0.1.1 is based on Microsoft.ML.Tokenizers 2.0.1 and corrects SentencePiece models that disable
BOS or EOS with token id -1. Assemblies, namespaces, and public APIs retain their upstream names.
About
Microsoft.ML.Tokenizers provides an abstraction for tokenizers as well as implementations of common tokenization algorithms.
Key Features
- Extensible tokenizer architecture that allows for specialization of Normalizer, PreTokenizer, Model/Encoder, Decoder
- BPE - Byte pair encoding model
- English Roberta model
- Tiktoken model
- Llama model
- Phi2 model
How to Use
using Microsoft.ML.Tokenizers;
using System.IO;
using System.Net.Http;
//
// Using Tiktoken Tokenizer
//
// Initialize the tokenizer for the `gpt-4o` model. This instance should be cached for all subsequent use.
Tokenizer tokenizer = TiktokenTokenizer.CreateForModel("gpt-4o");
string source = "Text tokenization is the process of splitting a string into a list of tokens.";
Console.WriteLine($"Tokens: {tokenizer.CountTokens(source)}");
// prints: Tokens: 16
var trimIndex = tokenizer.GetIndexByTokenCountFromEnd(source, 5, out string processedText, out _);
Console.WriteLine($"5 tokens from end: {processedText.Substring(trimIndex)}");
// prints: 5 tokens from end: a list of tokens.
trimIndex = tokenizer.GetIndexByTokenCount(source, 5, out processedText, out _);
Console.WriteLine($"5 tokens from start: {processedText.Substring(0, trimIndex)}");
// prints: 5 tokens from start: Text tokenization is the
IReadOnlyList<int> ids = tokenizer.EncodeToIds(source);
Console.WriteLine(string.Join(", ", ids));
// prints: 1199, 4037, 2065, 374, 279, 1920, 315, 45473, 264, 925, 1139, 264, 1160, 315, 11460, 13
//
// Using Llama Tokenizer
//
// Open a stream to the remote Llama tokenizer model data file.
using HttpClient httpClient = new();
const string modelUrl = @"https://huggingface.co/hf-internal-testing/llama-tokenizer/resolve/main/tokenizer.model";
using Stream remoteStream = await httpClient.GetStreamAsync(modelUrl);
// Create the Llama tokenizer using the remote stream. This should be cached for all subsequent use.
Tokenizer llamaTokenizer = LlamaTokenizer.Create(remoteStream);
string input = "Hello, world!";
ids = llamaTokenizer.EncodeToIds(input);
Console.WriteLine(string.Join(", ", ids));
// prints: 1, 15043, 29892, 3186, 29991
Console.WriteLine($"Tokens: {llamaTokenizer.CountTokens(input)}");
// prints: Tokens: 5
Main Types
The main types provided by this library are:
Microsoft.ML.Tokenizers.TokenizerMicrosoft.ML.Tokenizers.BpeTokenizerMicrosoft.ML.Tokenizers.EnglishRobertaTokenizerMicrosoft.ML.Tokenizers.TiktokenTokenizerMicrosoft.ML.Tokenizers.NormalizerMicrosoft.ML.Tokenizers.PreTokenizer
Additional Documentation
Related Packages
Feedback & Contributing
Microsoft.ML.Tokenizers is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.
| 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 was computed. 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. |
-
.NETStandard 2.0
- Google.Protobuf (>= 3.30.2)
- Microsoft.Bcl.AsyncInterfaces (>= 9.0.4)
- Microsoft.Bcl.HashCode (>= 6.0.0)
- Microsoft.Bcl.Memory (>= 9.0.14)
- System.Buffers (>= 4.6.1)
- System.IO.Pipelines (>= 9.0.4)
- System.Memory (>= 4.6.3)
- System.Runtime.CompilerServices.Unsafe (>= 6.1.2)
- System.Text.Encodings.Web (>= 9.0.4)
- System.Text.Json (>= 9.0.4)
-
net8.0
- Google.Protobuf (>= 3.30.2)
NuGet packages (11)
Showing the top 5 NuGet packages that depend on Darkspyre.ML.Tokenizers:
| Package | Downloads |
|---|---|
|
Darkspyre.Inference.Tensor.Registry
Registration, validation and ordered discovery of the Darkspyre Tensor engine implementations. |
|
|
Darkspyre.Inference.Connect
Image, speech and audio inference connectors for Darkspyre applications. |
|
|
Darkspyre.Inference.Tensor.Decision.Laya
Laya in-process typed-decision inference through ONNX Runtime. |
|
|
Darkspyre.Inference.Tensor.Image.Supra
Supra2-IMG in-process image generation through TensorSharp. |
|
|
Darkspyre.Inference.Connect.Common
Universal conversation and embedding contracts, shared provider infrastructure and automatic Connect discovery. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.0.1.1 | 346 | 10/18/2026 |
Based on Microsoft.ML.Tokenizers 2.0.1; accepts SentencePiece models whose BOS or EOS token is disabled with id -1.