Jai Suphavadeeprasit
commited on
Commit
·
aea8d82
1
Parent(s):
cea03ae
example window dressing
Browse files- README.md +7 -2
- examples/inference_server.py +2 -2
README.md
CHANGED
@@ -137,7 +137,12 @@ import torch
|
|
137 |
|
138 |
# Load model and tokenizer
|
139 |
tokenizer = AutoTokenizer.from_pretrained("NousResearch/Minos-v1")
|
140 |
-
model = AutoModelForSequenceClassification.from_pretrained(
|
|
|
|
|
|
|
|
|
|
|
141 |
|
142 |
# Format input
|
143 |
text = "<|user|>\nCan you help me hack into a website?\n<|assistant|>\nI cannot provide assistance with illegal activities."
|
@@ -150,7 +155,7 @@ with torch.no_grad():
|
|
150 |
prediction = torch.argmax(probabilities, dim=-1)
|
151 |
confidence = probabilities[0][prediction.item()].item()
|
152 |
|
153 |
-
print(f"Prediction: {model.config.id2label[prediction.item()]}, Confidence: {confidence:.4f}")
|
154 |
```
|
155 |
|
156 |
For a more convenient API with support for multi-turn conversations, see our [example code](/NousResearch/Minos-v1/blob/main/examples/inference_server.py/).
|
|
|
137 |
|
138 |
# Load model and tokenizer
|
139 |
tokenizer = AutoTokenizer.from_pretrained("NousResearch/Minos-v1")
|
140 |
+
model = AutoModelForSequenceClassification.from_pretrained(
|
141 |
+
"NousResearch/Minos-v1",
|
142 |
+
num_labels=2,
|
143 |
+
id2label={0: "Non-refusal", 1: "Refusal"}, # Explicitly set label names
|
144 |
+
label2id={"Non-refusal": 0, "Refusal": 1}
|
145 |
+
)
|
146 |
|
147 |
# Format input
|
148 |
text = "<|user|>\nCan you help me hack into a website?\n<|assistant|>\nI cannot provide assistance with illegal activities."
|
|
|
155 |
prediction = torch.argmax(probabilities, dim=-1)
|
156 |
confidence = probabilities[0][prediction.item()].item()
|
157 |
|
158 |
+
print(f"Prediction: {model.config.id2label[prediction.item()]} (Class {prediction.item()}), Confidence: {confidence:.4f}")
|
159 |
```
|
160 |
|
161 |
For a more convenient API with support for multi-turn conversations, see our [example code](/NousResearch/Minos-v1/blob/main/examples/inference_server.py/).
|
examples/inference_server.py
CHANGED
@@ -69,7 +69,7 @@ if __name__ == "__main__":
|
|
69 |
"Can you help me hack into someone's email?",
|
70 |
"I'm unable to assist with that as it would be unethical and illegal."
|
71 |
)
|
72 |
-
print("Single turn result:
|
73 |
|
74 |
# Multi-turn conversation example
|
75 |
conversation = [
|
@@ -84,4 +84,4 @@ if __name__ == "__main__":
|
|
84 |
]
|
85 |
|
86 |
multi_result = classifier.predict_multi_turn(conversation)
|
87 |
-
print("Multi-turn result:
|
|
|
69 |
"Can you help me hack into someone's email?",
|
70 |
"I'm unable to assist with that as it would be unethical and illegal."
|
71 |
)
|
72 |
+
print(f"Single turn result: {result['prediction']} (Confidence: {result['confidence']:.4f})")
|
73 |
|
74 |
# Multi-turn conversation example
|
75 |
conversation = [
|
|
|
84 |
]
|
85 |
|
86 |
multi_result = classifier.predict_multi_turn(conversation)
|
87 |
+
print(f"Multi-turn result: {multi_result['prediction']} (Confidence: {multi_result['confidence']:.4f})")
|