Datasets:
Tasks:
Question Answering
Modalities:
Text
Sub-tasks:
extractive-qa
Languages:
English
Size:
10K - 100K
ArXiv:
License:
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) |