Skip to main content
Any Framework

.NET wrapper of HuggingFace Tokenizers library

Published
Jun 11, 2024
2y ago
Total Downloads
105.7K
105,720

Deprecated Package Version

Reason: Legacy

There's breaking changes to the library. Check following issue: https://github.com/sappho192/Tokenizers.DotNet/issues/2

Install

dotnet add package Tokenizers.DotNet --version 0.1.0

No framework information available.

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;

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

// Write the path of tokenizer.json to tokenizer.path.txt
var tokenizerPath = "tokenizer.path.txt";
await File.WriteAllTextAsync(tokenizerPath, fileFullPath);
Console.WriteLine($"Wrote {fileFullPath} to {tokenizerPath}");

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

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

No structural changes between v0.0.1 and v0.1.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.No target framework metadata is available. Confirm compatibility in a representative project before standardising on this package.

Related Guides & Workflows

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