khalidalt commited on
Commit
55bb2f7
1 Parent(s): e7d52dc

Update tydiqa-goldp.py

Browse files
Files changed (1) hide show
  1. tydiqa-goldp.py +24 -4
tydiqa-goldp.py CHANGED
@@ -105,7 +105,27 @@ class tydiqa_GoldP(datasets.GeneratorBasedBuilder):
105
  # TODO(tydiqa): Yields (key, example) tuples from the dataset
106
 
107
  with open(filepath, encoding="utf-8") as f:
108
- for row in f:
109
- data = json.loads(row)
110
- idx = data['id']
111
- yield idx, data
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  # TODO(tydiqa): Yields (key, example) tuples from the dataset
106
 
107
  with open(filepath, encoding="utf-8") as f:
108
+ data = json.load(f)
109
+ for article in data["data"]:
110
+ title = article.get("title", "").strip()
111
+ for paragraph in article["paragraphs"]:
112
+ context = paragraph["context"].strip()
113
+ for qa in paragraph["qas"]:
114
+ question = qa["question"].strip()
115
+ id_ = qa["id"]
116
+
117
+ answer_starts = [answer["answer_start"] for answer in qa["answers"]]
118
+ answers = [answer["text"].strip() for answer in qa["answers"]]
119
+
120
+ # Features currently used are "context", "question", and "answers".
121
+ # Others are extracted here for the ease of future expansions.
122
+ yield id_, {
123
+ "title": title,
124
+ "context": context,
125
+ "question": question,
126
+ "id": id_,
127
+ "answers": {
128
+ "answer_start": answer_starts,
129
+ "text": answers,
130
+ },
131
+ }