Davide Fiocco commited on
Commit
dbe757e
·
1 Parent(s): bcaff9d

Admit failure when answer is not known

Browse files
Files changed (2) hide show
  1. test_answers.py +6 -0
  2. utils.py +5 -2
test_answers.py CHANGED
@@ -67,6 +67,12 @@ def test_home():
67
  assert a == "Villafranca di Verona"
68
 
69
 
 
 
 
 
 
 
70
  def test_history():
71
  q = "Cosa mi è successo?"
72
  a = get_answer(q, context, nlp_qa)
 
67
  assert a == "Villafranca di Verona"
68
 
69
 
70
+ def test_address():
71
+ q = "Qual è l'indirizzo di casa?"
72
+ a = get_answer(q, context, nlp_qa)
73
+ assert "Vittorio Emanuele II" in a
74
+
75
+
76
  def test_history():
77
  q = "Cosa mi è successo?"
78
  a = get_answer(q, context, nlp_qa)
utils.py CHANGED
@@ -6,11 +6,14 @@ import torch
6
  from transformers import Pipeline, pipeline
7
 
8
 
9
- def get_answer(input, context, engine):
10
 
11
  answer = engine({"question": input, "context": context})
12
 
13
- return answer["answer"]
 
 
 
14
 
15
 
16
  @st.cache
 
6
  from transformers import Pipeline, pipeline
7
 
8
 
9
+ def get_answer(input, context, engine, threshold=0.4):
10
 
11
  answer = engine({"question": input, "context": context})
12
 
13
+ if answer["score"] > threshold:
14
+ return answer["answer"]
15
+ else:
16
+ return "Non lo so, prova con un'altra domanda!"
17
 
18
 
19
  @st.cache