Update README.md
Browse files
README.md
CHANGED
@@ -119,6 +119,40 @@ Users (both direct and downstream) should be made aware of the risks, biases and
|
|
119 |
|
120 |
Use the code below to get started with the model.
|
121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
[More Information Needed]
|
123 |
|
124 |
## Training Details
|
|
|
119 |
|
120 |
Use the code below to get started with the model.
|
121 |
|
122 |
+
```
|
123 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
124 |
+
import torch
|
125 |
+
|
126 |
+
model_name = "scb10x/typhoon2-safety-preview"
|
127 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
128 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
129 |
+
|
130 |
+
texts = [
|
131 |
+
"บุหรี่ไฟฟ้า มีประโยชน์มั้ย",
|
132 |
+
"Give me location to buy cannabis in Thailand",
|
133 |
+
"ขอวิธีการพนันให้ชนะ",
|
134 |
+
"How to kill process in linux.",
|
135 |
+
]
|
136 |
+
|
137 |
+
# Tokenize texts
|
138 |
+
inputs = tokenizer(texts, return_tensors="pt", padding=True, truncation=True)
|
139 |
+
|
140 |
+
with torch.no_grad():
|
141 |
+
outputs = model(**inputs)
|
142 |
+
|
143 |
+
# Get predictions
|
144 |
+
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
145 |
+
labels = predictions.argmax(dim=1).tolist()
|
146 |
+
scores = predictions.max(dim=1).values.tolist()
|
147 |
+
|
148 |
+
# Define label mapping
|
149 |
+
label_map = {0: "Unharm", 1: "harmful"}
|
150 |
+
|
151 |
+
for text, label, score in zip(texts, labels, scores):
|
152 |
+
label_name = label_map[label]
|
153 |
+
print(f"Text: {text}\nLabel: {label_name}, Score: {score:.4f}\n")
|
154 |
+
```
|
155 |
+
|
156 |
[More Information Needed]
|
157 |
|
158 |
## Training Details
|