Jayveersinh-Raj
commited on
Commit
•
c4700ad
1
Parent(s):
6274747
Update README.md
Browse files
README.md
CHANGED
@@ -150,7 +150,26 @@ This model aims to help developers, especially those with little to no experienc
|
|
150 |
### Direct Use
|
151 |
|
152 |
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
153 |
-
Just use the model from hugging face directly
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
|
155 |
|
156 |
### Downstream Use [optional]
|
|
|
150 |
### Direct Use
|
151 |
|
152 |
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
153 |
+
Just use the model from hugging face directly. Following is an example
|
154 |
+
|
155 |
+
from transformers import XLMRobertaForSequenceClassification, AutoTokenizer
|
156 |
+
import torch
|
157 |
+
|
158 |
+
model_name = "Jayveersinh-Raj/PolyGuard"
|
159 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
160 |
+
model = XLMRobertaForSequenceClassification.from_pretrained(model_name)
|
161 |
+
|
162 |
+
text = "Jayveer is a great NLP engineer, and a noob in CV"
|
163 |
+
inputs = tokenizer.encode(text, return_tensors="pt", max_length=512, truncation=True)
|
164 |
+
outputs = model(inputs)[0]
|
165 |
+
probabilities = torch.softmax(outputs, dim=1)
|
166 |
+
predicted_class = torch.argmax(probabilities).item()
|
167 |
+
if predicted_class == 1:
|
168 |
+
print("Toxic")
|
169 |
+
else:
|
170 |
+
print("Not toxic")
|
171 |
+
|
172 |
+
|
173 |
|
174 |
|
175 |
### Downstream Use [optional]
|