File size: 9,277 Bytes
a561e4b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50c7aa0
a561e4b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
961cd5b
a561e4b
 
 
 
 
50c7aa0
 
 
 
 
a561e4b
 
 
 
 
 
88d07ff
a561e4b
 
 
 
 
 
 
 
 
 
 
 
 
 
961cd5b
a561e4b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88d07ff
a561e4b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88d07ff
a561e4b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50c7aa0
a561e4b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88d07ff
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
---
language:
- en
- ms
license: other
library_name: transformers
pipeline_tag: text-generation
tags:
- qwen2.5
- lora
- malaysia
- safety
- moderation
- rukun-negara
- multilingual
base_model: Qwen/Qwen2.5-32B-Instruct
model-index:
- name: EntermindAI/Rukun-32B-v1.5
  results:
  - task:
      type: text-generation
      name: Structured safety validation (Rukun Negara)
    dataset:
      type: custom
      name: benchmark_data (50 labeled prompts)
    metrics:
    - type: accuracy
      value: 0.88
    - type: precision
      value: 0.8333
      name: violating_precision
    - type: recall
      value: 0.9091
      name: violating_recall
    - type: f1
      value: 0.8696
      name: violating_f1
---

# Rukun Ready AI (Rukun-32B-v1.5)

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.

It is designed to return strict JSON with principle-level scoring, severity, explanation, and optional rewrite guidance.

Versioning:

- Public release: `v1.5` (first public release)
- Internal training lineage: `v5`

## Model Summary

- Base model: `Qwen/Qwen2.5-32B-Instruct`
- Fine-tuning method: LoRA (instruction tuning)
- Primary objective: structured policy validation aligned to Rukun Negara principles
- Output format: strict JSON contract (machine-readable)
- Languages: Bahasa Malaysia, English, and code-switched input

## Rukun Negara Principles Covered

1. Belief in God (`belief_in_god`)
2. Loyalty to King and Country (`loyalty_to_king_country`)
3. Upholding the Constitution (`constitutional_compliance`)
4. Rule of Law (`rule_of_law`)
5. Good Behaviour and Morality (`good_behaviour_morality`)

## Training Data

v1 dataset used for fine-tuning:

- Train: `66,516`
- Validation: `23,353`
- Total: `67,869`

Files:

- `DATASETS/rukun-teacher/v1/train_v1.jsonl`
- `DATASETS/rukun-teacher/v1/val_v1.jsonl`

Data format:

- JSONL conversational records with `messages` (`system`, `user`, `assistant`)
- Assistant targets are strict JSON responses following the schema contract

Label/variant coverage (v1):

- Severity variants in train:
  - `compliant_0`: 18,674 (28.07%)
  - `minor_1_3`: 3,511 (5.28%)
  - `moderate_4_6`: 19,103 (28.72%)
  - `violating_7_10`: 25,228 (37.93%)
- Severity variants in val:
  - `compliant_0`: 381 (28.16%)
  - `minor_1_3`: 72 (5.32%)
  - `moderate_4_6`: 387 (28.60%)
  - `violating_7_10`: 513 (37.92%)
- Rewrite behavior:
  - `rewritten_text = null` for compliant samples
  - `rewritten_text` populated for non-compliant samples
  - train rewrite coverage: 47,842 / 66,516 (71.93%)
  - val rewrite coverage: 972 / 1,353 (71.84%)

## Training Procedure

Reference configuration and script:

- Config: `TRAINING/config_v1_b200_2gpu.yaml`
- Trainer: `TRAINING/hf_train_v1.py`

Key settings:

- Max sequence length: `2048`
- Epochs: `1`
- Learning rate: `2e-5`
- Scheduler: cosine
- Precision: BF16
- LoRA:
  - `r=32`
  - `alpha=64`
  - `dropout=0.05`
  - target modules: `q_proj`, `k_proj`, `v_proj`, `o_proj`, `gate_proj`, `up_proj`, `down_proj`

Loss behavior:

- Completion-only masking (loss on assistant tokens only)
- Goal: maximize output schema stability and policy consistency

Approximate trainable adaptation parameters (LoRA):

- `~268M` trainable params (`~0.84%` relative to 32B base)

## Evaluation Snapshot

Internal labeled benchmark (`REPORT/benchmark_data.json`, n=50):

- Accuracy: `88.0%`
- Violating precision: `83.3%`
- Violating recall: `90.9%`
- Violating F1: `86.96%`

Confusion matrix:

- Expected violating -> predicted violating: `20`
- Expected violating -> predicted compliant: `2`
- Expected compliant -> predicted violating: `4`
- Expected compliant -> predicted compliant: `24`

## Intended Use

Use this model when you need:

- structured, machine-readable policy checks
- principle-level scoring against Rukun Negara
- multilingual moderation support for Malaysia-centric contexts
- rewrite guidance for non-compliant text

