Spaces:
Runtime error
Runtime error
ruanchaves
commited on
Commit
•
b47e996
1
Parent(s):
e721563
simplify interface
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
|
|
2 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
3 |
import torch
|
4 |
from collections import Counter
|
|
|
5 |
|
6 |
article_string = "Author: <a href=\"https://huggingface.co/ruanchaves\">Ruan Chaves Rodrigues</a>. Read more about our <a href=\"https://github.com/ruanchaves/eplm\">research on the evaluation of Portuguese language models</a>."
|
7 |
|
@@ -54,6 +55,10 @@ user_friendly_name = {
|
|
54 |
"ruanchaves/bert-large-portuguese-cased-faquad-nli": "BERTimbau large (FaQuAD)",
|
55 |
}
|
56 |
|
|
|
|
|
|
|
|
|
57 |
model_array = []
|
58 |
|
59 |
for model_name in model_list:
|
@@ -67,36 +72,43 @@ def most_frequent(array):
|
|
67 |
occurence_count = Counter(array)
|
68 |
return occurence_count.most_common(1)[0][0]
|
69 |
|
70 |
-
def predict(s1, s2):
|
|
|
|
|
71 |
scores = {}
|
|
|
72 |
for row in model_array:
|
73 |
-
name =
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
|
|
|
|
|
|
|
|
90 |
|
91 |
|
92 |
inputs = [
|
93 |
gr.inputs.Textbox(label="Question"),
|
94 |
-
gr.inputs.Textbox(label="Answer")
|
|
|
95 |
]
|
96 |
|
97 |
outputs = [
|
98 |
-
gr.
|
99 |
-
gr.JSON(label="Results by model", value=output_json_component_description)
|
100 |
]
|
101 |
|
102 |
|
|
|
2 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
3 |
import torch
|
4 |
from collections import Counter
|
5 |
+
from scipy.special import softmax
|
6 |
|
7 |
article_string = "Author: <a href=\"https://huggingface.co/ruanchaves\">Ruan Chaves Rodrigues</a>. Read more about our <a href=\"https://github.com/ruanchaves/eplm\">research on the evaluation of Portuguese language models</a>."
|
8 |
|
|
|
55 |
"ruanchaves/bert-large-portuguese-cased-faquad-nli": "BERTimbau large (FaQuAD)",
|
56 |
}
|
57 |
|
58 |
+
reverse_user_friendly_name = { v:k for k,v in user_friendly_name.items() }
|
59 |
+
|
60 |
+
user_friendly_name_list = list(user_friendly_name.values())
|
61 |
+
|
62 |
model_array = []
|
63 |
|
64 |
for model_name in model_list:
|
|
|
72 |
occurence_count = Counter(array)
|
73 |
return occurence_count.most_common(1)[0][0]
|
74 |
|
75 |
+
def predict(s1, s2, chosen_model):
|
76 |
+
if not chosen_model:
|
77 |
+
chosen_model = user_friendly_name_list[0]
|
78 |
scores = {}
|
79 |
+
full_chosen_model_name = reverse_user_friendly_name[chosen_model]
|
80 |
for row in model_array:
|
81 |
+
name = row["name"]
|
82 |
+
if name != full_chosen_model_name:
|
83 |
+
continue
|
84 |
+
else:
|
85 |
+
tokenizer = row["tokenizer"]
|
86 |
+
model = row["model"]
|
87 |
+
model_input = tokenizer(*([s1], [s2]), padding=True, return_tensors="pt")
|
88 |
+
with torch.no_grad():
|
89 |
+
output = model(**model_input)
|
90 |
+
logits = output[0][0].detach().numpy()
|
91 |
+
logits = softmax(logits).tolist()
|
92 |
+
break
|
93 |
+
def get_description(idx):
|
94 |
+
description = score_descriptions[idx]
|
95 |
+
description_pt = score_descriptions_pt[idx]
|
96 |
+
final_description = description + "\n \n" + description_pt
|
97 |
+
return final_description
|
98 |
+
|
99 |
+
scores = { get_description(k):v for k,v in enumerate(logits) }
|
100 |
+
|
101 |
+
return scores
|
102 |
|
103 |
|
104 |
inputs = [
|
105 |
gr.inputs.Textbox(label="Question"),
|
106 |
+
gr.inputs.Textbox(label="Answer"),
|
107 |
+
gr.Dropdown(label="Model", choices=user_friendly_name_list, default=user_friendly_name_list[0])
|
108 |
]
|
109 |
|
110 |
outputs = [
|
111 |
+
gr.Label(label="Result")
|
|
|
112 |
]
|
113 |
|
114 |
|