Datasets:
Tasks:
Question Answering
Modalities:
Text
Sub-tasks:
extractive-qa
Languages:
English
Size:
10K - 100K
ArXiv:
License:
File size: 1,837 Bytes
96f0ff3 90f9d23 96f0ff3 8de1925 96f0ff3 90f9d23 96f0ff3 8de1925 96f0ff3 8de1925 90f9d23 8de1925 |
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
import pandas as pd
import os
from tqdm import tqdm
import json
import shutil
directories = ['lifestyle', 'pooled', 'recreation', 'science', 'technology', 'writing'] #os.listdir()
for directory in directories:
print("Starting " + directory)
for file_type in ["dev", "test"]:
for question_type in ["qas.forum.jsonl", "qas.search.jsonl"]:
if directory != 'pooled':
with open('data/' + directory + "/" + file_type + "/metadata.jsonl", 'r', encoding="utf-8") as json_file:
metadata = list(json_file)
question_id_to_author = {}
for json_str in metadata:
current_row = json.loads(json_str)
question_id_to_author[current_row["question_id"]] = current_row["question_author"]
else:
question_id_to_author = {}
########################################################
with open(directory + "/" + file_type + "_" + question_type, 'r', encoding="utf-8") as json_file:
json_list = list(json_file)
revised_jsonl = []
for json_str in tqdm(json_list):
current_row = json.loads(json_str)
try:
current_row["question_author"] = question_id_to_author[current_row['qid']]
except:
current_row["question_author"] = ""
revised_jsonl.append(current_row)
########################################################
if not os.path.isdir(directory):
os.mkdir(directory)
with open(directory + "/" + file_type + "_" + question_type, 'w', encoding="utf-8") as outfile:
for entry in revised_jsonl:
json.dump(entry, outfile)
outfile.write('\n')
#with open(directory + "/" + file_type + question_type, 'w', encoding="utf-8") as fout:
# json.dump(data, fout)
#shutil.move('data/' + directory + "/" + file_type + "/" + question_type,
# directory + "/" + file_type + "_" + question_type) |