File size: 1,734 Bytes
d668179
f02467d
 
 
 
 
 
 
 
 
 
 
 
 
 
d668179
 
f02467d
d668179
f02467d
d668179
f02467d
d668179
f02467d
 
d668179
f02467d
d668179
f02467d
 
 
 
 
 
 
 
 
 
 
 
d668179
f02467d
d668179
f02467d
 
 
 
d668179
f02467d
 
d668179
f02467d
 
 
 
 
d668179
f02467d
d668179
f02467d
 
 
 
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
---
base_model: nvidia/Llama-3.1-Nemotron-Safety-Guard-8B-v3
language:
- en
- hi
license: other
tags:
- content-moderation
- safety
- lora
- peft
- hindi
- english
datasets:
- nvidia/Nemotron-Safety-Guard-Dataset-v3
---

# Nemotron Safety Guard — Hindi + English

QLoRA fine-tune of [nvidia/Llama-3.1-Nemotron-Safety-Guard-8B-v3](https://huggingface.co/nvidia/Llama-3.1-Nemotron-Safety-Guard-8B-v3) for Hindi and English content safety classification.

## what this is

the original model supports 9 languages. this fine-tune specializes it for hindi (`hi`) and english (`en`) only,
trained on a balanced sample from the Nemotron-Safety-Guard-Dataset-v3.

## training details

| | |
|---|---|
| base model | nvidia/Llama-3.1-Nemotron-Safety-Guard-8B-v3 |
| method | QLoRA (4-bit, nf4) |
| lora rank | 8 |
| lora alpha | 32 |
| target modules | q_proj, v_proj |
| trainable params | 3.4M (LoRA adapters, 4-bit compressed) |
| languages | English, Hindi |
| training samples | 1000 (balanced) |
| epochs | 1 |
| learning rate | 2e-4 |

## how to use

```python
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
import torch, json

base_model_id = "nvidia/Llama-3.1-Nemotron-Safety-Guard-8B-v3"
adapter_id = "Amaanaliii/nemotron-safety-guard-hi-en"

tokenizer = AutoTokenizer.from_pretrained(adapter_id)
model = AutoModelForCausalLM.from_pretrained(base_model_id, torch_dtype=torch.float16, device_map="auto")
model = PeftModel.from_pretrained(model, adapter_id)
model.eval()
```

## output format

```json
{"User Safety": "safe" | "unsafe", "Response Safety": "safe" | "unsafe", "Safety Categories": "Violence, ..."}
```
`Response Safety` and `Safety Categories` are omitted when not applicable.