Spaces:
Running
Running
Update interfaces/emotion9.py
Browse files- interfaces/emotion9.py +2 -0
interfaces/emotion9.py
CHANGED
@@ -37,6 +37,8 @@ def predict(text, model_id, tokenizer_id):
|
|
37 |
with torch.no_grad():
|
38 |
logits = model(**inputs).logits
|
39 |
|
|
|
|
|
40 |
NUMS_DICT = {i: key for i, key in enumerate(sorted(EMOTION9_LABEL_NAMES.keys()))}
|
41 |
output_pred = {f"[{NUMS_DICT[i]}] {EMOTION9_LABEL_NAMES[NUMS_DICT[i]]}": probs[i] for i in np.argsort(probs)[::-1]}
|
42 |
output_info = f'<p style="text-align: center; display: block">Prediction was made using the <a href="https://huggingface.co/{model_id}">{model_id}</a> model.</p>'
|
|
|
37 |
with torch.no_grad():
|
38 |
logits = model(**inputs).logits
|
39 |
|
40 |
+
probs = torch.nn.functional.softmax(logits, dim=1).cpu().numpy().flatten()
|
41 |
+
|
42 |
NUMS_DICT = {i: key for i, key in enumerate(sorted(EMOTION9_LABEL_NAMES.keys()))}
|
43 |
output_pred = {f"[{NUMS_DICT[i]}] {EMOTION9_LABEL_NAMES[NUMS_DICT[i]]}": probs[i] for i in np.argsort(probs)[::-1]}
|
44 |
output_info = f'<p style="text-align: center; display: block">Prediction was made using the <a href="https://huggingface.co/{model_id}">{model_id}</a> model.</p>'
|