SentimentAnalyzer.Core 3.0.0

dotnet add package SentimentAnalyzer.Core --version 3.0.0
                    
NuGet\Install-Package SentimentAnalyzer.Core -Version 3.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SentimentAnalyzer.Core" Version="3.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SentimentAnalyzer.Core" Version="3.0.0" />
                    
Directory.Packages.props
<PackageReference Include="SentimentAnalyzer.Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SentimentAnalyzer.Core --version 3.0.0
                    
#r "nuget: SentimentAnalyzer.Core, 3.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SentimentAnalyzer.Core@3.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SentimentAnalyzer.Core&version=3.0.0
                    
Install as a Cake Addin
#tool nuget:?package=SentimentAnalyzer.Core&version=3.0.0
                    
Install as a Cake Tool

SentimentAnalyzer

NuGet NuGet Downloads License: MIT

On-device (offline) Sentiment Analysis for .NET applications

A cross-platform, privacy-first library for sentiment analysis that runs entirely on-device without requiring internet connectivity.

โœจ Features

  • ๐Ÿ”’ Privacy-first - All processing happens on-device
  • ๐Ÿ“ด Fully offline - No internet connection required
  • ๐Ÿš€ Cross-platform - .NET Standard 2.0, .NET 8, .NET 10, MAUI, Blazor
  • โšก Multiple engines - Choose between speed, accuracy, or both
  • ๐ŸŒ Multilingual - Support for 104 languages

๐Ÿš€ Quick Start

dotnet add package SentimentAnalyzer.Core
using SentimentAnalyzer;

// Simple usage
var analyzer = new SentimentAnalyzer();
var result = analyzer.Analyze("I love this product!");

Console.WriteLine($"Sentiment: {result.Label}");     // Positive
Console.WriteLine($"Score: {result.Score:F2}");      // 0.87
Console.WriteLine($"Confidence: {result.Confidence:F2}");  // 0.74

Option B: High Accuracy (TinyBERT) - English Only

dotnet add package SentimentAnalyzer.Core
dotnet add package SentimentAnalyzer.Onnx
using SentimentAnalyzer;
using SentimentAnalyzer.Onnx;

// Use TinyBERT for higher accuracy (embedded model, ~18MB)
var analyzer = SentimentAnalyzer.CreateBuilder()
    .UseTinyBert()
    .Build();

var result = analyzer.Analyze("This product is amazing!");
Console.WriteLine($"Sentiment: {result.Label}");  // Positive
Console.WriteLine($"Confidence: {result.Confidence:P0}");  // 99%

Option C: Multilingual (DistilBERT) - 104 Languages

dotnet add package SentimentAnalyzer.Core
dotnet add package SentimentAnalyzer.Onnx.Multilingual
using SentimentAnalyzer;
using SentimentAnalyzer.Onnx.Multilingual;

// Use DistilBERT for multilingual support (downloads ~270MB model on first use)
var analyzer = SentimentAnalyzer.CreateBuilder()
    .UseDistilBert()
    .Build();

// Supports 104 languages!
var result = analyzer.Analyze("Ce produit est fantastique!");  // French
Console.WriteLine($"Sentiment: {result.Label}");  // Positive

// Also works with: Arabic, Chinese, German, Spanish, Hindi, Japanese, etc.

๐Ÿ“ฅ Note on DistilBERT Multilingual: The ~270MB model is automatically downloaded from GitHub Releases on first use and cached locally at %LOCALAPPDATA%\SentimentAnalyzer\models\. Subsequent uses are fully offline. See full list of 104 supported languages.

Option D: Legacy API (Backward Compatible)

dotnet add package SentimentAnalyzer
using SentimentAnalyzer;

// v1.x/v2.x API still works
var result = Sentiments.Predict("This product is amazing!");
Console.WriteLine($"Positive: {result.Prediction}");  // true

๏ฟฝ Choosing the Right Package

Package Comparison

Package Size Engine Languages Accuracy Speed Best For
SentimentAnalyzer.Core <1MB VADER (rule-based) English ~80% โšกโšกโšกโšกโšก Mobile, IoT, speed-critical apps
SentimentAnalyzer.Onnx ~18MB TinyBERT (transformer) English ~94% โšกโšกโšกโšก High accuracy, embedded model
SentimentAnalyzer.Onnx.Multilingual ~541MB DistilBERT (transformer) 104 languages ~83% โšกโšกโšก Multilingual, highest accuracy
SentimentAnalyzer ~15MB ML.NET (traditional ML) English ~85% โšกโšกโšกโšก Backward compatibility

Speed ratings: โšกโšกโšกโšกโšก (fastest) to โšก (slowest)

Platform Support

Platform Core Onnx (TinyBERT) Onnx.Multilingual Legacy
.NET Standard 2.0 โœ… โœ… โœ… โœ…
.NET 8 (LTS) โœ… โœ… โœ… โœ…
.NET 10 (LTS) โœ… โœ… โœ… โœ…
.NET MAUI โœ… โœ… โœ… โœ…
Blazor WASM โœ… โŒ โŒ โœ…
Blazor Server โœ… โœ… โœ… โœ…
Unity โœ… โš ๏ธ โŒ โœ…

Note: ONNX models require native C++ libraries and cannot run in Blazor WebAssembly. Use Core (VADER) for WASM or Blazor Server for ML models.

Use Cases

