A 9-class hazard classifier aligned with MLCommons AI Safety taxonomy. Part of a hierarchical safety classification system.
Model Description
This is
Level 2
of a 2-level hierarchical safety classifier:
Level 1
: Binary classification (safe/unsafe) - for initial filtering
Level 2 (this model)
: 9-class hazard taxonomy - for categorizing the type of unsafe content
Performance
Metric
Score
Accuracy
91.5%
F1 Macro
91.3%
F1 Weighted
91.3%
MLCommons-Aligned Labels
ID
Label
MLCommons Category
Description
0
S1_violent_crimes
S1
Murder, assault, terrorism
1
S2_nonviolent_crimes
S2
Theft, fraud, trafficking
2
S3_sex_crimes
S3, S4, S12
Sexual exploitation, CSE, adult content
3
S5_weapons_cbrne
S5
Chemical, biological, nuclear, explosives
4
S6_self_harm
S6
Suicide, self-injury, eating disorders
5
S7_hate
S7, S11
Hate speech, harassment, discrimination
6
S8_specialized_advice
S8
Medical, legal, financial advice
7
S9_privacy
S9
PII, doxing, surveillance
8
S13_misinformation
S13
Elections, conspiracy, false info
Training Hyperparameters
Parameter
Value
Base Model
jhu-clsp/mmBERT-base
LoRA Rank
32
LoRA Alpha
64
LoRA Dropout
0.1
Learning Rate
5e-5
Epochs
10
Batch Size
64
Max Samples
18,000
Training Samples
12,614
Validation Samples
2,700
Classes
9
Samples per Class
~2,000 (balanced via oversampling)
Usage
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
from peft import PeftModel
# Load model
tokenizer = AutoTokenizer.from_pretrained("llm-semantic-router/mmbert-safety-classifier-level2")
base_model = AutoModelForSequenceClassification.from_pretrained(
"jhu-clsp/mmBERT-base",
num_labels=9,
torch_dtype=torch.float32
)
model = PeftModel.from_pretrained(base_model, "llm-semantic-router/mmbert-safety-classifier-level2")
model.eval()
# Inference (use only after Level 1 predicts "unsafe")
text = "How to hack into someone's bank account"
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512)
with torch.no_grad():
outputs = model(**inputs)
pred = outputs.logits.argmax(-1).item()
conf = torch.softmax(outputs.logits, dim=-1)[0][pred].item()
labels = {
0: "S1_violent_crimes",
1: "S2_nonviolent_crimes",
2: "S3_sex_crimes",
3: "S5_weapons_cbrne",
4: "S6_self_harm",
5: "S7_hate",
6: "S8_specialized_advice",
7: "S9_privacy",
8: "S13_misinformation"
}
print(f"Hazard Category: {labels[pred]} ({conf:.2%})")
Hierarchical Classification Pipeline
Use with Level 1 for complete safety classification:
# Step 1: Run Level 1 to check if content is unsafe
level1_pred = run_level1(text) # Returns 0=safe, 1=unsafe# Step 2: If unsafe, run Level 2 for hazard categoryif level1_pred == 1:
hazard_category = run_level2(text)
print(f"Content is unsafe: {hazard_category}")
else:
print("Content is safe")
mmbert-safety-classifier-level2 huggingface.co is an AI model on huggingface.co that provides mmbert-safety-classifier-level2's model effect (), which can be used instantly with this llm-semantic-router mmbert-safety-classifier-level2 model. huggingface.co supports a free trial of the mmbert-safety-classifier-level2 model, and also provides paid use of the mmbert-safety-classifier-level2. Support call mmbert-safety-classifier-level2 model through api, including Node.js, Python, http.
mmbert-safety-classifier-level2 huggingface.co is an online trial and call api platform, which integrates mmbert-safety-classifier-level2's modeling effects, including api services, and provides a free online trial of mmbert-safety-classifier-level2, you can try mmbert-safety-classifier-level2 online for free by clicking the link below.
llm-semantic-router mmbert-safety-classifier-level2 online free url in huggingface.co:
mmbert-safety-classifier-level2 is an open source model from GitHub that offers a free installation service, and any user can find mmbert-safety-classifier-level2 on GitHub to install. At the same time, huggingface.co provides the effect of mmbert-safety-classifier-level2 install, users can directly use mmbert-safety-classifier-level2 installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
mmbert-safety-classifier-level2 install url in huggingface.co: