Alt Profanity Check
Alt Profanity Check is a fast, robust Python library designed to detect offensive language in strings, serving as a drop-in replacement for the unmaintained `profanity-check` library. It utilizes a linear Support Vector Machine (SVM) model trained on a large dataset of human-labeled text. The library is actively maintained, with frequent updates that align with its primary dependency, `scikit-learn`. The current version is 1.8.0, supporting Python 3.11 and newer.
Common errors
-
ModuleNotFoundError: No module named 'profanity_check'
cause The `alt-profanity-check` library is not installed, or Python cannot find the installed package.fixEnsure `alt-profanity-check` is installed in your active Python environment using `pip install alt-profanity-check`. -
AttributeError: module 'profanity_check' has no attribute 'predict'
cause This typically occurs if `alt-profanity-check` failed to install correctly or its internal data files (`model.joblib`, `vectorizer.joblib`) are missing/corrupted, often due to dependency conflicts with `scikit-learn` or `joblib`.fixReinstall `alt-profanity-check` in a fresh virtual environment to ensure all dependencies are correctly resolved: `python -m venv .venv && source .venv/bin/activate && pip install alt-profanity-check`. -
RuntimeError: Python version 3.10.x is not supported by scikit-learn 1.8.0
cause You are trying to use `alt-profanity-check` v1.8.0 (or newer) with an unsupported Python version. `alt-profanity-check` v1.8.0 requires Python >= 3.11.fixUpgrade your Python environment to 3.11 or newer, or downgrade `alt-profanity-check` to a version compatible with your current Python (e.g., `pip install alt-profanity-check==1.7.2` for Python 3.10).
Warnings
- breaking Python version requirements have changed significantly across minor versions of `alt-profanity-check` due to its tight coupling with `scikit-learn` dependencies. For `alt-profanity-check` v1.8.0, Python >= 3.11 is strictly required.
- gotcha The library is installed via `pip install alt-profanity-check`, but imports use the original module name `profanity_check` (e.g., `from profanity_check import predict`). This is by design, as it's a drop-in replacement.
- breaking Major underlying dependency (`scikit-learn`) version upgrades can introduce breaking changes. `alt-profanity-check` explicitly pins `scikit-learn` versions per release. Mismatched `scikit-learn` versions between what `alt-profanity-check` expects and what is installed in your environment can lead to runtime errors or incorrect predictions.
Install
-
pip install alt-profanity-check
Imports
- predict
from alt_profanity_check import predict
from profanity_check import predict
- predict_prob
from alt_profanity_check import predict_prob
from profanity_check import predict_prob
Quickstart
from profanity_check import predict, predict_prob
# Predict profanity (returns 1 for profane, 0 for clean)
texts = ['hello world', 'go to hell', 'this is a bad word']
predictions = predict(texts)
print(f"Predictions: {predictions}")
# Predict probability of profanity
probabilities = predict_prob(texts)
print(f"Probabilities: {probabilities}")