import os import json from datasets import load_dataset data = load_dataset("lmqg/qg_tweetqa") def process(tmp): tmp = [i.to_dict() for _, i in tmp.iterrows()] for i in tmp: i.pop('paragraph_question') i.pop('question') i['text'] = i.pop("paragraph") i['condition'] = f'Keyword: {i.pop("answer")}' tmp = [i for i in tmp if 'http' not in i['text']] return tmp train = process(data["train"].to_pandas()) val = process(data["validation"].to_pandas()) test = process(data["test"].to_pandas()) os.makedirs("dataset/qa", exist_ok=True) with open("dataset/qa/train.jsonl", "w") as f: f.write("\n".join([json.dumps(i) for i in train])) with open("dataset/qa/validation.jsonl", "w") as f: f.write("\n".join([json.dumps(i) for i in val])) with open("dataset/qa/test.jsonl", "w") as f: f.write("\n".join([json.dumps(i) for i in test]))