Run this model with HF Jobs
Run MostafaMaroof/sanadguard-322m on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/MostafaMaroof/sanadguard-322m. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/MostafaMaroof/sanadguard-322m on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use MostafaMaroof/sanadguard-322m with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Laya
How to use MostafaMaroof/sanadguard-322m with Laya:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
SanadGuard-322M
Arabic–English safety classification · 322M parameters · v2
SanadGuard checks whether an assistant's response contains harmful content. It returns a harm decision and a score without generating text, in about 35 ms on a T4. It also includes question definitions for prompt harm and response refusal.
What's new in v2: trained on 65K Arabic–English pairs with soft labels from
Qwen3Guard-Gen-4B, plus mined hard negatives. On Arabic, harmful-response F1 rose from 72.2 to 80.1,
and false alarms on safe responses fell from 41.9% to 10.6%.
v1 is still available with revision="v1".
Quick start
pip install "laya @ https://github.com/NandhaKishorM/laya/archive/4066d5d5fbf08b66c6757ddeedbd797bd7655bc0.zip" "transformers==4.57.6" "huggingface_hub==0.36.2"
import sys
from pathlib import Path
from huggingface_hub import snapshot_download
model_dir = Path(snapshot_download("MostafaMaroof/sanadguard-322m")) # revision="v1" for the old model
sys.path.insert(0, str(model_dir))
from predict_guard import Guard
guard = Guard(model_dir, device="cpu") # "cuda" for GPU
result = guard.predict(
prompt="How can I protect my account?",
response="Use a unique password and enable two-factor authentication.",
)
print(result["response_harm"], result["probability_yes"])
The helper applies the saved 0.549 threshold automatically (deployment_policy.json).
It was chosen on Nemotron validation data to keep false alarms near 10%, never on test data.
For higher recall, use 0.3253 (best validation F1). Arabic test results at that threshold: F1 80.8, recall 87.6, false-positive rate 17.4%.
Performance
Harmful-response detection on 3,223 held-out pairs:
- Fresh PolyGuardPrompts: test rows that v1's benchmark did not use.
- NVIDIA Nemotron Safety Guard v3: the test split.
None of these prompts were used in training or threshold selection. Bracketed values are 95% bootstrap intervals.
Arabic (1,864 pairs, 699 harmful)
| Model | F1 | AUPRC | Recall | Precision | False-positive rate | T4 latency |
|---|---|---|---|---|---|---|
| SanadGuard v2 | 80.1 [77.6, 82.4] | 87.7 [85.4, 89.9] | 78.5 | 81.7 | 10.6% | 35 ms |
| SanadGuard v1 | 72.2 [69.8, 74.4] | 79.8 [76.6, 82.9] | 95.9 | 57.9 | 41.9% | 39 ms |
| PolyGuard-Qwen-Smol | 77.8 [75.1, 80.1] | 81.4 [77.9, 84.6] | 77.0 | 78.7 | 12.5% | 832 ms |
| Qwen3Guard-Gen-0.6B | 81.5 [79.2, 83.8] | 89.5 [87.4, 91.4] | 82.8 | 80.3 | 12.2% | 652 ms |
English (1,359 pairs, 411 harmful)
| Model | F1 | AUPRC | Recall | Precision | False-positive rate |
|---|---|---|---|---|---|
| SanadGuard v2 | 78.2 [75.2, 81.3] | 88.2 [85.6, 90.6] | 78.6 | 77.8 | 9.7% |
| SanadGuard v1 | 70.7 [67.7, 73.7] | 81.1 [77.4, 84.3] | 93.2 | 56.9 | 30.6% |
| PolyGuard-Qwen-Smol | 80.6 [77.7, 83.3] | 82.6 [78.6, 86.2] | 86.9 | 75.2 | 12.4% |
| Qwen3Guard-Gen-0.6B | 82.6 [79.9, 85.4] | 89.8 [87.2, 92.2] | 88.3 | 77.6 | 11.1% |
On Arabic, v2 is statistically tied with Qwen3Guard-Gen-0.6B on F1: the difference is −1.5, with a 95% interval of [−3.7, +0.8]. It runs about 19× faster. v2 is significantly better than v1 on every test slice except the small hand-written set. On Arabic, v2 is also significantly better than PolyGuard-Smol on AUPRC. Latency is one response-harm decision, measured on a Tesla T4. The generative baselines use fp16 and a cached system prompt. Full results.
Usage notes
- Weakest slice: fresh PolyGuard Arabic, with F1 67.5 against Qwen3Guard-0.6B's 74.0. English is weaker than Arabic at the shipped threshold.
- Dialects: a small hand-written set covers Egyptian, Gulf, Levantine and Maghrebi Arabic, Arabizi and code-switching (28 pairs, 10 harmful). v2 catches 8 of 10 harmful responses with no false alarms. This set is too small for firm conclusions.
- Input limit: the helper rejects inputs over the trained 1,024-token budget.
- Use: as a fast first-pass filter. For high-stakes moderation, send uncertain scores to a larger guard model or human review.
- New data: performance can differ on new domains.
Credits
Based on Laya multilingual. Training uses PolyGuardMix and NVIDIA Nemotron Safety Guard data. Soft labels come from Qwen3Guard-Gen-4B (Apache-2.0). Model license: Apache-2.0. Dataset attribution, source revisions and training settings are in TRAINING.md.
- Downloads last month
- 22
Model tree for MostafaMaroof/sanadguard-322m
Base model
convaiinnovations/laya-multilingual