Stefano Fiorucci commited on
Commit
c5b375b
1 Parent(s): d4647c0

threshold for answers

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -38,7 +38,9 @@ def start_haystack():
38
  embedding_model="sentence-transformers/multi-qa-mpnet-base-dot-v1",
39
  model_format="sentence_transformers"
40
  )
41
- reader = FARMReader(model_name_or_path="deepset/roberta-base-squad2", use_gpu=True)
 
 
42
  pipe = ExtractiveQAPipeline(reader, retriever)
43
  return pipe
44
 
@@ -203,6 +205,8 @@ and see if the AI ​​can find an answer...
203
  st.write("## Results:")
204
 
205
  alert_irrelevance=True
 
 
206
 
207
  for count, result in enumerate(st.session_state.results['answers']):
208
  result=result.to_dict()
@@ -217,10 +221,8 @@ and see if the AI ​​can find an answer...
217
  # Hack due to this bug: https://github.com/streamlit/streamlit/issues/3190
218
  st.write(markdown("- ..."+context[:start_idx] + str(annotation(answer, "ANSWER", "#3e1c21")) + context[end_idx:]+"..."), unsafe_allow_html=True)
219
  source = ""
220
- name = unquote(result['meta']['name'])
221
  url = result['meta']['url']
222
  source = f"[{name}]({url})"
223
  st.markdown(f"**Score:** {result['score']:.2f} - **Source:** {source}")
224
- else:
225
- st.info("🤔    Haystack is unsure whether any of the documents contain an answer to your question. Try to reformulate it!")
226
  main()
 
38
  embedding_model="sentence-transformers/multi-qa-mpnet-base-dot-v1",
39
  model_format="sentence_transformers"
40
  )
41
+ reader = FARMReader(model_name_or_path="deepset/roberta-base-squad2",
42
+ use_gpu=False,
43
+ confidence_threshold=0.15)
44
  pipe = ExtractiveQAPipeline(reader, retriever)
45
  return pipe
46
 
 
205
  st.write("## Results:")
206
 
207
  alert_irrelevance=True
208
+ if len(st.session_state.results['answers'])>0:
209
+ st.info("🤔    Haystack is unsure whether any of the documents contain an answer to your question. Try to reformulate it!")
210
 
211
  for count, result in enumerate(st.session_state.results['answers']):
212
  result=result.to_dict()
 
221
  # Hack due to this bug: https://github.com/streamlit/streamlit/issues/3190
222
  st.write(markdown("- ..."+context[:start_idx] + str(annotation(answer, "ANSWER", "#3e1c21")) + context[end_idx:]+"..."), unsafe_allow_html=True)
223
  source = ""
224
+ name = unquote(result['meta']['name']).replace('_',' ')
225
  url = result['meta']['url']
226
  source = f"[{name}]({url})"
227
  st.markdown(f"**Score:** {result['score']:.2f} - **Source:** {source}")
 
 
228
  main()