Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -16,7 +16,7 @@ tokenizer =AutoTokenizer.from_pretrained(model_path)
|
|
16 |
|
17 |
def prediccion(contexto, pregunta):
|
18 |
#se toqueniza las preguntas y el contexto
|
19 |
-
entradas = tokenizer.encode_plus(pregunta, contexto, return_tensors='pt')
|
20 |
salida = model(**entradas)
|
21 |
inicio_respuesta = torch.argmax(salida[0])
|
22 |
final_respuesta = torch.argmax(salida[1]) + 1
|
@@ -47,6 +47,21 @@ def compute_f1(prediction, truth):
|
|
47 |
pred_tokens = normalize_text(prediction).split()
|
48 |
truth_tokens = normalize_text(truth).split()
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
|
52 |
|
|
|
16 |
|
17 |
def prediccion(contexto, pregunta):
|
18 |
#se toqueniza las preguntas y el contexto
|
19 |
+
entradas = tokenizer.encode_plus(pregunta, contexto, return_tensors='pt')
|
20 |
salida = model(**entradas)
|
21 |
inicio_respuesta = torch.argmax(salida[0])
|
22 |
final_respuesta = torch.argmax(salida[1]) + 1
|
|
|
47 |
pred_tokens = normalize_text(prediction).split()
|
48 |
truth_tokens = normalize_text(truth).split()
|
49 |
|
50 |
+
# if either the prediction or the truth is no-answer then f1 = 1 if they agree, 0 otherwise
|
51 |
+
if len(pred_tokens) == 0 or len(truth_tokens) == 0:
|
52 |
+
return int(pred_tokens == truth_tokens)
|
53 |
+
|
54 |
+
common_tokens = set(pred_tokens) & set(truth_tokens)
|
55 |
+
|
56 |
+
# if there are no common tokens then f1 = 0
|
57 |
+
if len(common_tokens) == 0:
|
58 |
+
return 0
|
59 |
+
|
60 |
+
prec = len(common_tokens) / len(pred_tokens)
|
61 |
+
rec = len(common_tokens) / len(truth_tokens)
|
62 |
+
|
63 |
+
return round(2 * (prec * rec) / (prec + rec), 2)
|
64 |
+
|
65 |
|
66 |
|
67 |
|