Datasets:

Modalities:
Text
Languages:
Hebrew
ArXiv:
Libraries:
Datasets
imvladikon commited on
Commit
a5de7c0
1 Parent(s): 9dde379

Update parashoot.py

Browse files
Files changed (1) hide show
  1. parashoot.py +24 -22
parashoot.py CHANGED
@@ -1,5 +1,6 @@
1
  #!/usr/bin/env python3
2
  # -*- coding: utf-8 -*-
 
3
  import json
4
  import os
5
 
@@ -84,27 +85,27 @@ class Parashoot(datasets.GeneratorBasedBuilder):
84
  )
85
 
86
  def _split_generators(self, dl_manager):
87
- downloaded_files = dl_manager.download_and_extract(_URLS)
88
 
89
  return [
90
  datasets.SplitGenerator(
91
  name=datasets.Split.TRAIN,
92
  gen_kwargs={
93
- "filepath": downloaded_files["train"],
94
  "basename": "train.jsonl",
95
  },
96
  ),
97
  datasets.SplitGenerator(
98
  name=datasets.Split.VALIDATION,
99
  gen_kwargs={
100
- "filepath": downloaded_files["validation"],
101
  "basename": "dev.jsonl",
102
  },
103
  ),
104
  datasets.SplitGenerator(
105
  name=datasets.Split.TEST,
106
  gen_kwargs={
107
- "filepath": downloaded_files["test"],
108
  "basename": "test.jsonl",
109
  },
110
  ),
@@ -114,21 +115,22 @@ class Parashoot(datasets.GeneratorBasedBuilder):
114
  """This function returns the examples in the raw (text) form."""
115
  logger.info("generating examples from = %s", filepath)
116
  key = 0
117
- with open(os.path.join(filepath, basename), encoding="utf-8") as f:
118
- for line in f:
119
- article = json.loads(line)
120
- title = article.get("title", "")
121
- context = article["context"]
122
- answer_starts = article["answers"]["answer_start"]
123
- answers = article["answers"]["text"]
124
- yield key, {
125
- "title": title,
126
- "context": context,
127
- "question": article["question"],
128
- "id": article["id"],
129
- "answers": {
130
- "answer_start": answer_starts,
131
- "text": answers,
132
- },
133
- }
134
- key += 1
 
 
1
  #!/usr/bin/env python3
2
  # -*- coding: utf-8 -*-
3
+ import io
4
  import json
5
  import os
6
 
 
85
  )
86
 
87
  def _split_generators(self, dl_manager):
88
+ downloaded_files = dl_manager.download(_URLS)
89
 
90
  return [
91
  datasets.SplitGenerator(
92
  name=datasets.Split.TRAIN,
93
  gen_kwargs={
94
+ "filepath": dl_manager.iter_archive(downloaded_files["train"]),
95
  "basename": "train.jsonl",
96
  },
97
  ),
98
  datasets.SplitGenerator(
99
  name=datasets.Split.VALIDATION,
100
  gen_kwargs={
101
+ "filepath": dl_manager.iter_archive(downloaded_files["validation"]),
102
  "basename": "dev.jsonl",
103
  },
104
  ),
105
  datasets.SplitGenerator(
106
  name=datasets.Split.TEST,
107
  gen_kwargs={
108
+ "filepath": dl_manager.iter_archive(downloaded_files["test"]),
109
  "basename": "test.jsonl",
110
  },
111
  ),
 
115
  """This function returns the examples in the raw (text) form."""
116
  logger.info("generating examples from = %s", filepath)
117
  key = 0
118
+ for file_path, file_obj in filepath:
119
+ with io.BytesIO(file_obj.read()) as f:
120
+ for line in f:
121
+ article = json.loads(line)
122
+ title = article.get("title", "")
123
+ context = article["context"]
124
+ answer_starts = article["answers"]["answer_start"]
125
+ answers = article["answers"]["text"]
126
+ yield key, {
127
+ "title": title,
128
+ "context": context,
129
+ "question": article["question"],
130
+ "id": article["id"],
131
+ "answers": {
132
+ "answer_start": answer_starts,
133
+ "text": answers,
134
+ },
135
+ }
136
+ key += 1