Spaces:
Running
Running
Update aap.py
Browse files
aap.py
CHANGED
|
@@ -8,6 +8,19 @@ import torch
|
|
| 8 |
|
| 9 |
# tokenizer = DistilBertTokenizer.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
|
| 10 |
# model = DistilBertForSequenceClassification.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
app = FastAPI()
|
| 13 |
|
|
|
|
| 8 |
|
| 9 |
# tokenizer = DistilBertTokenizer.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
|
| 10 |
# model = DistilBertForSequenceClassification.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
|
| 11 |
+
import torch
|
| 12 |
+
from transformers import DistilBertTokenizer, DistilBertForSequenceClassification
|
| 13 |
+
|
| 14 |
+
tokenizer = DistilBertTokenizer.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
|
| 15 |
+
model = DistilBertForSequenceClassification.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
|
| 16 |
+
|
| 17 |
+
inputs = tokenizer("Its very hot outside", return_tensors="pt")
|
| 18 |
+
with torch.no_grad():
|
| 19 |
+
logits = model(**inputs).logits
|
| 20 |
+
|
| 21 |
+
predicted_class_id = logits.argmax().item()
|
| 22 |
+
model.config.id2label[predicted_class_id]
|
| 23 |
+
|
| 24 |
|
| 25 |
app = FastAPI()
|
| 26 |
|