vishesh-t27 commited on
Commit
9fb12b1
·
verified ·
1 Parent(s): 7fd6a42

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +99 -0
README.md ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ - hi
6
+ pipeline_tag: text-generation
7
+ library_name: transformers
8
+ base_model:
9
+ - FrontiersMind/Nandi-Mini-600M-Early-Checkpoint
10
+ ---
11
+
12
+ # Nandi-Mini-150M-GuardRails
13
+
14
+ ## Introduction
15
+
16
+ Nandi-Mini-600M-GuardRails is a lightweight multilingual (English & Hindi) safety classification model that detects unsafe or policy-violating content in user prompts and AI responses across multiple harm categories.
17
+
18
+
19
+ ## 🚀 Usage
20
+
21
+ ```python
22
+ !pip install transformers=='5.4.0'
23
+
24
+ from transformers import AutoTokenizer, AutoModelForCausalLM
25
+ import torch
26
+ import json
27
+
28
+ model_name = "FrontiersMind/Nandi-Mini-600M-GuardRails"
29
+
30
+ device = "cuda" if torch.cuda.is_available() else "cpu"
31
+
32
+ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
33
+ model = AutoModelForCausalLM.from_pretrained(
34
+ model_name,
35
+ trust_remote_code=True,
36
+ dtype=torch.bfloat16
37
+ ).to(device).eval()
38
+
39
+
40
+ def classify_safety(prompt, response=None):
41
+
42
+ content = {"prompt": prompt}
43
+
44
+ if response is not None:
45
+ content["response"] = response
46
+
47
+ messages = [
48
+ {
49
+ "role": "user",
50
+ "content": content
51
+ }
52
+ ]
53
+
54
+ prompt = tokenizer.apply_chat_template(
55
+ messages,
56
+ tokenize=False,
57
+ add_generation_prompt=True
58
+ )
59
+
60
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
61
+
62
+ generated_ids = model.generate(
63
+ **inputs,
64
+ max_new_tokens=200,
65
+ do_sample=False,
66
+ temperature=0.0,
67
+ )
68
+
69
+ generated_ids = [
70
+ output_ids[len(input_ids):]
71
+ for input_ids, output_ids in zip(inputs.input_ids, generated_ids)
72
+ ]
73
+
74
+ response = tokenizer.batch_decode(
75
+ generated_ids,
76
+ skip_special_tokens=True
77
+ )[0]
78
+
79
+ return json.loads(response)
80
+
81
+
82
+ result = classify_safety(
83
+ prompt="Tell me how to kill someone.",
84
+ )
85
+
86
+ print(result)
87
+ ```
88
+
89
+
90
+
91
+ ## 📬 Feedback & Suggestions
92
+
93
+ We’d love to hear your thoughts, feedback, and ideas!
94
+
95
+ - **Discord**: https://discord.gg/ZGdjCdRt
96
+ - **Email:** support@frontiersmind.ai
97
+ - **Official Website** https://www.frontiersmind.ai/
98
+ - **LinkedIn:** https://www.linkedin.com/company/frontiersmind/
99
+ - **X (Twitter):** https://x.com/FrontiersMind