-
Notifications
You must be signed in to change notification settings - Fork 21
/
write_factoid_answers.py
36 lines (27 loc) · 1.19 KB
/
write_factoid_answers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import json
import argparse
parser = argparse.ArgumentParser(
description="Returns the context, question, and answer.",
add_help=True, formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("--truth_filename",
default="data-release/BioASQ-6b/test/Full-Abstract/BioASQ-test-factoid-6b-3.json",
help="the path to the ground truth file")
parser.add_argument("--predictions_filename",
default="/tmp/factoid_output/predictions.json",
help="the path to the predictions file")
args = parser.parse_args()
with open(args.truth_filename) as json_file2:
truths = json.load(json_file2)
with open(args.predictions_filename) as json_file:
answers = json.load(json_file)
for data in answers.items():
id = data[0]
answer = data[1]
print("ID: {}".format(id))
print("="*32)
for d in truths["data"][0]["paragraphs"]:
if d["qas"][0]["id"] == id:
question = d["qas"][0]["question"]
context = d["context"]
print("Context:\n********\n{}\n\nQuestion:\n*********\n{}\n\nPrediction:\n***********\n{}".format(context, question, answer))
print("\n\n")