Text Classification
Transformers
Safetensors
qwen3
content-safety
prompt-injection
multi-label-classification
safety
multilingual
hikmaai
Instructions to use HikmaAI/HikmaGuard with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use HikmaAI/HikmaGuard with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="HikmaAI/HikmaGuard")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("HikmaAI/HikmaGuard") model = AutoModelForSequenceClassification.from_pretrained("HikmaAI/HikmaGuard", device_map="auto") - Notebooks
- Google Colab
- Kaggle
File size: 4,416 Bytes
6604218 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | ---
language:
- en
- vi
- hi
- th
- zh
- ja
- ru
- ar
- sv
- es
- it
library_name: transformers
pipeline_tag: text-classification
base_model:
- Qwen/Qwen3Guard-Gen-4B
tags:
- content-safety
- prompt-injection
- multi-label-classification
- safety
- multilingual
- qwen3
- hikmaai
license: apache-2.0
---
# HikmaGuard
HikmaGuard is a multilingual AI safety model built on
[Qwen/Qwen3Guard-Gen-4B](https://huggingface.co/Qwen/Qwen3Guard-Gen-4B) by
[HikmaAI](https://huggingface.co/HikmaAI). It identifies content-safety risks and
prompt-injection attempts across user prompts, documents, emails, tool outputs, and
other untrusted content.
Nine specialized safety signals with calibrated confidence scores make HikmaGuard a
flexible foundation for moderation, guardrails, and policy enforcement in multilingual
AI applications.
## Model description
- **Version**: 0.1.0
- **Base model**: `Qwen/Qwen3Guard-Gen-4B`
- **Architecture**: `Qwen3ForSequenceClassification`
- **Maximum length**: 2048 tokens with head-tail truncation
- **Input kinds**: `user_prompt`, `external_content`
- **Fine-tuning**: LoRA rank 16, merged into BF16 weights
- **Policy/taxonomy**: `unified-guard-v1`
The independent heads are:
`hate`, `abuse`, `violence`, `self_harm`, `sexual_harm`, `misconduct`,
`dangerous_capability`, `prompt_injection`, and `indirect_prompt_injection`.
Applications can combine these specialized signals according to their own safety policy,
risk tolerance, and enforcement workflow.
## Calibrated thresholds
| Head | Threshold |
|---|---:|
| hate | 0.151028 |
| abuse | 0.321673 |
| violence | 0.576542 |
| self_harm | 0.143188 |
| sexual_harm | 0.191933 |
| misconduct | 0.774583 |
| dangerous_capability | 0.754915 |
| prompt_injection | 0.980000 |
| indirect_prompt_injection | 0.992000 |
The thresholds in `thresholds.json` are bound to this model by both the model-config
SHA-256 and the `hikma_artifact_id`, making deployments reproducible and easy to audit.
## Usage
```python
import json
import torch
from huggingface_hub import hf_hub_download
from transformers import AutoModelForSequenceClassification, AutoTokenizer
repo_id = "HikmaAI/HikmaGuard"
heads = ['hate', 'abuse', 'violence', 'self_harm', 'sexual_harm', 'misconduct', 'dangerous_capability', 'prompt_injection', 'indirect_prompt_injection']
input_kind = "user_prompt" # or "external_content"
text = "Example text to classify"
tokenizer = AutoTokenizer.from_pretrained(repo_id)
model = AutoModelForSequenceClassification.from_pretrained(
repo_id,
torch_dtype=torch.bfloat16,
device_map="auto",
).eval()
messages = [{
"role": "user",
"content": (
f"Source: {input_kind}\n"
"<BEGIN_UNTRUSTED_CONTENT>\n"
f"{text}\n"
"<END_UNTRUSTED_CONTENT>"
),
}]
formatted = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=False,
)
encoded = tokenizer(formatted, truncation=False, padding=False)
for key, sequence in encoded.items():
if len(sequence) > 2048:
encoded[key] = (
sequence[:1024]
+ sequence[-1024:]
)
inputs = tokenizer.pad(encoded, padding=True, return_tensors="pt").to(model.device)
with torch.no_grad():
scores = torch.sigmoid(model(**inputs).logits)[0].float().cpu().tolist()
thresholds = json.load(open(hf_hub_download(repo_id, "thresholds.json")))
result = {
head: {
"score": score,
"detected": score >= thresholds["heads"][head]["threshold"],
}
for head, score in zip(heads, scores)
}
```
For batched inference, apply head-tail truncation to each sequence before padding.
Content-safety and direct-injection inputs use `user_prompt`; untrusted documents or
tool output use `external_content`.
## Training and evaluation notes
- Training used a deterministic 100,000-record multilingual coreset with partial-label
masking across content safety, direct prompt injection, and indirect prompt injection.
- Specialized supervision preserves the distinction between content safety, direct prompt
injection, and indirect prompt injection.
- This version is optimized for user prompts and untrusted external content.
## License
Apache-2.0. See `LICENSE`.
## Citation
```bibtex
@misc{hikmaai-hikmaguard-2026,
title={HikmaGuard},
author={HikmaAI},
year={2026},
publisher={Hugging Face},
url={https://huggingface.co/HikmaAI/HikmaGuard}
}
```
|