Datasets:
rcds
/

Modalities:
Tabular
Text
Languages:
English
Libraries:
Datasets
License:
Skatinger commited on
Commit
e6fbd6e
1 Parent(s): e5d5d7b

Update wikipedia-for-mask-filling.py

Browse files
Files changed (1) hide show
  1. wikipedia-for-mask-filling.py +19 -15
wikipedia-for-mask-filling.py CHANGED
@@ -105,26 +105,30 @@ class WikipediaForMaskFilling(datasets.GeneratorBasedBuilder):
105
  def _split_generators(self, dl_manager):
106
  type = self.config.type
107
  size = self.config.size
108
- urls_to_download = f"data/{type}_{size}.jsonl.xz"
109
- downloaded_files = dl_manager.download_and_extract(urls_to_download)
110
 
111
  return [
112
- datasets.SplitGenerator(name='train', gen_kwargs={"filepath": downloaded_files}),
113
  ]
114
 
115
  def _generate_examples(self, filepath):
116
  _id = 0
117
  print("using filepaths:")
118
  print(filepath)
119
- with open(filepath, encoding="utf-8") as f:
120
- try:
121
- with xz.open(filepath) as f:
122
- for line in f:
123
- data = json.loads(line)
124
- yield _id, {
125
- "texts": data["texts"],
126
- "masks": data["masks"]
127
- }
128
- _id += 1
129
- except Exception:
130
- logger.exception("Error while processing file %s", filepath)
 
 
 
 
 
 
105
  def _split_generators(self, dl_manager):
106
  type = self.config.type
107
  size = self.config.size
108
+ filepath = dl_manager.download(f"data/{type}_{size}.jsonl.xz")
 
109
 
110
  return [
111
+ datasets.SplitGenerator(name='train', gen_kwargs={"filepath": filepath}),
112
  ]
113
 
114
  def _generate_examples(self, filepath):
115
  _id = 0
116
  print("using filepaths:")
117
  print(filepath)
118
+ if filepath:
119
+ logger.info("Generating examples from = %s", filepath)
120
+ try:
121
+ with xz.open(open(filepath,'rb'), 'rt', encoding='utf-8') as f:
122
+ json_list = list(f)
123
+
124
+ for json_str in json_list:
125
+ example = json.loads(json_str)
126
+ if example is not None and isinstance(example, dict):
127
+ yield id_, {
128
+ "texts": data["texts"],
129
+ "masks": data["masks"]
130
+ }
131
+ id_ +=1
132
+
133
+ except Exception:
134
+ logger.exception("Error while processing file %s", filepath)