Moderators: One package to moderate them all
Project description
Moderators
TODO: refactor readme to target users instead of maintainers
This repository provides an extensible core skeleton for content moderation. Phase 1 includes:
- Standard data classes (Box, PredictionResult)
- BaseModerator flow (predict → _preprocess → _predict → _postprocess)
- ModelHubMixin-based
AutoModeratorfactory (readsconfig.jsonfrom HF Hub or local) - CLI:
moderators(load and run inference)
First integration: Transformers.
Installation
Create Python environment (Python 3.10+ recommended):
uv venv --python 3.10
source .venv/bin/activate
Install with pip:
pip install moderators[transformers]
Install with uv:
uv add "moderators[transformers]"
Install from source:
uv sync --extra transformers
Quick Start
from moderators.auto_model import AutoModerator
moderator = AutoModerator.from_pretrained("org/model") # or a local folder path
results = moderator("some input")
print(results)
config.json example (Transformers):
{
"architecture": "TransformersModerator",
"task": "image-classification"
}
- Naming convention: the
XyzModeratorclass must be defined inmoderators/integrations/xyz_moderator.py. - Note:
AutoModeratoris a factory class; it returns the actual integration instance.
Automatic dependency installation
When using the Transformers integration, the library may auto-install missing dependencies at runtime:
- transformers
- A deep learning framework (PyTorch preferred: torch)
- Pillow (for image tasks)
It uses uv if available, otherwise falls back to pip. Disable auto-install via:
export MODERATORS_DISABLE_AUTO_INSTALL=1
Usage Overview
AutoModerator.from_pretrained("org/model") dynamically loads the correct integration class based on the "architecture" field in config.json.
Command Line (CLI)
Run models directly from the terminal.
Usage:
moderators <model_id_or_local_dir> <input> [--local-files-only]
Examples:
- Text classification:
moderators distilbert/distilbert-base-uncased-finetuned-sst-2-english "I love this!"
- Image classification (Falconsai/nsfw_image_detection) with a local image:
moderators Falconsai/nsfw_image_detection /path/to/image.jpg
Notes:
- The CLI prints JSON to stdout.
- Use
--local-files-onlyto force offline usage if all files are already cached.
Transformers config inference
If "architecture" is missing but the config looks like a Transformers model (e.g., has architectures, transformers_version, id2label/label2id), the factory assumes:
architecture = "TransformersModerator"- It tries to infer
"task"(e.g., classification). If it cannot infer, you must specify"task"explicitly (e.g.,"image-classification").
Callbacks
Moderators run a minimal callback system around prediction:
on_predict_start(moderator)is called before prediction.on_predict_end(moderator)is called after prediction.
By default, on_predict_start enqueues a lightweight analytics event (see below). You can customize per-instance callbacks:
mod = AutoModerator.from_pretrained("org/model")
# Disable all start callbacks (including analytics)
mod.callbacks["on_predict_start"].clear()
# Or add your own callback
def my_callback(m):
print("Starting inference for", m.model_id)
mod.callbacks["on_predict_start"].append(my_callback)
Anonymous Telemetry
We believe in providing our users with full control over their data. By default, our package is configured to collect analytics to help improve the experience for all users. However, we respect that some users may prefer to opt out of this data collection.
To opt out of sending analytics, you can simply create ~/.moderators/settings.json file with "sync": false. This ensures that no data is transmitted from your machine to our analytics tools.
Limitations (Phase 1)
- Only
TransformersModeratoris supported; other architectures raiseNotImplementedError. - Image tasks require Pillow and at least one DL framework (preferably PyTorch). The library may attempt auto-install, otherwise it will raise an error.
Integrations
- Transformers integration
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file moderators-0.0.1.tar.gz.
File metadata
- Download URL: moderators-0.0.1.tar.gz
- Upload date:
- Size: 23.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9558f28d64fa0fb5db4e6a3b0826ea6e39e8346ba665d52cadcad38e9fc928d0
|
|
| MD5 |
1c6ac6de5a53ba83c6a8c058a1680ec4
|
|
| BLAKE2b-256 |
37c3f3747e87afa3a09a9c0d733a6210876237d7b52e1a2606d61693e6f9380f
|
Provenance
The following attestation bundles were made for moderators-0.0.1.tar.gz:
Publisher:
publish.yml on viddexa/moderators
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
moderators-0.0.1.tar.gz -
Subject digest:
9558f28d64fa0fb5db4e6a3b0826ea6e39e8346ba665d52cadcad38e9fc928d0 - Sigstore transparency entry: 595711497
- Sigstore integration time:
-
Permalink:
viddexa/moderators@b80ad7c3be2d82d300754aa439ce1bbd5988e12b -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/viddexa
-
Access:
internal
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b80ad7c3be2d82d300754aa439ce1bbd5988e12b -
Trigger Event:
release
-
Statement type:
File details
Details for the file moderators-0.0.1-py3-none-any.whl.
File metadata
- Download URL: moderators-0.0.1-py3-none-any.whl
- Upload date:
- Size: 19.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17bbb55fad540c8614ff3db3ea504604070f93139e6116d34090e2c7f75ff1f8
|
|
| MD5 |
6d8ca53b30ce03f2d8fbc809d16984b1
|
|
| BLAKE2b-256 |
4a7b0b19de0540737c1f8b489fc5e3acdc32896e35571a3f2f525876c366d61f
|
Provenance
The following attestation bundles were made for moderators-0.0.1-py3-none-any.whl:
Publisher:
publish.yml on viddexa/moderators
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
moderators-0.0.1-py3-none-any.whl -
Subject digest:
17bbb55fad540c8614ff3db3ea504604070f93139e6116d34090e2c7f75ff1f8 - Sigstore transparency entry: 595711546
- Sigstore integration time:
-
Permalink:
viddexa/moderators@b80ad7c3be2d82d300754aa439ce1bbd5988e12b -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/viddexa
-
Access:
internal
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b80ad7c3be2d82d300754aa439ce1bbd5988e12b -
Trigger Event:
release
-
Statement type: