SQuAD / data_loader /load_squad_json.py
tnp554's picture
feat: deploy SQuAD backend with all AI models
09daf0b
raw
history blame contribute delete
601 Bytes
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