SentimentAnalyzer.Core
3.0.0
dotnet add package SentimentAnalyzer.Core --version 3.0.0
NuGet\Install-Package SentimentAnalyzer.Core -Version 3.0.0
<PackageReference Include="SentimentAnalyzer.Core" Version="3.0.0" />
<PackageVersion Include="SentimentAnalyzer.Core" Version="3.0.0" />
<PackageReference Include="SentimentAnalyzer.Core" />
paket add SentimentAnalyzer.Core --version 3.0.0
#r "nuget: SentimentAnalyzer.Core, 3.0.0"
#:package SentimentAnalyzer.Core@3.0.0
#addin nuget:?package=SentimentAnalyzer.Core&version=3.0.0
#tool nuget:?package=SentimentAnalyzer.Core&version=3.0.0
SentimentAnalyzer
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
Option A: Lightweight (VADER) - Recommended for most apps
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
- Blog Post: On-device Machine Learning with SentimentAnalyzer
- CHANGELOG for version history
- GitHub Releases for model downloads
โก 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
- Blog Post: On-device Machine Learning with SentimentAnalyzer
- Sample Applications - Console, Blazor, MAUI examples
- CHANGELOG - Version history and migration guides
- GitHub Releases - Model downloads
๐ค 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 | Versions 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. |
-
.NETStandard 2.0
- VaderSharp2 (>= 3.3.2.1)
-
net10.0
- VaderSharp2 (>= 3.3.2.1)
-
net8.0
- VaderSharp2 (>= 3.3.2.1)
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.