import jsonlines | |
from tqdm import tqdm | |
path = 'coco_msmarco_dev.jsonl' | |
data = [] | |
with jsonlines.open(path, 'r') as reader: | |
for instance in tqdm(reader, total=6980): #tqdm(f, total=6980): | |
data.append(instance) | |
print('data append done!') | |
new = [] | |
for instance in tqdm(data): | |
qrels = {x: int(instance['qrels'][x]) for x in instance['qrels']} | |
temp = {'qid': instance['qid'], 'q_text': instance['q_text'], | |
'bm25_results': [], 'qrels': qrels} | |
bm25 = [] | |
for x in instance['COCO_results']: | |
bm25.append({'text': x['text'], 'title': '', 'bm25_score': x['score'], 'pid': x['pid']}) | |
temp['bm25_results'] = bm25 | |
new.append(temp) | |
print('writing..') | |
with jsonlines.open('./msmarco.jsonl', 'w') as writer: | |
writer.write_all(new) | |
print('done!') | |