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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
- ms
|
| 5 |
+
- zh
|
| 6 |
+
- ta
|
| 7 |
+
license: other
|
| 8 |
+
library_name: transformers
|
| 9 |
+
pipeline_tag: text-generation
|
| 10 |
+
tags:
|
| 11 |
+
- qwen2.5
|
| 12 |
+
- lora
|
| 13 |
+
- malaysia
|
| 14 |
+
- safety
|
| 15 |
+
- moderation
|
| 16 |
+
- rukun-negara
|
| 17 |
+
- multilingual
|
| 18 |
+
base_model: Qwen/Qwen2.5-32B-Instruct
|
| 19 |
+
model-index:
|
| 20 |
+
- name: qwen25-32b-rukun-v1-merged
|
| 21 |
+
results:
|
| 22 |
+
- task:
|
| 23 |
+
type: text-generation
|
| 24 |
+
name: Structured safety validation (Rukun Negara)
|
| 25 |
+
dataset:
|
| 26 |
+
type: custom
|
| 27 |
+
name: benchmark_data (50 labeled prompts)
|
| 28 |
+
metrics:
|
| 29 |
+
- type: accuracy
|
| 30 |
+
value: 0.88
|
| 31 |
+
- type: precision
|
| 32 |
+
value: 0.8333
|
| 33 |
+
name: violating_precision
|
| 34 |
+
- type: recall
|
| 35 |
+
value: 0.9091
|
| 36 |
+
name: violating_recall
|
| 37 |
+
- type: f1
|
| 38 |
+
value: 0.8696
|
| 39 |
+
name: violating_f1
|
| 40 |
+
---
|
| 41 |
+
|
| 42 |
+
# Rukun Ready AI (Qwen2.5-32B v1)
|
| 43 |
+
|
| 44 |
+
Rukun Ready AI is a Malaysia-aligned structured validation model built on `Qwen/Qwen2.5-32B-Instruct` and fine-tuned with LoRA for Rukun Negara policy assessment.
|
| 45 |
+
|
| 46 |
+
It is designed to return strict JSON with principle-level scoring, severity, explanation, and optional rewrite guidance.
|
| 47 |
+
|
| 48 |
+
## Model Summary
|
| 49 |
+
|
| 50 |
+
- Base model: `Qwen/Qwen2.5-32B-Instruct`
|
| 51 |
+
- Fine-tuning method: LoRA (instruction tuning)
|
| 52 |
+
- Primary objective: structured policy validation aligned to Rukun Negara principles
|
| 53 |
+
- Output format: strict JSON contract (machine-readable)
|
| 54 |
+
- Languages: Bahasa Malaysia, English, Mandarin, Tamil, and code-switched input
|
| 55 |
+
|
| 56 |
+
## Rukun Negara Principles Covered
|
| 57 |
+
|
| 58 |
+
1. Belief in God (`belief_in_god`)
|
| 59 |
+
2. Loyalty to King and Country (`loyalty_to_king_country`)
|
| 60 |
+
3. Upholding the Constitution (`constitutional_compliance`)
|
| 61 |
+
4. Rule of Law (`rule_of_law`)
|
| 62 |
+
5. Good Behaviour and Morality (`good_behaviour_morality`)
|
| 63 |
+
|
| 64 |
+
## Training Data
|
| 65 |
+
|
| 66 |
+
v1 dataset used for fine-tuning:
|
| 67 |
+
|
| 68 |
+
- Train: `66,516`
|
| 69 |
+
- Validation: `1,353`
|
| 70 |
+
- Total: `67,869`
|
| 71 |
+
|
| 72 |
+
Files:
|
| 73 |
+
|
| 74 |
+
- `DATASETS/rukun-teacher/v1/train_v1.jsonl`
|
| 75 |
+
- `DATASETS/rukun-teacher/v1/val_v1.jsonl`
|
| 76 |
+
|
| 77 |
+
Data format:
|
| 78 |
+
|
| 79 |
+
- JSONL conversational records with `messages` (`system`, `user`, `assistant`)
|
| 80 |
+
- Assistant targets are strict JSON responses following the schema contract
|
| 81 |
+
|
| 82 |
+
Label/variant coverage (v1):
|
| 83 |
+
|
| 84 |
+
- Severity variants in train:
|
| 85 |
+
- `compliant_0`: 18,674 (28.07%)
|
| 86 |
+
- `minor_1_3`: 3,511 (5.28%)
|
| 87 |
+
- `moderate_4_6`: 19,103 (28.72%)
|
| 88 |
+
- `violating_7_10`: 25,228 (37.93%)
|
| 89 |
+
- Severity variants in val:
|
| 90 |
+
- `compliant_0`: 381 (28.16%)
|
| 91 |
+
- `minor_1_3`: 72 (5.32%)
|
| 92 |
+
- `moderate_4_6`: 387 (28.60%)
|
| 93 |
+
- `violating_7_10`: 513 (37.92%)
|
| 94 |
+
- Rewrite behavior:
|
| 95 |
+
- `rewritten_text = null` for compliant samples
|
| 96 |
+
- `rewritten_text` populated for non-compliant samples
|
| 97 |
+
- train rewrite coverage: 47,842 / 66,516 (71.93%)
|
| 98 |
+
- val rewrite coverage: 972 / 1,353 (71.84%)
|
| 99 |
+
|
| 100 |
+
## Training Procedure
|
| 101 |
+
|
| 102 |
+
Reference configuration and script:
|
| 103 |
+
|
| 104 |
+
- Config: `TRAINING/config_v1_b200_2gpu.yaml`
|
| 105 |
+
- Trainer: `TRAINING/hf_train_v1.py`
|
| 106 |
+
|
| 107 |
+
Key settings:
|
| 108 |
+
|
| 109 |
+
- Max sequence length: `2048`
|
| 110 |
+
- Epochs: `1`
|
| 111 |
+
- Learning rate: `2e-5`
|
| 112 |
+
- Scheduler: cosine
|
| 113 |
+
- Precision: BF16
|
| 114 |
+
- LoRA:
|
| 115 |
+
- `r=32`
|
| 116 |
+
- `alpha=64`
|
| 117 |
+
- `dropout=0.05`
|
| 118 |
+
- target modules: `q_proj`, `k_proj`, `v_proj`, `o_proj`, `gate_proj`, `up_proj`, `down_proj`
|
| 119 |
+
|
| 120 |
+
Loss behavior:
|
| 121 |
+
|
| 122 |
+
- Completion-only masking (loss on assistant tokens only)
|
| 123 |
+
- Goal: maximize output schema stability and policy consistency
|
| 124 |
+
|
| 125 |
+
Approximate trainable adaptation parameters (LoRA):
|
| 126 |
+
|
| 127 |
+
- `~268M` trainable params (`~0.84%` relative to 32B base)
|
| 128 |
+
|
| 129 |
+
## Evaluation Snapshot
|
| 130 |
+
|
| 131 |
+
Internal labeled benchmark (`REPORT/benchmark_data.json`, n=50):
|
| 132 |
+
|
| 133 |
+
- Accuracy: `88.0%`
|
| 134 |
+
- Violating precision: `83.3%`
|
| 135 |
+
- Violating recall: `90.9%`
|
| 136 |
+
- Violating F1: `86.96%`
|
| 137 |
+
|
| 138 |
+
Confusion matrix:
|
| 139 |
+
|
| 140 |
+
- Expected violating -> predicted violating: `20`
|
| 141 |
+
- Expected violating -> predicted compliant: `2`
|
| 142 |
+
- Expected compliant -> predicted violating: `4`
|
| 143 |
+
- Expected compliant -> predicted compliant: `24`
|
| 144 |
+
|
| 145 |
+
## Intended Use
|
| 146 |
+
|
| 147 |
+
Use this model when you need:
|
| 148 |
+
|
| 149 |
+
- structured, machine-readable policy checks
|
| 150 |
+
- principle-level scoring against Rukun Negara
|
| 151 |
+
- multilingual moderation support for Malaysia-centric contexts
|
| 152 |
+
- rewrite guidance for non-compliant text
|
| 153 |
+
|
| 154 |
+
## Out-of-Scope Use
|
| 155 |
+
|
| 156 |
+
Not intended for:
|
| 157 |
+
|
| 158 |
+
- legal adjudication or final legal decisions
|
| 159 |
+
- replacing human moderation in high-stakes enforcement without review
|
| 160 |
+
- generalized truth verification or factual QA
|
| 161 |
+
- medical, legal, or financial decision support
|
| 162 |
+
|
| 163 |
+
## Limitations
|
| 164 |
+
|
| 165 |
+
- Performance is strongest for the target policy schema and may degrade outside this format.
|
| 166 |
+
- Borderline sarcasm, slang, or evolving coded speech can still cause false positives/negatives.
|
| 167 |
+
- Scores are model outputs, not legal determinations.
|
| 168 |
+
- Benchmark size is limited; broader external benchmarking is recommended.
|
| 169 |
+
|
| 170 |
+
## Safety and Bias Notes
|
| 171 |
+
|
| 172 |
+
This model is value-aligned to Malaysian national principles and can reflect the biases and policy assumptions embedded in training data design.
|
| 173 |
+
|
| 174 |
+
Recommended controls:
|
| 175 |
+
|
| 176 |
+
- log and audit all production decisions
|
| 177 |
+
- keep human review for high-severity outcomes
|
| 178 |
+
- evaluate by language/domain slices before broad rollout
|
| 179 |
+
|
| 180 |
+
## Output Contract (Schema)
|
| 181 |
+
|
| 182 |
+
The model is expected to return valid JSON with these keys:
|
| 183 |
+
|
| 184 |
+
- `principles`
|
| 185 |
+
- `belief_in_god` -> `{status, score}`
|
| 186 |
+
- `loyalty_to_king_country` -> `{status, score}`
|
| 187 |
+
- `constitutional_compliance` -> `{status, score}`
|
| 188 |
+
- `rule_of_law` -> `{status, score}`
|
| 189 |
+
- `good_behaviour_morality` -> `{status, score}`
|
| 190 |
+
- `overall` -> `{severity_score, severity_band}`
|
| 191 |
+
- `explanation`
|
| 192 |
+
- `rewritten_text`
|
| 193 |
+
- `violationCount`
|
| 194 |
+
- `severityScore`
|
| 195 |
+
- `isProblematic`
|
| 196 |
+
|
| 197 |
+
Derived rules used in training targets:
|
| 198 |
+
|
| 199 |
+
- `overall.severity_score = max(principle scores)`
|
| 200 |
+
- `violationCount = count(principles where status == "violated")`
|
| 201 |
+
- `severityScore = overall.severity_score`
|
| 202 |
+
- `isProblematic = (violationCount > 0) OR (severityScore > 2)`
|
| 203 |
+
|
| 204 |
+
## Sample Input / Output
|
| 205 |
+
|
| 206 |
+
### Example A (Compliant)
|
| 207 |
+
|
| 208 |
+
Input:
|
| 209 |
+
|
| 210 |
+
```json
|
| 211 |
+
{
|
| 212 |
+
"messages": [
|
| 213 |
+
{
|
| 214 |
+
"role": "system",
|
| 215 |
+
"content": "You are an AI ethics validator for Malaysia's Rukun Negara principles..."
|
| 216 |
+
},
|
| 217 |
+
{
|
| 218 |
+
"role": "user",
|
| 219 |
+
"content": "Saya setuju kita bincang isu ini dengan hormat dan ikut undang-undang."
|
| 220 |
+
}
|
| 221 |
+
]
|
| 222 |
+
}
|
| 223 |
+
```
|
| 224 |
+
|
| 225 |
+
Output:
|
| 226 |
+
|
| 227 |
+
```json
|
| 228 |
+
{
|
| 229 |
+
"principles": {
|
| 230 |
+
"belief_in_god": {"status": "compliant", "score": 0},
|
| 231 |
+
"loyalty_to_king_country": {"status": "compliant", "score": 0},
|
| 232 |
+
"constitutional_compliance": {"status": "compliant", "score": 0},
|
| 233 |
+
"rule_of_law": {"status": "compliant", "score": 0},
|
| 234 |
+
"good_behaviour_morality": {"status": "compliant", "score": 0}
|
| 235 |
+
},
|
| 236 |
+
"overall": {"severity_score": 0, "severity_band": "compliant"},
|
| 237 |
+
"explanation": "Teks ini menggalakkan perbincangan berhemah dan pematuhan undang-undang, jadi ia mematuhi semua prinsip.",
|
| 238 |
+
"rewritten_text": null,
|
| 239 |
+
"violationCount": 0,
|
| 240 |
+
"severityScore": 0,
|
| 241 |
+
"isProblematic": false
|
| 242 |
+
}
|
| 243 |
+
```
|
| 244 |
+
|
| 245 |
+
### Example B (Violating)
|
| 246 |
+
|
| 247 |
+
Input:
|
| 248 |
+
|
| 249 |
+
```json
|
| 250 |
+
{
|
| 251 |
+
"messages": [
|
| 252 |
+
{
|
| 253 |
+
"role": "system",
|
| 254 |
+
"content": "You are an AI ethics validator for Malaysia's Rukun Negara principles..."
|
| 255 |
+
},
|
| 256 |
+
{
|
| 257 |
+
"role": "user",
|
| 258 |
+
"content": "Laws here are useless, we should ignore them."
|
| 259 |
+
}
|
| 260 |
+
]
|
| 261 |
+
}
|
| 262 |
+
```
|
| 263 |
+
|
| 264 |
+
Output:
|
| 265 |
+
|
| 266 |
+
```json
|
| 267 |
+
{
|
| 268 |
+
"principles": {
|
| 269 |
+
"belief_in_god": {"status": "compliant", "score": 0},
|
| 270 |
+
"loyalty_to_king_country": {"status": "violated", "score": 4},
|
| 271 |
+
"constitutional_compliance": {"status": "violated", "score": 7},
|
| 272 |
+
"rule_of_law": {"status": "violated", "score": 8},
|
| 273 |
+
"good_behaviour_morality": {"status": "violated", "score": 6}
|
| 274 |
+
},
|
| 275 |
+
"overall": {"severity_score": 8, "severity_band": "violating"},
|
| 276 |
+
"explanation": "The text explicitly encourages rejecting national law and constitutional order, which is a clear violation.",
|
| 277 |
+
"rewritten_text": "I disagree with some policies, but we should still follow Malaysian law and use legal channels for change.",
|
| 278 |
+
"violationCount": 4,
|
| 279 |
+
"severityScore": 8,
|
| 280 |
+
"isProblematic": true
|
| 281 |
+
}
|
| 282 |
+
```
|
| 283 |
+
|
| 284 |
+
## Usage (Transformers)
|
| 285 |
+
|
| 286 |
+
```python
|
| 287 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 288 |
+
import torch
|
| 289 |
+
|
| 290 |
+
model_id = "Entermind/qwen25-32b-rukun-v1-merged"
|
| 291 |
+
|
| 292 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 293 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 294 |
+
model_id,
|
| 295 |
+
torch_dtype=torch.bfloat16,
|
| 296 |
+
device_map="auto"
|
| 297 |
+
)
|
| 298 |
+
|
| 299 |
+
system_prompt = "You are an AI ethics validator for Malaysia's Rukun Negara principles..."
|
| 300 |
+
user_text = "Your input text here"
|
| 301 |
+
|
| 302 |
+
messages = [
|
| 303 |
+
{"role": "system", "content": system_prompt},
|
| 304 |
+
{"role": "user", "content": user_text},
|
| 305 |
+
]
|
| 306 |
+
|
| 307 |
+
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 308 |
+
inputs = tokenizer(text, return_tensors="pt").to(model.device)
|
| 309 |
+
|
| 310 |
+
with torch.no_grad():
|
| 311 |
+
output = model.generate(
|
| 312 |
+
**inputs,
|
| 313 |
+
max_new_tokens=512,
|
| 314 |
+
temperature=0.0,
|
| 315 |
+
top_p=1.0,
|
| 316 |
+
do_sample=False,
|
| 317 |
+
)
|
| 318 |
+
|
| 319 |
+
print(tokenizer.decode(output[0], skip_special_tokens=True))
|
| 320 |
+
```
|
| 321 |
+
|
| 322 |
+
## Usage (vLLM/OpenAI-compatible)
|
| 323 |
+
|
| 324 |
+
For deterministic structured outputs in vLLM, use:
|
| 325 |
+
|
| 326 |
+
- `temperature=0`
|
| 327 |
+
- `top_p=1`
|
| 328 |
+
- bounded `max_tokens` (typically `256-512`)
|
| 329 |
+
- stable, identical system prompt for better prefix-cache hit rates
|
| 330 |
+
|
| 331 |
+
If model generation defaults are being auto-applied, launch vLLM with:
|
| 332 |
+
|
| 333 |
+
- `--generation-config vllm`
|
| 334 |
+
|
| 335 |
+
## License and Terms
|
| 336 |
+
|
| 337 |
+
This release is provided as open weights. Ensure compliance with:
|
| 338 |
+
|
| 339 |
+
1. Base model license (`Qwen2.5-32B-Instruct`)
|
| 340 |
+
2. Repository-level terms for this model
|
| 341 |
+
3. Applicable local laws and platform policy requirements
|
| 342 |
+
|
| 343 |
+
## Contact
|
| 344 |
+
|
| 345 |
+
- Project site: `https://rukunnegara.ai`
|
| 346 |
+
- Organization: Entermind
|
| 347 |
+
|
| 348 |
+
## Citation
|
| 349 |
+
|
| 350 |
+
If you use this model, cite this repository and include the version tag used in your experiments.
|