StanzaSharp 1.0.0
See the version list below for details.
dotnet add package StanzaSharp --version 1.0.0
NuGet\Install-Package StanzaSharp -Version 1.0.0
<PackageReference Include="StanzaSharp" Version="1.0.0" />
<PackageVersion Include="StanzaSharp" Version="1.0.0" />
<PackageReference Include="StanzaSharp" />
paket add StanzaSharp --version 1.0.0
#r "nuget: StanzaSharp, 1.0.0"
#:package StanzaSharp@1.0.0
#addin nuget:?package=StanzaSharp&version=1.0.0
#tool nuget:?package=StanzaSharp&version=1.0.0
StanzaSharp
Stanza's English NLP pipeline in .NET:
- tokenization and sentence splitting
- multi-word token expansion ("don't" → "do" + "n't")
- part-of-speech tags and morphological features
- lemmas
- dependency parsing
- named entities (OntoNotes types: PERSON, ORG, GPE, DATE, ...)
- constituency parsing
- sentence sentiment (negative, neutral, positive)
It runs Stanza's own pretrained models in plain .NET code, with no Python and no native libraries. The output is identical to Python Stanza 1.15.0 on its golden test data.
Install
dotnet add package StanzaSharp
That is all: the models run on StanzaSharp's managed backend, C# kernels using the CPU's SIMD instructions. On the full pipeline it is about twice as fast as the TorchSharp backend on 8 threads and needs less memory, with the same output.
TorchSharp backend. In its own package since 1.0, StanzaSharp.Cuda (also the way to a GPU, below). Add it and
the native libtorch yourself, TorchSharp-cpu (or one platform's libtorch-cpu-<rid> 2.10.0 package; on Windows on
Arm64 libtorch-cpu-win-arm64, since TorchSharp-cpu has none), and select it:
using var nlp = Pipeline.Load(dir, new PipelineOptions { Backend = CudaBackend.Cpu });
- Its version must match the
TorchSharpversion StanzaSharp.Cuda depends on; otherwise the build warns withSTANZA001. - On macOS (Apple Silicon), also run
brew install libomp: libtorch loads OpenMP from Homebrew's path. <StanzaSharpTrimNative>true</StanzaSharpTrimNative>leaves out the libtorch files StanzaSharp never loads (35 MB on Linux x64, 29 MB on macOS).- The
StanzaSharp.Cpu.*platform packages ended with 0.4; referenceTorchSharp-cpuor alibtorch-cpu-<rid>package instead.
Supported platforms
The managed backend runs wherever .NET 10 runs. CI runs it against the golden data on:
| Platform | Managed backend (default) | TorchSharp backend |
|---|---|---|
| Linux x64 (glibc) | Yes | Yes |
| Windows x64 | Yes | Yes |
| Windows on Arm64 | Yes | Yes, with libtorch-cpu-win-arm64 |
| macOS on Apple Silicon | Yes | Yes, after brew install libomp |
| Linux Arm64 (glibc) | Yes (verified in CI) | No: no libtorch or TorchSharp build |
| Alpine and other musl Linux | Yes (verified in CI, Docker) | No: libtorch is built for glibc only |
| macOS on Intel (x64) | Not tested | No |
Docker: any .NET 10 runtime image works, including the chiseled runtime:10.0-noble-chiseled and
runtime:10.0-alpine (publish with -r linux-musl-x64 there): the image needs nothing but the .NET runtime. Mount
the models read-only rather than copying them into the image. A sample Dockerfile is in the repository's
samples/docker.
Download the models
The models (about 600 MB) come from Stanza's Hugging Face repository. Download them once:
await ModelDownloader.DownloadAsync("models/stanza/en"); // all, ~600 MB
await ModelDownloader.DownloadAsync("models/stanza/en", "tokenize,mwt,pos,lemma"); // only what these need
Each file is checked against its published MD5, and files already present are kept. Pipeline.Load itself
never touches the network.
Command line: the stanzasharp .NET tool (package StanzaSharp.Tool, about 1 MB, no native libraries) downloads
them too, e.g. in a Dockerfile or CI:
dotnet tool install -g StanzaSharp.Tool
stanzasharp download models/stanza/en --processors tokenize,mwt,pos,lemma # --package default_fast for that package
Use
using StanzaSharp;
using var nlp = Pipeline.Load("models/stanza/en");
var doc = nlp.Process("Barack Obama was born in Hawaii. He was elected president in 2008.");
foreach (var sentence in doc.Sentences)
{
foreach (var word in sentence.Words)
Console.WriteLine($"{word.Id}\t{word.Text}\t{word.Lemma}\t{word.Upos}\t{word.Feats}\t{word.Head}\t{word.Deprel}");
Console.WriteLine(sentence.Constituency); // (ROOT (S (NP (NNP Barack) (NNP Obama)) ...))
}
Pipeline.Load(dir, new PipelineOptions { Processors = "tokenize,mwt" })runs only the listed processors; each needs the ones before it. The default is all eight, like Stanza's English default:tokenize,mwt,pos,lemma,constituency,depparse,sentiment,ner.- Add
nerto the list for named entities:doc.Entities(text, type, character offsets) and a BIOES tag per token (Token.Ner). - Add
sentimentto the list forsentence.Sentiment: 0 negative, 1 neutral, 2 positive. Conllu.Write(doc)gives CoNLL-U in Stanza's format.nlp.Process(texts)with anyIEnumerable<string>processes many texts at once, like Stanza'sbulk_process: oneDocumentper text, much faster for short texts.nlp.Process(new[] { new[] { "Hello", "world", "." } })takes text that is already split into sentences and tokens, like Stanza'stokenize_pretokenized=True.Processis thread-safe: share one pipeline between threads. Every overload takes aCancellationToken. One call on a short sentence takes about 28 ms on 8 threads (default_fast: 14 ms). On short texts, about two calls in flight per pipeline give the most throughput; more evict each other's weights from the CPU cache. SetMaxConcurrentCalls = 2inPipelineOptionsto make extra callers wait their turn.- Memory: a call's peak is set by its largest batch (the tagger pads up to 250 sentences to the longest), so to
bound it, call
Processon parts of about 1,000 words split at blank lines. The annotations stay the same; withtokenize,mwt,pos,constituencyon 15,000 words the peak drops from 1.7 to 1.2 GB for about 15% more time. - Memory between calls: on the managed backend (the default) the models and the scratch buffers of a call's largest
batches stay on the .NET GC heap for the next call, so the working set stays near the call's peak. To give it back
when a service goes idle, call
GC.Collect(2, GCCollectionMode.Aggressive, blocking: true, compacting: true)a minute or more after the last call (pooled buffers are released only then); the process drops to about its size after loading. On the TorchSharp backend, on Linux (glibc), a call of 1,000 words or more returns the memory it freed to the OS (malloc_trim); on Windows libtorch's allocator keeps it, and the environment variableMIMALLOC_PURGE_DELAY=0, set before libtorch loads, returns it for about 20% more time. PipelineOptions:Backend:PipelineBackend.Managed(the default), orCudaBackend.Create()/CudaBackend.CpufromStanzaSharp.Cuda.Threads: threads per operation, set process-wide at Load: the managed backend's one thread pool (shared by concurrent calls), or libtorch's intra-op threads. By default at mostEnvironment.ProcessorCount, which respects a container's CPU quota.SplitSentences = false: one sentence per paragraph (Stanza'stokenize_no_ssplit).VerifyChecksums: checks the.ptmodel files against Stanza's MD5s before loading.Logger: anILoggerfor load and processing times.
Processor.Tokenize, ...,Processor.Nerare constants for the processor list.
Faster: the default_fast package
new PipelineOptions { Package = "default_fast" } selects Stanza's default_fast package: no constituency
parser, and pos, depparse and ner with their own small character models instead of the large character
language models. It is faster and smaller, and its output is identical to Python Stanza's
package='default_fast'.
var options = new PipelineOptions { Package = "default_fast" };
await ModelDownloader.DownloadAsync("models/stanza/en", options); // what Load reads with these options
using var nlp = Pipeline.Load("models/stanza/en", options);
GPU
Reference StanzaSharp.Cuda and TorchSharp-cuda-windows (or TorchSharp-cuda-linux), then
Pipeline.Load(dir, new PipelineOptions { Backend = CudaBackend.Create(disableTf32: true) }).
disableTf32 gives output identical to the CPU by turning TF32 off process-wide; with TF32 on (libtorch's
default), a few near-tie decisions can differ. See the repository's docs/gpu.md.
License
Apache 2.0, like Stanza, whose code this ports (see NOTICE). Stanza's models are not included. Their licenses vary with the training data.
Source, issues and docs: https://github.com/bisforboman/StanzaSharp
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
NuGet packages (5)
Showing the top 5 NuGet packages that depend on StanzaSharp:
| Package | Downloads |
|---|---|
|
StanzaSharp.Cuda
The TorchSharp (libtorch) backend for StanzaSharp: runs Stanza's English pipeline on an NVIDIA GPU (CudaBackend.Create()) or on libtorch's CPU kernels (CudaBackend.Cpu). Add TorchSharp-cuda-windows or TorchSharp-cuda-linux (TorchSharp-cpu for the CPU) for the native libtorch. |
|
|
StanzaSharp.Cpu.Windows
StanzaSharp plus the CPU libtorch for Windows x64 only. Use instead of StanzaSharp + TorchSharp-cpu, which restores libtorch for Linux, Windows and macOS (about 265 MB of downloads); this restores one platform's. |
|
|
StanzaSharp.Cpu.WindowsArm64
StanzaSharp plus the CPU libtorch for Windows on Arm64 only. TorchSharp-cpu has no Windows Arm64 libtorch, so on Windows on Arm this is the package to use. |
|
|
StanzaSharp.Cpu.MacOS
StanzaSharp plus the CPU libtorch for macOS on Apple Silicon (arm64) only. Use instead of StanzaSharp + TorchSharp-cpu, which restores libtorch for Linux, Windows and macOS (about 265 MB of downloads); this restores one platform's. Needs Homebrew's OpenMP: brew install libomp. |
|
|
StanzaSharp.Cpu.Linux
StanzaSharp plus the CPU libtorch for Linux x64 only. Use instead of StanzaSharp + TorchSharp-cpu, which restores libtorch for Linux, Windows and macOS (about 265 MB of downloads); this restores one platform's. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.8.0 | 0 | 10/15/2026 |
| 1.7.0 | 41 | 10/14/2026 |
| 1.6.0 | 49 | 10/14/2026 |
| 1.5.0 | 66 | 10/13/2026 |
| 1.4.0 | 51 | 10/13/2026 |
| 1.3.0 | 64 | 10/12/2026 |
| 1.2.0 | 67 | 10/12/2026 |
| 1.1.0 | 86 | 10/12/2026 |
| 1.0.0 | 79 | 10/10/2026 |
| 0.6.0 | 64 | 10/10/2026 |
| 0.5.1 | 60 | 10/10/2026 |
| 0.5.0 | 67 | 10/9/2026 |
| 0.4.2 | 89 | 10/7/2026 |
| 0.4.1 | 94 | 10/7/2026 |
| 0.4.0 | 93 | 10/7/2026 |
| 0.3.0 | 89 | 10/6/2026 |
| 0.2.0 | 72 | 10/6/2026 |
| 0.1.0 | 65 | 10/6/2026 |
| 0.1.0-alpha.2 | 48 | 10/6/2026 |
| 0.1.0-alpha.1 | 51 | 10/6/2026 |