| import json | |
| def load_squad_json(path): | |
| with open(path, "r", encoding="utf-8") as f: | |
| data = json.load(f) | |
| samples = [] | |
| for article in data["data"]: | |
| for para in article["paragraphs"]: | |
| context = para["context"] | |
| for qa in para["qas"]: | |
| if not qa["answers"]: | |
| continue | |
| ans = qa["answers"][0] | |
| samples.append({ | |
| "context": context, | |
| "question": qa["question"], | |
| "answer_text": ans["text"] | |
| }) | |
| return samples | |