A little wrapper for hugging face transformers in C#
See the code
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.
PreTrainedTokenizerBaseFor 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);
}
162 followers · starred May 2025
C#
81.8%
Python
18.2%
A little wrapper for hugging face transformers in C#
See the code
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.
PreTrainedTokenizerBaseFor 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);
}
162 followers · starred May 2025
C#
81.8%
Python
18.2%