Downloads · 30 days
10
9% of all-time downloads
Pommu/threat-detection-jigsaw
threat-detection-jigsaw is a text classification model from Pommu. Use it when you need a label for a piece of text. The card lists the license as mit.
NLP Course Project — Individual Assignment Model: Fine-tuned roberta-base | Task: 6-class Multi-label Classification Dataset: google/jigsawtoxicitypred (~150K samples)
Downloads · 30 days
10
9% of all-time downloads
All-time downloads
106
Public
Parameters
125M
997 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors499 MB · 99%
From the Hugging Face model README
NLP Course Project — Individual Assignment
Model: Fine-tuned roberta-base | Task: 6-class Multi-label Classification
Dataset: google/jigsaw_toxicity_pred (~150K samples)
| Resource | URL |
|---|---|
| 🖥️ Interactive UI (HuggingFace Spaces) | https://huggingface.co/spaces/Pommu/threat-detection-jigsaw |
| 🤖 Fine-tuned Model | https://huggingface.co/Pommu/threat-detection-jigsaw |
| 🔌 Local API | http://localhost:8000/predict (POST) |
Modern organizations face increasing risks from implicit threats and workplace harassment. Unlike simple slur-detectors, this project focuses on intent-based detection. It uses the Jigsaw Toxic Comment dataset to identify professional and personal risk across 6 binary categories:
| Label | Description | Risk Level |
|---|---|---|
Threatening | Violent intent, intimidation, physical danger | 🔴 HIGH |
Hate Speech | Identity-based attacks, protected groups | 🔴 HIGH |
Highly Severe | Extreme toxicity, highly disruptive | 🔴 HIGH |
Toxic | Rude, disrespectful, unprofessional | 🟡 MEDIUM |
Insult | Personal attacks, non-violent harassment | 🟡 MEDIUM |
Profanity | Obscene language, compliance violation | 🟡 LOW |
[User Input: Text / Chat Transcript]
│
▼
[Gradio UI] ── HTTP POST /predict ──▶ [FastAPI Backend]
│
┌────────────┴────────────┐
│ │
[Layer 1] [Layer 2]
Fine-tuned RoBERTa Lexical Booster
(6 Jigsaw labels) (keyword pattern match)
│ │
└────────────┬────────────┘
│
{label, confidence, risk_level}
threat class (0.3% of data) to maximize recall.Design Choice: We prioritize Recall over Precision for threats. A false positive (flagging safe text) is far less costly than a false negative (missing a real threat).
# Test implicit threat detection locally
curl -X POST http://localhost:8000/predict \
-H "Content-Type: application/json" \
-d '{"text": "I will find you and you will regret every decision you have made."}'
JSON Response:
{
"prediction": "Threatening",
"confidence": 0.85,
"is_threat": true,
"risk_level": "HIGH",
"all_scores": [
{"label": "Toxic", "confidence": 0.0009},
{"label": "Threatening", "confidence": 0.85},
...
]
}
NLP Course Project/
├── notebook/
│ └── train_3.ipynb ← Colab training notebook (WeightedTrainer)
├── app/
│ ├── main.py ← FastAPI backend + Lexical Booster
│ ├── model_loader.py ← Singleton model loader (thread-safe)
│ ├── schemas.py ← Pydantic request/response models
│ └── demo.py ← Gradio UI (standalone OR API-backed)
├── spaces/
│ ├── app.py ← HuggingFace Spaces entry point
│ └── requirements.txt
├── requirements.txt ← API/demo dependencies
├── requirements_training.txt ← Training dependencies (Colab)
├── setup_local.bat ← Windows one-click environment setup
└── README.md
# Option A: one-click setup
setup_local.bat
# Option B: manual
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt
Set your .env file:
HF_TOKEN=your_token_here
MODEL_NAME=Pommu/threat-detection-jigsaw
# Terminal 1 — Start the FastAPI backend
uvicorn app.main:app --reload
# Terminal 2 — Launch the Gradio demo
python app/demo.py
Open http://localhost:7860 to see the UI.
notebook/train_3.ipynb in Google ColabHF_Token to Colab Secrets (🔑 icon)MODEL_NAME = Pommu/threat-detection-jigsawspaces/ contents to the Space repo| Component | Technology |
|---|---|
| Model | roberta-base (HuggingFace Transformers) |
| Training | HuggingFace Trainer API + WeightedTrainer (custom) |
| Dataset | google/jigsaw_toxicity_pred (150K samples, 6 labels) |
| Backend API | FastAPI + Uvicorn |
| UI | Gradio |
| Deployment | HuggingFace Spaces |
| Evaluation | scikit-learn (Precision/Recall/F1/Confusion Matrix) |