tonybaloney/TransformersSharp

A little wrapper for hugging face transformers in C#

C#

123

104 commits

updated Jul 27, 2025

See the code

README

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);
}
dotnet
huggingface
huggingface-transformers

Significant stargazers

AliReZa Sabouri

162 followers · starred May 2025

tonybaloney/TransformersSharp

A little wrapper for hugging face transformers in C#

C#

123

104 commits

updated Jul 27, 2025

See the code

README

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);
}
dotnet
huggingface
huggingface-transformers

Significant stargazers

AliReZa Sabouri

162 followers · starred May 2025

Languages

C#

81.8%

Python

18.2%