Update app.py
Browse files
app.py
CHANGED
|
@@ -27,11 +27,13 @@ if st.button('Run semantic question answering'):
|
|
| 27 |
top_5_hits = kws_result['hits']['hits'][:5] # print("First 5 results:")
|
| 28 |
top_5_text = [{'text': hit['_source']['content'][:500],
|
| 29 |
'confidence': hit['_score']} for hit in top_5_hits ]
|
|
|
|
| 30 |
top_5_para = [hit['_source']['content'][:5000] for hit in top_5_hits]
|
| 31 |
|
| 32 |
DPR_MODEL = "deepset/roberta-base-squad2" #, model="distilbert-base-cased-distilled-squad"
|
| 33 |
pipe_exqa = pipeline("question-answering", model=DPR_MODEL)
|
| 34 |
-
qa_results = [pipe_exqa(question=question, context=paragraph) for paragraph in top_5_para]
|
|
|
|
| 35 |
|
| 36 |
for i, qa_result in enumerate(qa_results):
|
| 37 |
if "answer" in qa_result.keys():
|
|
@@ -40,8 +42,10 @@ if st.button('Run semantic question answering'):
|
|
| 40 |
paragraph = top_5_para[i]
|
| 41 |
start_par, stop_para = max(0, qa_result["start"]-86), min(qa_result["end"]+90, len(paragraph))
|
| 42 |
answer_context = paragraph[start_par:stop_para].replace(answer_span, f'**{answer_span}**')
|
| 43 |
-
st.write(f'Answer context (and score): ... _{answer_context}_ ...')
|
| 44 |
-
|
|
|
|
|
|
|
| 45 |
|
| 46 |
st.write(f'Answers JSON: '); st.write(qa_results)
|
| 47 |
|
|
|
|
| 27 |
top_5_hits = kws_result['hits']['hits'][:5] # print("First 5 results:")
|
| 28 |
top_5_text = [{'text': hit['_source']['content'][:500],
|
| 29 |
'confidence': hit['_score']} for hit in top_5_hits ]
|
| 30 |
+
top_3_para = [hit['_source']['content'][:5000] for hit in top_5_hits[:3]]
|
| 31 |
top_5_para = [hit['_source']['content'][:5000] for hit in top_5_hits]
|
| 32 |
|
| 33 |
DPR_MODEL = "deepset/roberta-base-squad2" #, model="distilbert-base-cased-distilled-squad"
|
| 34 |
pipe_exqa = pipeline("question-answering", model=DPR_MODEL)
|
| 35 |
+
# qa_results = [pipe_exqa(question=question, context=paragraph) for paragraph in top_5_para]
|
| 36 |
+
qa_results = [pipe_exqa(question=question, context=paragraph) for paragraph in top_3_para]
|
| 37 |
|
| 38 |
for i, qa_result in enumerate(qa_results):
|
| 39 |
if "answer" in qa_result.keys():
|
|
|
|
| 42 |
paragraph = top_5_para[i]
|
| 43 |
start_par, stop_para = max(0, qa_result["start"]-86), min(qa_result["end"]+90, len(paragraph))
|
| 44 |
answer_context = paragraph[start_par:stop_para].replace(answer_span, f'**{answer_span}**')
|
| 45 |
+
st.write(f'Answer context (and score): ... _{answer_context}_ ...')
|
| 46 |
+
color_string = 'green' if answer_score > 0.65 else 'orange' if answer_score > 0.45 else 'red'
|
| 47 |
+
# st.markdown("""This text is :red[colored red]""")
|
| 48 |
+
st.markdown(f'(answer confidence: :{color_string}[{format(answer_score, ".3f")}])')
|
| 49 |
|
| 50 |
st.write(f'Answers JSON: '); st.write(qa_results)
|
| 51 |
|