Skip to main content
net6.0net7.0net8.0

.NET wrapper of HuggingFace Tokenizers library

Published
Jun 16, 2024
2y ago
Total Downloads
105.1K
105,091

Deprecated Package Version

Reason: Legacy, CriticalBugs

These packages are compatible with the runtime 0.5.0 or below. Please use 0.9.2 or above to use the runtime 0.6.1 or above. For the reason, check https://github.com/sappho192/Tokenizers.DotNet/issues/4

Install

dotnet add package Tokenizers.DotNet --version 0.9.1
ProductVersions
.NET
net6.0net7.0net8.0

README

Tokenizers.DotNet

.NET wrapper of HuggingFace Tokenizers library

Nuget Package list

Package main Description
Tokenizers.DotNet Nuget Tokenizers.DotNet Core library
Tokenizers.DotNet.runtime.win Nuget Tokenizers.DotNet.runtime.win Native bindings for windows x64

Requirements

  • .NET 6 or above

Supported functionalities

  • Download tokenizer files from Hugginface Hub
  • Load tokenizer file(.json) from local
  • Decode embeddings to string

How to use

(1) Install the packages

  1. From the NuGet, install Tokenizers.DotNet package
  2. And then, install Tokenizers.DotNet.runtime.win package too

(2) Write the code

Check following example code:

using Tokenizers.DotNet;

// Download skt/kogpt2-base-v2/tokenizer.json from the hub
var hubName = "skt/kogpt2-base-v2";
var filePath = "tokenizer.json";
var fileFullPath = await HuggingFace.GetFileFromHub(hubName, filePath, "deps");
Console.WriteLine($"Downloaded {fileFullPath}");

// Create a tokenizer instance
var tokenizer = new Tokenizer(vocabPath: fileFullPath);
var tokens = new uint[] { 9330, 387, 12857, 9376, 18649, 9098, 7656, 6969, 8084, 1 };
var decoded = tokenizer.Decode(tokens);
Console.WriteLine($"Decoded: {decoded}");

Console.WriteLine($"Version of Tokenizers.DotNet.runtime.win: {tokenizer.GetVersion()}");

How to build

  1. Prepare following stuff:
    1. Rust build system (cargo)
    2. .NET build system (dotnet 6.0)
    3. PowerShell (Recommend 7.4.2 or above)
  2. Run build_all_clean.ps1
    1. To build Tokenizers.DotNet.runtime.win only, run build_rust.ps1
    2. To build Tokenizers.DotNet only, run build_dotnet.ps1

Each build artifacts will be in nuget directory.

Changes from Previous Version

v0.9.0v0.9.1
Added Frameworks
net6.0net7.0net8.0

Adoption Assessment

Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.

NuGet marks this package as deprecated. Review the publisher's migration guidance before adopting it.Compatibility metadata lists 3 target frameworks; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.