SafeSpeech pipeline for hate intensity classification, explanation, and mitigation in Indic social media text
Jupyter Notebook
0
11 commits
updated Jul 10, 2026
SafeSpeech is a pipeline for hate/offensive text moderation and mitigation in Indic languages.
For the live Hindi flow, the system does this:
hate or non-hatenon-hate: return original text unchangedhate: return influential words and a mitigation attemptFastAPI) for Hindi moderation//metricsscripts/test_full_flow.py3.11+ (3.12 also works)gitdocker (for container run)git clone https://github.com/neeraj1909/safespeech-indic-hate-mitigation.git
cd safespeech-indic-hate-mitigation
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install --upgrade pip
pip install -e .
The live API requires both paths:
Example paths used in this repo:
./muril_supervised_hasoc2019_macd_hindi/final./mlm_muril/finetuned_google_muril_mlmIf either path is missing, server startup fails fast with a clear error.
python3 scripts/run_api.py \
--classifier-path ./muril_supervised_hasoc2019_macd_hindi/final \
--mlm-path ./mlm_muril/finetuned_google_muril_mlm \
--device cpu \
--port 8000
After startup:
http://localhost:8000/http://localhost:8000/healthhttp://localhost:8000/metricscurl http://localhost:8000/health
curl -X POST http://localhost:8000/v1/moderate-hindi \
-H "Content-Type: application/json" \
-d '{"text":"यह पाठ घृणित नहीं है"}'
Expected behavior:
output_text, mitigation=nullinfluential_words populated and mitigation attemptedcurl http://localhost:8000/metrics
Metrics include:
request_counthate_ratemitigation_success_ratelatency_p50_ms, latency_p95_ms, latency_max_ms)python3 scripts/test_full_flow.py --base-url http://localhost:8000
python3 scripts/test_full_flow.py \
--start-server \
--classifier-path ./muril_supervised_hasoc2019_macd_hindi/final \
--mlm-path ./mlm_muril/finetuned_google_muril_mlm \
--device cpu \
--base-url http://localhost:8000
If server is not running for Option A, script exits cleanly with:
API is not reachable ... Start the server first, or rerun with --start-server.docker build -t safespeech-live .
docker run --rm -p 8000:8000 \
-v /absolute/path/to/classifier:/models/classifier:ro \
-v /absolute/path/to/mlm:/models/mlm:ro \
safespeech-live
Then test:
curl http://localhost:8000/health
curl -X POST http://localhost:8000/v1/moderate-hindi \
-H "Content-Type: application/json" \
-d '{"text":"यह पाठ घृणित नहीं है"}'
timeout 60 uv run pytest -m unit --no-cov
timeout 60 uv run pytest -m integration --no-cov
uv run ruff check --fix .
Connection refused on localhost:8000scripts/run_api.py, or use scripts/test_full_flow.py --start-server.--classifier-path and --mlm-path exist and point to directories.docker system prune -af
MIT
SafeSpeech pipeline for hate intensity classification, explanation, and mitigation in Indic social media text
Jupyter Notebook
0
11 commits
updated Jul 10, 2026
SafeSpeech is a pipeline for hate/offensive text moderation and mitigation in Indic languages.
For the live Hindi flow, the system does this:
hate or non-hatenon-hate: return original text unchangedhate: return influential words and a mitigation attemptFastAPI) for Hindi moderation//metricsscripts/test_full_flow.py3.11+ (3.12 also works)gitdocker (for container run)git clone https://github.com/neeraj1909/safespeech-indic-hate-mitigation.git
cd safespeech-indic-hate-mitigation
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install --upgrade pip
pip install -e .
The live API requires both paths:
Example paths used in this repo:
./muril_supervised_hasoc2019_macd_hindi/final./mlm_muril/finetuned_google_muril_mlmIf either path is missing, server startup fails fast with a clear error.
python3 scripts/run_api.py \
--classifier-path ./muril_supervised_hasoc2019_macd_hindi/final \
--mlm-path ./mlm_muril/finetuned_google_muril_mlm \
--device cpu \
--port 8000
After startup:
http://localhost:8000/http://localhost:8000/healthhttp://localhost:8000/metricscurl http://localhost:8000/health
curl -X POST http://localhost:8000/v1/moderate-hindi \
-H "Content-Type: application/json" \
-d '{"text":"यह पाठ घृणित नहीं है"}'
Expected behavior:
output_text, mitigation=nullinfluential_words populated and mitigation attemptedcurl http://localhost:8000/metrics
Metrics include:
request_counthate_ratemitigation_success_ratelatency_p50_ms, latency_p95_ms, latency_max_ms)python3 scripts/test_full_flow.py --base-url http://localhost:8000
python3 scripts/test_full_flow.py \
--start-server \
--classifier-path ./muril_supervised_hasoc2019_macd_hindi/final \
--mlm-path ./mlm_muril/finetuned_google_muril_mlm \
--device cpu \
--base-url http://localhost:8000
If server is not running for Option A, script exits cleanly with:
API is not reachable ... Start the server first, or rerun with --start-server.docker build -t safespeech-live .
docker run --rm -p 8000:8000 \
-v /absolute/path/to/classifier:/models/classifier:ro \
-v /absolute/path/to/mlm:/models/mlm:ro \
safespeech-live
Then test:
curl http://localhost:8000/health
curl -X POST http://localhost:8000/v1/moderate-hindi \
-H "Content-Type: application/json" \
-d '{"text":"यह पाठ घृणित नहीं है"}'
timeout 60 uv run pytest -m unit --no-cov
timeout 60 uv run pytest -m integration --no-cov
uv run ruff check --fix .
Connection refused on localhost:8000scripts/run_api.py, or use scripts/test_full_flow.py --start-server.--classifier-path and --mlm-path exist and point to directories.docker system prune -af
MIT