RuleBasedContentClassifier<T>
Models & Types · AiDotNet.AdversarialRobustness.Safety
A rule-based content classifier that uses pattern matching for classification.
Inheritance: ContentClassifierBase<T> → RuleBasedContentClassifier<T>
For Beginners
This is a simple classifier that looks for specific words and patterns in text. While it’s less sophisticated than ML-based classifiers, it’s fast, interpretable, and doesn’t require training data.
How It Works
This classifier serves as a baseline or fallback when ML models are not available. It uses configurable regex patterns to detect various categories of harmful content.
Constructors
| Constructor | Summary |
|---|---|
RuleBasedContentClassifier(Dictionary<string, List<string>> categoryPatterns, double threshold) |
Initializes a new rule-based content classifier with custom patterns. |
RuleBasedContentClassifier(double threshold) |
Initializes a new rule-based content classifier with default patterns. |
Methods
| Method | Summary |
|---|---|
ContentClassificationResult<T> Classify(Vector<T> content) |
|
ContentClassificationResult<T> ClassifyText(string text) |
|
bool IsReady() |
|
byte[] Serialize() |
Auto-generated common model serialization surface. |
void AddPattern(string category, string pattern) |
Adds a detection pattern for a category. |
void ClearCategory(string category) |
Removes all patterns for a category. |
void Deserialize(byte[] data) |
Auto-generated common model deserialization surface. |