Skip to content

thenewth/TransformersSharp

 
 

Repository files navigation

TransformersSharp

Logo

A little wrapper for Hugging Face Transformers in C#. This is not a comprehensive 1:1 mapping of the whole HuggingFace transformers package, because the API is enormous.

If you need a specific feature, toggle or pipeline API clone this repo and make adjustments.

This project was created using CSnakes and will fetch Python, PyTorch, and Hugging Face Transformers automatically, so you don't need to install them manually.

Full Documentation

Features

Usage

For example, the Python code:

from transformers import pipeline
import torch

pipeline = pipeline("text-generation", model="Qwen/Qwen2.5-0.5B", torch_dtype=torch.bfloat16)
results = pipeline("Tell me a story about a brave knight.", max_length=100, temperature=0.7)
for result in results:
    print(result["generated_text"])

Is equivalent to:

using TransformersSharp.Pipelines;

var pipeline = TextGenerationPipeline.FromModel("Qwen/Qwen2.5-0.5B", TorchDtype.BFloat16);
var results = pipeline.Generate("Tell me a story about a brave knight.", maxLength: 100, temperature: 0.7);
foreach (var result in results)
{
    Console.WriteLine(result);
}

About

A little wrapper for hugging face transformers in C#

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • C# 81.4%
  • Python 18.6%