google/civil_comments
Viewer • Updated • 2M • 22.8k • 32
How to use navodPeiris/minilm-toxic-spam-classifier with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-classification", model="navodPeiris/minilm-toxic-spam-classifier") # Load model directly
from transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("navodPeiris/minilm-toxic-spam-classifier")
model = AutoModelForSequenceClassification.from_pretrained("navodPeiris/minilm-toxic-spam-classifier")A lightweight content moderation model that classifies text into safe, toxic, or spam. Built on MiniLMv2-L6-H384 and fine-tuned with focal loss for robust handling of hard examples. This model is in ONNX format and optimized for CPU inference.
| Label ID | Label | Description |
|---|---|---|
| 0 | safe |
Normal, non-harmful content |
| 1 | toxic |
Hate speech, threats, personal attacks, severe insults |
| 2 | spam |
Unsolicited promotions, scams, phishing attempts |
from optimum.onnxruntime import ORTModelForSequenceClassification
from transformers import AutoTokenizer, AutoConfig
import torch
model_name = "navodPeiris/minilm-toxic-spam-classifier"
tokenizer = AutoTokenizer.from_pretrained(model_name)
config = AutoConfig.from_pretrained(model_name)
model = ORTModelForSequenceClassification.from_pretrained(model_name)
text = "look like garbage!"
inputs = tokenizer(text, return_tensors="pt")
outputs = model(**inputs)
# Convert logits → probabilities
probs = torch.softmax(outputs.logits, dim=-1)
# Get predicted class
pred_id = torch.argmax(probs, dim=-1).item()
label = config.id2label[pred_id]
confidence = probs[0][pred_id].item()
print(label, f"{confidence}")
import { pipeline } from "@huggingface/transformers";
const pipe = await pipeline(
"text-classification",
"navodPeiris/minilm-toxic-spam-classifier",
);
const res = await pipe("this code is uglier than u ugghh");
console.log("res:", res);
Evaluated on a held-out test set of 13,123 samples:
precision recall f1-score support
safe 0.98 0.96 0.97 4332
toxic 0.90 0.96 0.93 1626
spam 0.99 0.97 0.98 1157
accuracy 0.96 7115
macro avg 0.95 0.96 0.96 7115
weighted avg 0.96 0.96 0.96 7115
The model was trained on a combined dataset from multiple sources:
| Source | Type | Usage |
|---|---|---|
| Jigsaw Toxic Comments | Toxicity | safe / toxic labels |
| Civil Comments | Toxicity | safe / toxic labels |
| Mail Spam/Ham | Spam | spam labels |
| Enron Spam | Spam | spam labels |
An ONNX version of the model is included for fast CPU inference:
Apache 2.0