Use Case Recommended Package
Mobile apps (MAUI, Xamarin) Core (VADER) or Onnx (TinyBERT)
IoT/Edge devices Core (VADER)
Blazor WebAssembly Core (VADER)
Speed-critical applications Core (VADER)
High accuracy (English) Onnx (TinyBERT)
Multilingual support Onnx.Multilingual (DistilBERT)
Social media analysis Core (VADER - optimized for social text with emojis)
Customer reviews Onnx (TinyBERT) or Onnx.Multilingual
Enterprise/existing apps Legacy (ML.NET)

๏ฟฝ๐Ÿ“– API Reference

Core Package

SentimentAnalyzer Class
// Default constructor (uses VADER engine)
var analyzer = new SentimentAnalyzer();

// With options
var analyzer = new SentimentAnalyzer(SentimentAnalyzerOptions.Binary);

// Builder pattern
var analyzer = SentimentAnalyzer.CreateBuilder()
    .WithNeutralThresholds(0.3, 0.7)  // Customize neutral zone
    .Build();
SentimentResult
Property Type Description
Text string Original input text
Label SentimentLabel Positive, Neutral, or Negative
Score double Normalized score (0-1)
Confidence double Prediction confidence (0-1)
Engine string Engine name ("Vader", "TinyBert", "DistilBert")
IsPositive bool Shorthand for Label == Positive
IsNegative bool Shorthand for Label == Negative
IsNeutral bool Shorthand for Label == Neutral
SentimentAnalyzerOptions
// Presets
SentimentAnalyzerOptions.Default   // Neutral zone: 0.4-0.6
SentimentAnalyzerOptions.Binary    // No neutral (positive/negative only)
SentimentAnalyzerOptions.Strict    // Narrow neutral: 0.45-0.55
SentimentAnalyzerOptions.Lenient   // Wide neutral: 0.3-0.7
Batch Processing
var analyzer = new SentimentAnalyzer();

var reviews = new[] {
    "Great product!",
    "Terrible service.",
    "It's okay I guess."
};

var results = analyzer.AnalyzeBatch(reviews);
foreach (var result in results)
{
    Console.WriteLine($"{result.Label}: {result.Text}");
}

๐Ÿ› ๏ธ Advanced Usage

Custom Engine

// Implement ISentimentEngine for custom engines
public class MyCustomEngine : ISentimentEngine
{
    public string Name => "Custom";

    public SentimentResult Analyze(string text) { /* ... */ }
    public IReadOnlyList<SentimentResult> AnalyzeBatch(IEnumerable<string> texts) { /* ... */ }
    public void Dispose() { }
}

// Use with builder
var analyzer = SentimentAnalyzer.CreateBuilder()
    .WithEngine(_ => new MyCustomEngine())
    .Build();
```

### TinyBERT with Custom Options

```csharp
using SentimentAnalyzer.Onnx;
using Microsoft.ML.OnnxRuntime;

// Configure ONNX Runtime session options
var sessionOptions = new SessionOptions
{
    GraphOptimizationLevel = GraphOptimizationLevel.ORT_ENABLE_ALL,
    ExecutionMode = ExecutionMode.ORT_PARALLEL
};

var analyzer = SentimentAnalyzer.CreateBuilder()
    .UseTinyBert(sessionOptions)
    .WithBinaryClassification()  // Disable neutral classification
    .Build();

DistilBERT Multilingual with Progress

using SentimentAnalyzer.Onnx.Multilingual;

var progress = new Progress<double>(p =>
    Console.WriteLine($"Downloading model: {p:P0}"));

var analyzer = await SentimentAnalyzer.CreateBuilder()
    .UseDistilBertMultilingualAsync(progress: progress);

// Model is now cached locally, subsequent uses are offline

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

๐Ÿ“š Learn More


โšก Performance Comparison

Engine Package Accuracy Speed Size Languages
VADER Core ~80% โšกโšกโšกโšกโšก <1MB English
TinyBERT Onnx ~94% โšกโšกโšกโšก ~18MB English
DistilBERT Onnx.Multilingual ~83% โšกโšกโšก ~541MB 104
ML.NET (Legacy) SentimentAnalyzer ~85% โšกโšกโšกโšก ~15MB English

Speed ratings: โšกโšกโšกโšกโšก (fastest) to โšก (slowest). Accuracy tested on various datasets. ๏ฟฝ Migration from v2.x

If using Sentiments.Predict():

No changes needed! The legacy API continues to work:

<PackageReference Include="SentimentAnalyzer" Version="3.0.0" />

To use new engines (smaller, faster, or more accurate):

// Before (ML.NET, ~15MB)
var result = Sentiments.Predict("I love this!");

// After (VADER, <1MB - fastest)
var analyzer = new SentimentAnalyzer();
var result = analyzer.Analyze("I love this!");

// Result now has more properties:
// result.Label (enum), result.Confidence, result.IsPositive, etc.

๐Ÿ“š Learn More

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on SentimentAnalyzer.Core:

Package Downloads
SentimentAnalyzer.Onnx.Multilingual

High-accuracy multilingual sentiment analysis using DistilBERT transformer. Supports 104 languages with 3-class classification (positive/neutral/negative). NOTE: The ~270MB model is downloaded on first use and cached locally for offline use. Requires SentimentAnalyzer.Core.

SentimentAnalyzer.Onnx

Lightweight transformer-based sentiment analysis using TinyBERT (~18MB). 94.2% accuracy on Amazon reviews. Fully offline with embedded model. English-only, binary classification (positive/negative). For multilingual support, use SentimentAnalyzer.Onnx.Multilingual.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.0 49 1/26/2026

v3.0 introduces a modular architecture with multiple sentiment engines. Core package includes VADER (rule-based, <1MB) for fast, lightweight sentiment analysis.