Update app.py
Browse files
app.py
CHANGED
@@ -172,8 +172,7 @@ def claim(text):
|
|
172 |
who.append(substr)
|
173 |
else:
|
174 |
pass
|
175 |
-
|
176 |
-
|
177 |
df['who'][j] = "<sep>".join(who)
|
178 |
# else:
|
179 |
# continue
|
@@ -236,6 +235,7 @@ def claim(text):
|
|
236 |
why.append(substr)
|
237 |
else:
|
238 |
pass
|
|
|
239 |
|
240 |
df['why'][j] = "<sep>".join(why)
|
241 |
# else:
|
@@ -268,6 +268,7 @@ def claim(text):
|
|
268 |
when.append(substr)
|
269 |
else:
|
270 |
pass
|
|
|
271 |
|
272 |
df['when'][j] = "<sep>".join(when)
|
273 |
# else:
|
@@ -301,6 +302,7 @@ def claim(text):
|
|
301 |
where.append(substr)
|
302 |
else:
|
303 |
pass
|
|
|
304 |
|
305 |
df['where'][j] = "<sep>".join(where)
|
306 |
|
@@ -344,7 +346,7 @@ def gen_qa_who(df):
|
|
344 |
claim=df['claim'][i]
|
345 |
answer= split_ws(df["who"])
|
346 |
evidence=df["evidence"][i]
|
347 |
-
time.sleep(10)
|
348 |
if srl!="":
|
349 |
try:
|
350 |
for j in range(0,len(answer)):
|
@@ -358,15 +360,14 @@ def gen_qa_who(df):
|
|
358 |
question_ids = rephrase_question_who(question_ids)
|
359 |
list_of_ques_who.append(f"""Q{j+1}:{question_ids}""")
|
360 |
list_of_ans_who.append(f"""Ans{j+1}:{answer[j]}""")
|
361 |
-
input_evidence = f"
|
362 |
-
time.sleep(10)
|
363 |
answer_evidence = query_evidence({"inputs":input_evidence,"truncation":True,"wait_for_model":True})[0]['generated_text']
|
364 |
if answer_evidence.lower() in evidence.lower():
|
365 |
list_of_evidence_answer_who.append(f"""Evidence{j+1}:{answer_evidence}""")
|
366 |
else:
|
367 |
answer_evidence=""
|
368 |
list_of_evidence_answer_who.append(f"""No mention of 'who'in any related documents.""")
|
369 |
-
list_of_evidence_answer_who.append(f"""Evidence{j+1}:{answer_evidence}""")
|
370 |
threshold = 0.2
|
371 |
list_of_pairs = [(answer_evidence, answer[j])]
|
372 |
rouge_l_score = calc_rouge_l_score(answer_evidence, answer[j])
|
@@ -384,7 +385,7 @@ def gen_qa_who(df):
|
|
384 |
list_of_ans_who=""
|
385 |
list_of_evidence_answer_who="No mention of 'who'in any related documents."
|
386 |
rouge_l_scores="Not verifiable"
|
387 |
-
return list_of_ques_who,list_of_ans_who,list_of_evidence_answer_who
|
388 |
#------------------------------------------------------------
|
389 |
|
390 |
def rephrase_question_what(question):
|
|
|
172 |
who.append(substr)
|
173 |
else:
|
174 |
pass
|
175 |
+
who=list(set(who))
|
|
|
176 |
df['who'][j] = "<sep>".join(who)
|
177 |
# else:
|
178 |
# continue
|
|
|
235 |
why.append(substr)
|
236 |
else:
|
237 |
pass
|
238 |
+
why=list(set(why))
|
239 |
|
240 |
df['why'][j] = "<sep>".join(why)
|
241 |
# else:
|
|
|
268 |
when.append(substr)
|
269 |
else:
|
270 |
pass
|
271 |
+
when=list(set(when))
|
272 |
|
273 |
df['when'][j] = "<sep>".join(when)
|
274 |
# else:
|
|
|
302 |
where.append(substr)
|
303 |
else:
|
304 |
pass
|
305 |
+
where=list(set(where))
|
306 |
|
307 |
df['where'][j] = "<sep>".join(where)
|
308 |
|
|
|
346 |
claim=df['claim'][i]
|
347 |
answer= split_ws(df["who"])
|
348 |
evidence=df["evidence"][i]
|
349 |
+
#time.sleep(10)
|
350 |
if srl!="":
|
351 |
try:
|
352 |
for j in range(0,len(answer)):
|
|
|
360 |
question_ids = rephrase_question_who(question_ids)
|
361 |
list_of_ques_who.append(f"""Q{j+1}:{question_ids}""")
|
362 |
list_of_ans_who.append(f"""Ans{j+1}:{answer[j]}""")
|
363 |
+
input_evidence = f"answer_the_next_question_from_context: {question_ids} context: {evidence}"
|
364 |
+
#time.sleep(10)
|
365 |
answer_evidence = query_evidence({"inputs":input_evidence,"truncation":True,"wait_for_model":True})[0]['generated_text']
|
366 |
if answer_evidence.lower() in evidence.lower():
|
367 |
list_of_evidence_answer_who.append(f"""Evidence{j+1}:{answer_evidence}""")
|
368 |
else:
|
369 |
answer_evidence=""
|
370 |
list_of_evidence_answer_who.append(f"""No mention of 'who'in any related documents.""")
|
|
|
371 |
threshold = 0.2
|
372 |
list_of_pairs = [(answer_evidence, answer[j])]
|
373 |
rouge_l_score = calc_rouge_l_score(answer_evidence, answer[j])
|
|
|
385 |
list_of_ans_who=""
|
386 |
list_of_evidence_answer_who="No mention of 'who'in any related documents."
|
387 |
rouge_l_scores="Not verifiable"
|
388 |
+
return list_of_ques_who,list_of_ans_who,rouge_l_scores,list_of_evidence_answer_who
|
389 |
#------------------------------------------------------------
|
390 |
|
391 |
def rephrase_question_what(question):
|