DotnetBadWordDetector 2.0.0

dotnet add package DotnetBadWordDetector --version 2.0.0
                    
NuGet\Install-Package DotnetBadWordDetector -Version 2.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="DotnetBadWordDetector" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DotnetBadWordDetector" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="DotnetBadWordDetector" />
                    
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 DotnetBadWordDetector --version 2.0.0
                    
#r "nuget: DotnetBadWordDetector, 2.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.
#addin nuget:?package=DotnetBadWordDetector&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=DotnetBadWordDetector&version=2.0.0
                    
Install as a Cake Tool

.NET Bad Word Detector and Filter

This is a fast and robust library that detects offensive language within text strings. It currently supports English, Portuguese, and Spanish languages.

How It Works

This library uses a logistic regression ML.NET model trained on thousands of human-labeled words. The trained model is embedded as a resource in this library and is consulted on every prediction.

Why Use This Library?

Unlike other .NET profanity detection libraries that rely solely on static hard-coded lists of bad words — such as ProfanityDetector — which uses this list stored in memory, this library uses a machine learning approach that can detect creative substitutions and misspellings (e.g., "h0us3" instead of "house"). This makes it much harder to bypass.

Performance

In benchmarks, this library was up to 618 times faster than the most downloaded .NET package for detecting profanity. For 100 successive predictions, it was approximately 24 times faster.

Package 1 Prediction 10 Predictions 100 Predictions
.NET Bad Word Detector 0.0462 ms 1.5508 ms 4.1887 ms
ProfanityDetector 28.5823 ms 42.4606 ms 102.0750 ms

PC specs: Dell Inspiron 13, i7 8th gen, 16 GB RAM.

Installation

dotnet add package DotnetBadWordDetector

How to Use

Create the detector

using DotnetBadWordDetector;

// English only (default)
var detector = new ProfanityDetector();

// Or load all supported languages: English, Spanish, and Portuguese
var detectorAll = new ProfanityDetector(allLocales: true);

Check if a word is offensive

if (detector.IsProfane("example")) {
    // Word is classified as offensive
}

Check if a phrase contains any offensive words

if (detector.IsPhraseProfane("this is an example")) {
    // Phrase contains at least one offensive word
}

Get the probability that a word or phrase is offensive

float probWord = detector.GetProfanityProbability("example");
float probPhrase = detector.GetPhraseProfanityProbability("this is an example");

Mask offensive words in a phrase

string cleanText = detector.MaskProfanity("this is an example", '*');

This will replace any detected offensive words with asterisks or your chosen character.

Model Quality

Model quality metrics evaluation
--------------------------------
Accuracy: 98.43%
AUC: 99.49%
F1 Score: 97.25%

Notes

This library is not perfect: it is not 100% accurate and it is context-free — meaning it cannot detect profane phrases made of individually inoffensive words. Definitions of "profanity" can vary by culture. This library uses human-labeled data, which might not align perfectly with all contexts.

Tips

  • Keep the detector instance in memory for better performance — it uses very little memory (less than 100 KB).
  • Be cautious when enabling all locales together, as it may produce more false positives in multilingual texts.

Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request with suggestions for new features, languages, or improvements.

Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on DotnetBadWordDetector:

Package Downloads
Veltonsoft.BrawlStars.V24.MonolithCore

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 151 6/4/2025
1.0.1 14,525 3/8/2022
1.0.0 477 3/8/2022