Registry / ai-ml / detoxify

detoxify

JSON →
library0.5.2pypypi✓ verified 85d ago

Detoxify is a Python library for detecting toxic comments using pre-trained transformer models. It provides a simple interface to classify text as toxic, severe toxic, obscene, threat, insult, identity hate, etc. The latest version is 0.5.2, with releases approximately every few months. It requires Python >=3.7 and supports Hugging Face transformers.

pip install detoxify
INSTALL
IMPORT
SIG · DETOXIFY
D
detoxify
ai-mlpythonv0.5.2
Install
75.2s avg
Import
8860ms
Disk
4992MB
Pass rate
4/ 10
Env Coverage4 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.5.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✕ build_error
✓ 86.35s
py 3.11
✕ build_error
✓ 80.05s
py 3.12
✕ build_error
✓ 69.55s
py 3.13
✕ build_error
✓ 65s
py 3.9
✕ build_error
✕ timeout
4992MB installed
● package 4992MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Detoxify
from detoxify import Detoxify
import Detoxify
Detoxify is a class inside the module, not the module itself.

Loads the 'original' toxic comment model and predicts toxicity scores for a sample sentence.

from detoxify import Detoxify # Load the model (chooses 'original' by default) model = Detoxify('original') result = model.predict('This is a terrible, horrible example!') print(result) # Example output: {'toxicity': 0.9, 'severe_toxicity': 0.1, ...}
Debug
Known issues
gotchaThe default model 'original' may be outdated. For better performance, use 'unbiased' (small) or 'multilingual' (larger) models. See https://github.com/unitaryai/detoxify#available-models.
fix
Specify a model name explicitly: Detoxify('unbiased')
affects: >=0.1.0
gotchaThe output scores are not probabilities; they are raw logits or sigmoid outputs. Thresholds are applied by the library (score >= 0.5 is considered toxic). Do not interpret as calibrated probabilities.
fix
Use the "toxicity" score directly; the library already applies a threshold for classification if needed. Check the `predict` method's threshold parameter.
affects: all
gotchaFirst run will download the model weights (~500 MB) from Hugging Face, which may take time and require an internet connection.
fix
Pre-download models using `detoxify.download_model('original')` before offline use, or set a local cache directory.
affects: all
deprecatedThe 'original' model is based on a deprecated BERT checkpoint. It is no longer recommended for new projects; use 'unbiased' or 'multilingual' instead.
fix
Switch to Detoxify('unbiased') or Detoxify('multilingual').
affects: >=0.4.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'detoxify'
The package is not installed or the module name is misspelled.
fix
Run 'pip install detoxify' in your environment.
OSError: Can't load the model 'original' from HuggingFace. File not found or no internet.
The model is not cached locally and there is no internet connection to download it.
fix
Ensure internet is available on first run, or pre-download the model using detoxify.download_model('original') while connected.
AttributeError: module 'detoxify' has no attribute 'Detoxify'
Incorrect import pattern: used 'import detoxify' instead of 'from detoxify import Detoxify'.
fix
Use 'from detoxify import Detoxify' to import the class.
Upgrade
Version history
0.5.2latest on PyPI · released Feb 1, 2024
Audit
Dependencies
transformersrequiredCore dependency for loading and running pre-trained models.
torchoptionalPyTorch backend for the transformer models. Optional if using TensorFlow.
tensorflowoptionalTensorFlow backend option. Not required if using PyTorch.
Agent activity
15 hits · last 30 days
node
14
OpenAI (training)
1
Resources
detoxify — pip install detoxify · libregistry