Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import torch
|
| 3 |
+
from transformers import DistilBertTokenizer, DistilBertForSequenceClassification
|
| 4 |
+
|
| 5 |
+
tokenizer = DistilBertTokenizer.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
|
| 6 |
+
model = DistilBertForSequenceClassification.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
|
| 7 |
+
|
| 8 |
+
inputs = tokenizer("Hello, my dog is cute", return_tensors="pt")
|
| 9 |
+
with torch.no_grad():
|
| 10 |
+
logits = model(**inputs).logits
|
| 11 |
+
|
| 12 |
+
predicted_class_id = logits.argmax().item()
|
| 13 |
+
model.config.id2label[predicted_class_id]
|