Spaces:
Running
Running
kovacsvi
commited on
Commit
·
27a48cb
1
Parent(s):
920ee47
out of scope variable fixed
Browse files- interfaces/emotion9.py +3 -6
interfaces/emotion9.py
CHANGED
@@ -20,15 +20,10 @@ domains = {
|
|
20 |
"parliamentary speech": "parlspeech",
|
21 |
}
|
22 |
|
23 |
-
USE_V2 = False
|
24 |
-
if language in ["slovak", "polish", "czech", "hungarian"]:
|
25 |
-
EMOTION9_LABEL_NAMES = EMOTION9_V2_LABEL_NAMES
|
26 |
-
USE_V2 = True
|
27 |
-
|
28 |
def build_huggingface_path(language: str):
|
29 |
language = language.lower()
|
30 |
base_model_id = f"poltextlab/xlm-roberta-large-pooled-{language}-emotions9"
|
31 |
-
if
|
32 |
return base_model_id + "-v2"
|
33 |
return base_model_id
|
34 |
|
@@ -62,6 +57,8 @@ def predict(text, model_id, tokenizer_id):
|
|
62 |
|
63 |
probs = torch.nn.functional.softmax(logits, dim=1).cpu().numpy().flatten()
|
64 |
|
|
|
|
|
65 |
NUMS_DICT = {i: key for i, key in enumerate(sorted(EMOTION9_LABEL_NAMES.keys()))}
|
66 |
output_pred = {f"[{NUMS_DICT[i]}] {EMOTION9_LABEL_NAMES[NUMS_DICT[i]]}": probs[i] for i in np.argsort(probs)[::-1]}
|
67 |
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>'
|
|
|
20 |
"parliamentary speech": "parlspeech",
|
21 |
}
|
22 |
|
|
|
|
|
|
|
|
|
|
|
23 |
def build_huggingface_path(language: str):
|
24 |
language = language.lower()
|
25 |
base_model_id = f"poltextlab/xlm-roberta-large-pooled-{language}-emotions9"
|
26 |
+
if language in ["slovak", "polish", "czech", "hungarian"]:
|
27 |
return base_model_id + "-v2"
|
28 |
return base_model_id
|
29 |
|
|
|
57 |
|
58 |
probs = torch.nn.functional.softmax(logits, dim=1).cpu().numpy().flatten()
|
59 |
|
60 |
+
if "v2" in model_id:
|
61 |
+
EMOTION9_LABEL_NAMES = EMOTION9_V2_LABEL_NAMES
|
62 |
NUMS_DICT = {i: key for i, key in enumerate(sorted(EMOTION9_LABEL_NAMES.keys()))}
|
63 |
output_pred = {f"[{NUMS_DICT[i]}] {EMOTION9_LABEL_NAMES[NUMS_DICT[i]]}": probs[i] for i in np.argsort(probs)[::-1]}
|
64 |
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>'
|