Production-ready multi-label toxicity classification worker service
206
Production-ready multi-label toxicity classification worker service built with Hexagonal Architecture (Ports and Adapters) using unitary/toxic-bert run with ONNX Runtime on CPU.
The service uses:
fastapi & uvicorn for the REST APIoptimum[onnxruntime] for exporting and running the model on ONNX Runtime CPUopentelemetry-api & opentelemetry-sdk for tracing| Variable | Description | Default |
|---|---|---|
PORT | FastAPI service port | 8008 |
TOXICITY_MODEL_ID | Model identifier or local path | unitary/toxic-bert |
docker build -t chiefj/toxicity-worker:latest -f build/Dockerfile .
Run the container by passing the environment variables:
docker run -d \
-p 8008:8008 \
-e PORT=8008 \
-e TOXICITY_MODEL_ID=unitary/toxic-bert \
--name toxicity-worker \
chiefj/toxicity-worker:latest
Defined in contracts/openapi/v1.yaml.
Response:
{
"status": "ok",
"model": "unitary/toxic-bert",
"model_id": "unitary/toxic-bert"
}
Request:
{
"text": "response text here"
}
Response:
{
"toxicity": 0.02,
"severe_toxicity": 0.00,
"obscene": 0.01,
"threat": 0.00,
"insult": 0.02,
"identity_hate": 0.00
}
For texts exceeding 510 tokens, the response will also include the long response strategy:
{
"toxicity": 0.02,
"severe_toxicity": 0.00,
"obscene": 0.01,
"threat": 0.00,
"insult": 0.02,
"identity_hate": 0.00,
"long_response_strategy": "max_of_two_passes"
}
Run the test suite using pytest with the following command:
cd packages/python/toxicity-worker
python3 -m pytest tests/ -v --tb=short --cov=src --cov-report=term-missing
Content type
Image
Digest
sha256:3314c456a…
Size
3.2 GB
Last updated
3 months ago
docker pull chiefj/toxicity-worker