A LoRA-finetuned multilingual BERT model for binary content safety classification (safe/unsafe), following the MLCommons AI Safety Hazard Taxonomy.
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2from peft import PeftModel
3
4# Load base model and tokenizer
5base_model = "jhu-clsp/mmBERT-base"
6tokenizer = AutoTokenizer.from_pretrained("llm-semantic-router/mlcommons-safety-classifier-level1-binary")
7model = AutoModelForSequenceClassification.from_pretrained(base_model, num_labels=2)
8model = PeftModel.from_pretrained(model, "llm-semantic-router/mlcommons-safety-classifier-level1-binary")
9
10# Classify
11text = "How do I make a cake?"
12inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512)
13outputs = model(**inputs)
14prediction = outputs.logits.argmax(-1).item()
15label = "safe" if prediction == 0 else "unsafe"
16print(f"Classification: {label}")
1{
2 "safe": 0,
3 "unsafe": 1
4}
1@misc{mlcommons-safety-classifier,
2 title={MLCommons AI Safety Classifier},
3 author={LLM Semantic Router Team},
4 year={2026},
5 publisher={Hugging Face},
6 url={https://huggingface.co/llm-semantic-router/mlcommons-safety-classifier-level1-binary}
7}