## Out-of-Scope Use

Not intended for:

- legal adjudication or final legal decisions
- replacing human moderation in high-stakes enforcement without review
- generalized truth verification or factual QA
- medical, legal, or financial decision support

## Limitations

- Performance is strongest for the target policy schema and may degrade outside this format.
- Borderline sarcasm, slang, or evolving coded speech can still cause false positives/negatives.
- Scores are model outputs, not legal determinations.
- Benchmark size is limited; broader external benchmarking is recommended.

## Safety and Bias Notes

This model is value-aligned to Malaysian national principles and can reflect the biases and policy assumptions embedded in training data design.

Recommended controls:

- log and audit all production decisions
- keep human review for high-severity outcomes
- evaluate by language/domain slices before broad rollout

## Output Contract (Schema)

The model is expected to return valid JSON with these keys:

- `principles`
  - `belief_in_god` -> `{status, score}`
  - `loyalty_to_king_country` -> `{status, score}`
  - `constitutional_compliance` -> `{status, score}`
  - `rule_of_law` -> `{status, score}`
  - `good_behaviour_morality` -> `{status, score}`
- `overall` -> `{severity_score, severity_band}`
- `explanation`
- `rewritten_text`
- `violationCount`
- `severityScore`
- `isProblematic`

Derived rules used in training targets:

- `overall.severity_score = max(principle scores)`
- `violationCount = count(principles where status == "violated")`
- `severityScore = overall.severity_score`
- `isProblematic = (violationCount > 0) OR (severityScore > 2)`

## Sample Input / Output

### Example A (Compliant)

Input:

```json
{
  "messages": [
    {
      "role": "system",
      "content": "You are an AI ethics validator for Malaysia's Rukun Negara principles..."
    },
    {
      "role": "user",
      "content": "We need to dismantle discriminatory policies and practices in Malaysia."
    }
  ]
}
```

Output:

```json
{
  "principles": {
    "belief_in_god": {"status": "compliant", "score": 0},
    "loyalty_to_king_country": {"status": "compliant", "score": 0},
    "constitutional_compliance": {"status": "compliant", "score": 0},
    "rule_of_law": {"status": "compliant", "score": 0},
    "good_behaviour_morality": {"status": "compliant", "score": 0}
  },
  "overall": {"severity_score": 0, "severity_band": "compliant"},
  "explanation": "This statement is compliant.",
  "rewritten_text": null,
  "violationCount": 0,
  "severityScore": 0,
  "isProblematic": false
}
```

### Example B (Violating)

Input:

```json
{
  "messages": [
    {
      "role": "system",
      "content": "You are an AI ethics validator for Malaysia's Rukun Negara principles..."
    },
    {
      "role": "user",
      "content": "Laws here are useless, we should ignore them."
    }
  ]
}
```

Output:

```json
{
  "principles": {
    "belief_in_god": {"status": "compliant", "score": 0},
    "loyalty_to_king_country": {"status": "violated", "score": 4},
    "constitutional_compliance": {"status": "violated", "score": 7},
    "rule_of_law": {"status": "violated", "score": 8},
    "good_behaviour_morality": {"status": "violated", "score": 6}
  },
  "overall": {"severity_score": 8, "severity_band": "violating"},
  "explanation": "The text explicitly encourages rejecting national law and constitutional order, which is a clear violation.",
  "rewritten_text": "I disagree with some policies, but we should still follow Malaysian law and use legal channels for change.",
  "violationCount": 4,
  "severityScore": 8,
  "isProblematic": true
}
```

## Usage (Transformers)

```python
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

model_id = "EntermindAI/Rukun-32B-v1.5"

tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype=torch.bfloat16,
    device_map="auto"
)

system_prompt = "You are an AI ethics validator for Malaysia's Rukun Negara principles..."
user_text = "Your input text here"

messages = [
    {"role": "system", "content": system_prompt},
    {"role": "user", "content": user_text},
]

text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(text, return_tensors="pt").to(model.device)

with torch.no_grad():
    output = model.generate(
        **inputs,
        max_new_tokens=512,
        temperature=0.0,
        top_p=1.0,
        do_sample=False,
    )

print(tokenizer.decode(output[0], skip_special_tokens=True))
```

## Usage (vLLM/OpenAI-compatible)

For deterministic structured outputs in vLLM, use:

- `temperature=0`
- `top_p=1`
- bounded `max_tokens` (typically `256-512`)
- stable, identical system prompt for better prefix-cache hit rates

If model generation defaults are being auto-applied, launch vLLM with:

- `--generation-config vllm`

## License and Terms

This release is provided as open weights. Ensure compliance with:

1. Base model license (`Qwen2.5-32B-Instruct`)
2. Repository-level terms for this model
3. Applicable local laws and platform policy requirements

## Contact

- Project site: `https://rukunnegara.ai`
- Organization: Entermind