![]() |
VOOZH | about |
dotnet add package Microsoft.ML.Tokenizers --version 2.0.0
NuGet\Install-Package Microsoft.ML.Tokenizers -Version 2.0.0
<PackageReference Include="Microsoft.ML.Tokenizers" Version="2.0.0" />
<PackageVersion Include="Microsoft.ML.Tokenizers" Version="2.0.0" />Directory.Packages.props
<PackageReference Include="Microsoft.ML.Tokenizers" />Project file
paket add Microsoft.ML.Tokenizers --version 2.0.0
#r "nuget: Microsoft.ML.Tokenizers, 2.0.0"
#:package Microsoft.ML.Tokenizers@2.0.0
#addin nuget:?package=Microsoft.ML.Tokenizers&version=2.0.0Install as a Cake Addin
#tool nuget:?package=Microsoft.ML.Tokenizers&version=2.0.0Install as a Cake Tool
Microsoft.ML.Tokenizers provides an abstraction for tokenizers as well as implementations of common tokenization algorithms.
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
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.PreTokenizerMicrosoft.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 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on Microsoft.ML.Tokenizers:
| Package | Downloads |
|---|---|
|
Microsoft.Agents.AI
Provides Microsoft Agent Framework core functionality. |
|
|
Microsoft.ML.Tokenizers.Data.O200kBase
The Microsoft.ML.Tokenizers.Data.O200kBase includes the Tiktoken tokenizer data file o200k_base.tiktoken, which is utilized by models such as gpt-4o. |
|
|
Microsoft.ML.Tokenizers.Data.Cl100kBase
The Microsoft.ML.Tokenizers.Data.Cl100kBase class includes the Tiktoken tokenizer data file cl100k_base.tiktoken, which is utilized by models such as GPT-4. |
|
|
Microsoft.Agents.AI.OpenAI
Provides Microsoft Agent Framework support for OpenAI. |
|
|
Microsoft.Agents.AI.Workflows
Provides Microsoft Agent Framework support for workflows. |
Showing the top 20 popular GitHub repositories that depend on Microsoft.ML.Tokenizers:
| Repository | Stars |
|---|---|
|
microsoft/semantic-kernel
Integrate cutting-edge LLM technology quickly and easily into your apps
|
|
|
ravendb/ravendb
ACID Document Database
|
|
|
dotnet/skills
Repository for skills to assist AI coding agents with .NET and C#
|
|
|
dotnet/extensions
This repository contains a suite of libraries that provide facilities commonly needed when creating production-ready applications.
|
|
|
jayfunc/BetterLyrics
An elegant and deeply customizable lyrics visualizer & versatile music player, built with WinUI3/Win2D | 一款优雅且高度自定义的歌词可视化与全能音乐播放应用,基于 WinUI3/Win2D 构建
|
|
|
microsoft/WhatTheHack
A collection of challenge based hack-a-thons including student guide, coach guide, lecture presentations, sample/instructional code and templates. Please visit the What The Hack website at: https://aka.ms/wth
|
|
|
microsoft/ai-dev-gallery
An open-source project for Windows developers to learn how to add AI with local models and APIs to Windows apps.
|
|
|
dotnet/ResXResourceManager
Manage localization of all ResX-Based resources in one central place.
|
|
|
elevenyellow/handcrafted-persona-engine
An AI-powered interactive avatar engine using Live2D, LLM, ASR, TTS, and RVC. Ideal for VTubing, streaming, and virtual assistant applications.
|
|
|
managedcode/dotnet-skills
Installable .NET skill catalog and CLI for Codex, Claude Code, GitHub Copilot, and Gemini.
|
|
|
axzxs2001/Asp.NetCoreExperiment
原来所有项目都移动到**OleVersion**目录下进行保留。新的案例装以.net 5.0为主,一部分对以前案例进行升级,一部分将以前的工作经验总结出来,以供大家参考!
|
|
|
Azure-Samples/cosmosdb-chatgpt
Sample application that combines Azure Cosmos DB with Azure OpenAI ChatGPT service
|
|
|
dmitry-brazhenko/SharpToken
SharpToken is a C# library for tokenizing natural language text. It's based on the tiktoken Python library and designed to be fast and accurate.
|
|
|
saddam213/OnnxStack
C# Stable Diffusion using ONNX Runtime
|
|
|
microsoft/Document-Knowledge-Mining-Solution-Accelerator
Solution accelerator built on Azure OpenAI Service and Azure AI Document Intelligence to process and extract summaries, entities, and metadata from unstructured, multi-modal documents and enable searching and chatting over this data.
|
|
|
lindexi/lindexi_gd
博客用到的代码
|
|
|
alnkesq/AppViewLite
A Bluesky appview focused on low resource consumption
|
|
|
Azure/Vector-Search-AI-Assistant
Microsoft Official Build Modern AI Apps reference solutions and content. Demonstrate how to build Copilot applications that incorporate Hero Azure Services including Azure OpenAI Service, Azure Container Apps (or AKS) and Azure Cosmos DB for NoSQL with Vector Search.
|
|
|
marcominerva/SqlDatabaseVectorSearch
A Blazor Web App and Minimal API for performing RAG (Retrieval Augmented Generation) and vector search using the native VECTOR type in Azure SQL Database and Azure OpenAI.
|
|
|
tonybaloney/TransformersSharp
A little wrapper for hugging face transformers in C#
|
| Version | Downloads | Last Updated |
|---|---|---|
| 3.0.0-preview.26160.2 | 17,323 | 3/12/2026 |
| 2.0.0 | 2,418,815 | 11/11/2025 |
| 2.0.0-preview.25527.5 | 29,491 | 10/29/2025 |
| 2.0.0-preview.25503.2 | 13,762 | 10/3/2025 |
| 2.0.0-preview.25373.1 | 29,596 | 7/28/2025 |
| 2.0.0-preview.1.25127.4 | 146,572 | 2/28/2025 |
| 2.0.0-preview.1.25125.4 | 3,292 | 2/25/2025 |
| 1.0.3 | 127,399 | 10/28/2025 |
| 1.0.2 | 1,458,595 | 2/26/2025 |
| 1.0.1 | 536,372 | 1/15/2025 |
| 1.0.0 | 1,039,896 | 11/14/2024 |
| 0.22.0 | 81,173 | 11/13/2024 |
| 0.22.0-preview.24526.1 | 3,663 | 10/27/2024 |
| 0.22.0-preview.24522.7 | 4,543 | 10/23/2024 |
| 0.22.0-preview.24378.1 | 387,335 | 7/29/2024 |
| 0.22.0-preview.24271.1 | 228,182 | 5/21/2024 |
| 0.22.0-preview.24179.1 | 231,826 | 4/2/2024 |
| 0.22.0-preview.24162.2 | 23,777 | 3/13/2024 |
| 0.21.1 | 254,537 | 1/18/2024 |
| 0.21.0 | 91,506 | 11/27/2023 |