Spaces:
Running
Running
tokenizer update
Browse files
app.py
CHANGED
|
@@ -4,24 +4,26 @@ import torch
|
|
| 4 |
|
| 5 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
|
|
|
| 9 |
model.to(device)
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
def predict(query: str) -> dict:
|
| 12 |
inputs = tokenizer(query, return_tensors='pt')
|
| 13 |
inputs.to(device)
|
| 14 |
outputs = model(**inputs)
|
| 15 |
outputs = torch.sigmoid(outputs.logits)
|
| 16 |
outputs = outputs.detach().cpu().numpy()
|
| 17 |
-
label2ids = {
|
| 18 |
-
"sadness": 0,
|
| 19 |
-
"joy": 1,
|
| 20 |
-
"love": 2,
|
| 21 |
-
"anger": 3,
|
| 22 |
-
"fear": 4,
|
| 23 |
-
"surprise": 5,
|
| 24 |
-
}
|
| 25 |
|
| 26 |
for i, k in enumerate(label2ids.keys()):
|
| 27 |
label2ids[k] = outputs[0][i]
|
|
|
|
| 4 |
|
| 5 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
| 6 |
|
| 7 |
+
model_id = "Rahmat82/DistilBERT-finetuned-on-emotion"
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id, return_tensors="pt", use_fast=True)
|
| 9 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_id)
|
| 10 |
model.to(device)
|
| 11 |
|
| 12 |
+
label2ids = {
|
| 13 |
+
"sadness": 0,
|
| 14 |
+
"joy": 1,
|
| 15 |
+
"love": 2,
|
| 16 |
+
"anger": 3,
|
| 17 |
+
"fear": 4,
|
| 18 |
+
"surprise": 5,
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
def predict(query: str) -> dict:
|
| 22 |
inputs = tokenizer(query, return_tensors='pt')
|
| 23 |
inputs.to(device)
|
| 24 |
outputs = model(**inputs)
|
| 25 |
outputs = torch.sigmoid(outputs.logits)
|
| 26 |
outputs = outputs.detach().cpu().numpy()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
for i, k in enumerate(label2ids.keys()):
|
| 29 |
label2ids[k] = outputs[0][i]
|