File size: 601 Bytes
09daf0b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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