Views
No views yet
darelphilip/hinglish-toxicity-classifier)🚀 Live Interactive Demo: Test this model in real-time on Hugging Face Spaces.
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.darelphilip)XLMRobertaForSequenceClassification)en), Hindi (hi)l3cube-pune/hing-robertamodel.safetensors, ~1.11 GB)darelphilip/hinglish-toxicity-classifierdarelphilip/hinglish_toxicity0.5 sigmoid threshold across all classes. For production moderation:threshold = 0.50 - 0.60 (balances precision).threshold = 0.20 - 0.35 (maximizes recall).1import torch
2from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
4MODEL_ID = "darelphilip/hinglish-toxicity-classifier"
5
6# Load tokenizer and model
7tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
8model = AutoModelForSequenceClassification.from_pretrained(MODEL_ID)
9model.eval()
10
11# Move to GPU if available
12device = "cuda" if torch.cuda.is_available() else "cpu"
13model.to(device)
14
15id2label = model.config.id2label
16
17# Input Hinglish texts
18texts = [
19 "Bhai tu pagal hai kya, yeh kya bakwas hai?",
20 "Have a wonderful day everyone!",
21 "Chup kar bilkul bakwaas mat kar yahan"
22]
23
24inputs = tokenizer(
25 texts,
26 padding=True,
27 truncation=True,
28 max_length=128,
29 return_tensors="pt"
30)
31inputs = {k: v.to(device) for k, v in inputs.items()}
32
33with torch.no_grad():
34 logits = model(**inputs).logits
35 probabilities = torch.sigmoid(logits).cpu()
36
37# Evaluate against a custom threshold
38threshold = 0.50
39predictions = (probabilities > threshold).int()
40
41for text, probs, preds in zip(texts, probabilities, predictions):
42 print(f"\n📝 Sentence: \"{text}\"")
43 for idx, (prob, pred) in enumerate(zip(probs, preds)):
44 label = id2label[idx]
45 status = "🚨 FLAGGED" if pred == 1 else "✅ CLEAN"
46 print(f" {label:<25} -> {status} (prob: {prob:.4f})")1from transformers import pipeline
2
3classifier = pipeline(
4 "text-classification",
5 model="darelphilip/hinglish-toxicity-classifier",
6 top_k=None
7)
8
9results = classifier("Bhai tu kitna bekaar insaan hai")
10print(results)BCEWithLogitsLoss using positive class weighting vectors (pos_weight) to penalize false negatives on rare, severe categories.EarlyStoppingCallback(patience=1) monitoring validation Macro F1 (load_best_model_at_end=True). Best weights automatically restored from Epoch 1.l3cube-pune/hing-roberta (278M parameters)| 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 |