darelphilip's picture
Update README.md
0c069e6 verified
|
Raw
History Blame Contribute Delete
8.18 kB
---
library_name: transformers
tags:
- text-classification
- multi-label-classification
- toxicity
- content-moderation
- hinglish
- code-mixed
- indic-nlp
language:
- hi
- en
base_model: l3cube-pune/hing-roberta
license: mit
pipeline_tag: text-classification
metrics:
- f1
- precision
- recall
- loss
---
# Hinglish Toxicity Classifier (`darelphilip/hinglish-toxicity-classifier`)
A fine-tuned multi-label text classification model engineered to detect toxicity, profanity, harassment, and identity-targeted hate speech in Romanized Hindi-English (Hinglish) code-mixed text.
> 🚀 **Live Interactive Demo:** Test this model in real-time on [Hugging Face Spaces](https://huggingface.co/spaces/darelphilip/hinglish_toxicity).
---
## Model Details
### Model Description
This model is fine-tuned from [`l3cube-pune/hing-roberta`](https://huggingface.co/l3cube-pune/hing-roberta) across **116,000+ Romanized Hinglish conversational comments**. It is built for multi-label classification using a weighted Binary Cross-Entropy loss function (`pos_weight`) to counter class imbalance between high-frequency casual profanity and low-frequency targeted hate speech.
- **Developed by:** Darel Philip (`darelphilip`)
- **Contact / Author Email:** [enigmaticdarel@gmail.com](mailto:enigmaticdarel@gmail.com)
- **Model Type:** Transformer-based Multi-Label Sequence Classification (`XLMRobertaForSequenceClassification`)
- **Language(s) (NLP):** Hinglish (Romanized Hindi-English code-mixed), English (`en`), Hindi (`hi`)
- **License:** MIT
- **Finetuned from Model:** [`l3cube-pune/hing-roberta`](https://huggingface.co/l3cube-pune/hing-roberta)
- **Model Serialization:** Safetensors (`model.safetensors`, ~1.11 GB)
### Model Sources & Links
- **Model Repository:** [`darelphilip/hinglish-toxicity-classifier`](https://huggingface.co/darelphilip/hinglish-toxicity-classifier)
- **Live Interactive Space:** [`darelphilip/hinglish_toxicity`](https://huggingface.co/spaces/darelphilip/hinglish_toxicity)
- **Base Architecture:** XLM-RoBERTa (Trained on L3Cube-HingCorpus)
---
## Uses
### Direct Use
- **Automated Content Moderation:** Scanning forum posts, comment feeds, and social platforms for Romanized Hinglish abuse.
- **Toxicity Auditing:** Batch-processing historical comment archives to measure community health and identify moderation trends.
- **Community Bot Filters:** Serving as a backend decision engine for custom moderation bots and automated rule queues.
### Downstream Use & Hybrid Pipelines
Because encoder models evaluate all tokens simultaneously, strong positive words (*mast*, *accha*, *pyaar*) can sometimes mask targeted slurs in sarcastic sentences. In production, this model is designed to work within a **two-stage hybrid architecture**:
1. **Stage 1 (Deterministic Fast Path):** A strict Regex/keyword dictionary immediately catches zero-tolerance identity slurs.
2. **Stage 2 (Statistical Context Path):** This transformer model classifies contextual toxicity, mild abuse, and implicit harassment.
3. **Stage 3 (Escalation / Review):** Ambiguous borderline cases can be escalated to human moderators or routed to a larger reasoning LLM.
### Out-of-Scope Use
- Autonomous execution of permanent account bans or legal enforcement without human review.
- Monolingual Devanagari Hindi or standard formal English (optimized specifically for Roman/Latin script code-mixed text).
- Complex multi-sentence narrative satire where toxicity relies exclusively on long-range external world context.
---
## Bias, Risks, and Limitations
- **Sarcasm & Positive Token Masking:** Sarcastic or passive-aggressive insults wrapped in affectionate language may produce lower probability scores.
- **Spelling & Phonetic Variations:** Romanized Hinglish lacks standardized spelling (e.g., *pyaar* vs. *pyar*, *bhai* vs. *bhaii*). Extreme misspellings can affect subword tokenization.
- **Class Frequency Skew:** Severe identity-targeted categories have significantly fewer positive training instances than casual slang, requiring custom per-class thresholding.
### Recommended Threshold Strategy
Do not rely on a static `0.5` sigmoid threshold across all classes. For production moderation:
- **Casual Profanity / Insults:** `threshold = 0.50 - 0.60` (balances precision).
- **Severe Identity Slurs / Targeted Hate:** `threshold = 0.20 - 0.35` (maximizes recall).
---
## How to Get Started with the Model
### Multi-Label Batch Inference (PyTorch)
```python
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
MODEL_ID = "darelphilip/hinglish-toxicity-classifier"
# Load tokenizer and model
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
model = AutoModelForSequenceClassification.from_pretrained(MODEL_ID)
model.eval()
# Move to GPU if available
device = "cuda" if torch.cuda.is_available() else "cpu"
model.to(device)
id2label = model.config.id2label
# Input Hinglish texts
texts = [
"Bhai tu pagal hai kya, yeh kya bakwas hai?",
"Have a wonderful day everyone!",
"Chup kar bilkul bakwaas mat kar yahan"
]
inputs = tokenizer(
texts,
padding=True,
truncation=True,
max_length=128,
return_tensors="pt"
)
inputs = {k: v.to(device) for k, v in inputs.items()}
with torch.no_grad():
logits = model(**inputs).logits
probabilities = torch.sigmoid(logits).cpu()
# Evaluate against a custom threshold
threshold = 0.50
predictions = (probabilities > threshold).int()
for text, probs, preds in zip(texts, probabilities, predictions):
print(f"\n📝 Sentence: \"{text}\"")
for idx, (prob, pred) in enumerate(zip(probs, preds)):
label = id2label[idx]
status = "🚨 FLAGGED" if pred == 1 else "✅ CLEAN"
print(f" {label:<25} -> {status} (prob: {prob:.4f})")
```
### High-Level Pipeline Usage
```python
from transformers import pipeline
classifier = pipeline(
"text-classification",
model="darelphilip/hinglish-toxicity-classifier",
top_k=None
)
results = classifier("Bhai tu kitna bekaar insaan hai")
print(results)
```
---
## Training Details
### Training Data
- **Dataset Size:** 116,000+ labeled rows.
- **Domain:** Romanized Hinglish conversational comments, code-mixed social media posts, and forum discussions.
- **Labels:** Multi-label schema covering general toxicity, profanity, identity attack, and harassment.
### Training Procedure
- **Loss Function:** `BCEWithLogitsLoss` using positive class weighting vectors (`pos_weight`) to penalize false negatives on rare, severe categories.
- **Early Stopping:** Triggered via `EarlyStoppingCallback(patience=1)` monitoring validation Macro F1 (`load_best_model_at_end=True`). Best weights automatically restored from Epoch 1.
#### Training Hyperparameters
- **Base Architecture:** `l3cube-pune/hing-roberta` (278M parameters)
- **Sequence Length:** 128 tokens
- **Optimizer:** AdamW
- **Epochs Completed:** 2 (Early stopped at best checkpoint: Epoch 1)
- **Batch Size:** Dynamic gradient accumulation configuration
---
## Evaluation
### Validation Set Results
| Metric | Epoch 1 (Best Restored Checkpoint) | Epoch 2 |
| :--- | :--- | :--- |
| **Validation Loss** | **0.944581** | 0.769777 |
| **Macro F1** | **0.556591** | 0.538771 |
| **Micro F1** | **0.654647** | 0.637569 |
| **Precision** | **0.525735** | 0.440160 |
| **Recall** | **0.621775** | 0.739079 |
---
## Technical Specifications
### Compute Infrastructure
- **Training Hardware:** NVIDIA Tesla T4 GPU (Google Colab)
- **System Memory:** ~6.9 GB / 12.7 GB
- **VRAM Utilization:** ~5.9 GB / 15.0 GB
- **Software Stack:** PyTorch, Hugging Face Transformers, Hugging Face Datasets, Accelerate, Gradio
---
## Contact & Community
- **Author / Maintainer:** Darel Philip
- **Email:** [enigmaticdarel@gmail.com](mailto:enigmaticdarel@gmail.com)
- **Hugging Face Profile:** [@darelphilip](https://huggingface.co/darelphilip)
- **Model Card Issues / PRs:** [darelphilip/hinglish-toxicity-classifier/discussions](https://huggingface.co/darelphilip/hinglish-toxicity-classifier/discussions)
- **Web App:** [darelphilip/hinglish_toxicity](https://huggingface.co/spaces/darelphilip/hinglish_toxicity)