English |
Русский
A simple toxicity detector.
The model is built on rubert-tiny2 and trained using knowledge distillation from the more powerful russian_toxicity_classifier. The architecture features a hybrid approach: neural network embeddings are supplemented by signals from a built-in profanity dictionary (including an exceptions system). This allows the model to achieve high accuracy while maintaining a minimal size.
The model was tested on an independent test set of 102,217 lines that was completely unseen during training. To minimize false positives, the classification threshold was dynamically optimized for Precision 95% on the validation set and saved directly inside the model weights file.
| Metric | Value | Comment |
|---|---|---|
| Accuracy | 1.00 | High value due to significant class imbalance |
| Precision (Toxic) | 0.94 | 94% accuracy in classifying toxic content |
| Recall (Toxic) | 0.65 | The model detects ~2/3 of all toxic messages |
| F1-score (Toxic) | 0.77 | Harmonic mean of precision and recall |
The high Precision (0.94) ensures that the model almost never produces false positives. The lower Recall (0.65) is a deliberate trade-off to ensure a comfortable user experience without aggressive over-blocking.
from toxicity_detector import ToxicityDetector
# Create detector (optionally specify device)
detector = ToxicityDetector(device="cpu")
texts = [
'Ты берега попутал?', # {'is_toxic': False, 'score': 0.1941}
'Это правый берег реки, не путай с левым.', # {'is_toxic': False, 'score': 0.0223}
"Ты дуралей." # {'is_toxic': True, 'score': 0.9958}
]
# Predict one by one
for idx, text in enumerate(texts, start=1):
print(f"{idx}) {detector.predict(text)}")
# Predict batch (faster for multiple texts)
results = detector.predict_batch(texts)
for idx, res in enumerate(results, start=1):
print(f"{idx}) {res}")pip install git+https://github.com/KvaytG/ru-toxicity-detector.gitLicensed under the PolyForm Noncommercial license.
This project uses open-source components. For license details see pyproject.toml and dependencies' official websites.