drAbreu commited on
Commit
eda8b24
1 Parent(s): f980ccb

All tasks working

Browse files
Files changed (1) hide show
  1. sd-nlp-non-tokenized.py +28 -19
sd-nlp-non-tokenized.py CHANGED
@@ -19,9 +19,7 @@
19
  from __future__ import absolute_import, division, print_function
20
 
21
  import json
22
- import pdb
23
  import datasets
24
- import os
25
 
26
  _BASE_URL = "https://huggingface.co/datasets/EMBO/sd-nlp-non-tokenized/resolve/main/"
27
 
@@ -71,8 +69,6 @@ class SourceDataNLP(datasets.GeneratorBasedBuilder):
71
 
72
  _URLS = {
73
  "NER": f"{_BASE_URL}sd_panels_general_tokenization.zip",
74
- "ROLES": f"{_BASE_URL}sd_panels_general_tokenization.zip",
75
- "BORING": f"{_BASE_URL}sd_panels_general_tokenization.zip",
76
  "PANELIZATION": f"{_BASE_URL}sd_fig_general_tokenization.zip",
77
  }
78
  BUILDER_CONFIGS = [
@@ -95,49 +91,57 @@ class SourceDataNLP(datasets.GeneratorBasedBuilder):
95
  {
96
  "words": datasets.Sequence(feature=datasets.Value("string")),
97
  "labels": datasets.Sequence(
98
- feature=datasets.ClassLabel(num_classes=len(self._NER_LABEL_NAMES), names=self._NER_LABEL_NAMES)
 
99
  ),
 
100
  }
101
  )
102
  elif self.config.name == "GENEPROD_ROLES":
103
  features = datasets.Features(
104
  {
105
- "input_ids": datasets.Sequence(feature=datasets.Value("string")),
106
  "labels": datasets.Sequence(
107
  feature=datasets.ClassLabel(
108
- num_classes=len(self._SEMANTIC_GENEPROD_ROLES_LABEL_NAMES), names=self._SEMANTIC_GENEPROD_ROLES_LABEL_NAMES
 
109
  )
110
  ),
111
-
112
  }
113
  )
114
  elif self.config.name == "SMALL_MOL_ROLES":
115
  features = datasets.Features(
116
  {
117
- "input_ids": datasets.Sequence(feature=datasets.Value("string")),
118
  "labels": datasets.Sequence(
119
  feature=datasets.ClassLabel(
120
- num_classes=len(self._SEMANTIC_SMALL_MOL_ROLES_LABEL_NAMES), names=self._SEMANTIC_SMALL_MOL_ROLES_LABEL_NAMES
 
121
  )
122
  ),
 
123
  }
124
  )
125
  elif self.config.name == "BORING":
126
  features = datasets.Features(
127
  {
128
- "input_ids": datasets.Sequence(feature=datasets.Value("string")),
129
  "labels": datasets.Sequence(
130
- feature=datasets.ClassLabel(num_classes=len(self._BORING_LABEL_NAMES), names=self._BORING_LABEL_NAMES)
 
131
  ),
132
  }
133
  )
134
  elif self.config.name == "PANELIZATION":
135
  features = datasets.Features(
136
  {
137
- "input_ids": datasets.Sequence(feature=datasets.Value("string")),
138
  "labels": datasets.Sequence(
139
- feature=datasets.ClassLabel(num_classes=len(self._PANEL_START_NAMES), names=self._PANEL_START_NAMES)
 
140
  ),
 
141
  }
142
  )
143
 
@@ -153,11 +157,14 @@ class SourceDataNLP(datasets.GeneratorBasedBuilder):
153
  def _split_generators(self, dl_manager: datasets.DownloadManager):
154
  """Returns SplitGenerators.
155
  Uses local files if a data_dir is specified. Otherwise downloads the files from their official url."""
156
- url = self._URLS[self.config.name]
157
- data_dir = dl_manager.download_and_extract(url)
158
  if self.config.name in ["NER", "GENEPROD_ROLES", "SMALL_MOL_ROLES", "BORING"]:
 
 
159
  data_dir += "/sd_panels_general_tokenization"
160
  elif self.config.name == "PANELIZATION":
 
 
161
  data_dir += "/sd_fig_general_tokenization"
162
  else:
163
  raise ValueError(f"unkonwn config name: {self.config.name}")
@@ -185,6 +192,7 @@ class SourceDataNLP(datasets.GeneratorBasedBuilder):
185
  """Yields examples. This method will receive as arguments the `gen_kwargs` defined in the previous `_split_generators` method.
186
  It is in charge of opening the given file and yielding (key, example) tuples from the dataset
187
  The key is not important, it's more here for legacy reason (legacy from tfds)"""
 
188
 
189
  with open(filepath, encoding="utf-8") as f:
190
  # logger.info("⏳ Generating examples from = %s", filepath)
@@ -208,7 +216,7 @@ class SourceDataNLP(datasets.GeneratorBasedBuilder):
208
  "tag_mask": tag_mask,
209
  }
210
  elif self.config.name == "SMALL_MOL_ROLES":
211
- labels = data["words"]["small_mol_roles"]
212
  small_mol = ["B-SMALL_MOLECULE", "I-SMALL_MOLECULE"]
213
  tag_mask = [1 if t in small_mol else 0 for t in labels]
214
  yield id_, {
@@ -217,12 +225,13 @@ class SourceDataNLP(datasets.GeneratorBasedBuilder):
217
  "tag_mask": tag_mask,
218
  }
219
  elif self.config.name == "BORING":
220
- yield id_, {"words": data["words"], "labels": data["label_ids"]["boring"]}
 
221
  elif self.config.name == "PANELIZATION":
222
  labels = data["label_ids"]["panel_start"]
223
  tag_mask = [1 if t == "B-PANEL_START" else 0 for t in labels]
224
  yield id_, {
225
- "input_ids": data["words"],
226
  "labels": data["label_ids"]["panel_start"],
227
  "tag_mask": tag_mask,
228
  }
 
19
  from __future__ import absolute_import, division, print_function
20
 
21
  import json
 
22
  import datasets
 
23
 
24
  _BASE_URL = "https://huggingface.co/datasets/EMBO/sd-nlp-non-tokenized/resolve/main/"
25
 
 
69
 
70
  _URLS = {
71
  "NER": f"{_BASE_URL}sd_panels_general_tokenization.zip",
 
 
72
  "PANELIZATION": f"{_BASE_URL}sd_fig_general_tokenization.zip",
73
  }
74
  BUILDER_CONFIGS = [
 
91
  {
92
  "words": datasets.Sequence(feature=datasets.Value("string")),
93
  "labels": datasets.Sequence(
94
+ feature=datasets.ClassLabel(num_classes=len(self._NER_LABEL_NAMES),
95
+ names=self._NER_LABEL_NAMES)
96
  ),
97
+ "tag_mask": datasets.Sequence(feature=datasets.Value("int8")),
98
  }
99
  )
100
  elif self.config.name == "GENEPROD_ROLES":
101
  features = datasets.Features(
102
  {
103
+ "words": datasets.Sequence(feature=datasets.Value("string")),
104
  "labels": datasets.Sequence(
105
  feature=datasets.ClassLabel(
106
+ num_classes=len(self._SEMANTIC_GENEPROD_ROLES_LABEL_NAMES),
107
+ names=self._SEMANTIC_GENEPROD_ROLES_LABEL_NAMES
108
  )
109
  ),
110
+ "tag_mask": datasets.Sequence(feature=datasets.Value("int8")),
111
  }
112
  )
113
  elif self.config.name == "SMALL_MOL_ROLES":
114
  features = datasets.Features(
115
  {
116
+ "words": datasets.Sequence(feature=datasets.Value("string")),
117
  "labels": datasets.Sequence(
118
  feature=datasets.ClassLabel(
119
+ num_classes=len(self._SEMANTIC_SMALL_MOL_ROLES_LABEL_NAMES),
120
+ names=self._SEMANTIC_SMALL_MOL_ROLES_LABEL_NAMES
121
  )
122
  ),
123
+ "tag_mask": datasets.Sequence(feature=datasets.Value("int8")),
124
  }
125
  )
126
  elif self.config.name == "BORING":
127
  features = datasets.Features(
128
  {
129
+ "words": datasets.Sequence(feature=datasets.Value("string")),
130
  "labels": datasets.Sequence(
131
+ feature=datasets.ClassLabel(num_classes=len(self._BORING_LABEL_NAMES),
132
+ names=self._BORING_LABEL_NAMES)
133
  ),
134
  }
135
  )
136
  elif self.config.name == "PANELIZATION":
137
  features = datasets.Features(
138
  {
139
+ "words": datasets.Sequence(feature=datasets.Value("string")),
140
  "labels": datasets.Sequence(
141
+ feature=datasets.ClassLabel(num_classes=len(self._PANEL_START_NAMES),
142
+ names=self._PANEL_START_NAMES)
143
  ),
144
+ "tag_mask": datasets.Sequence(feature=datasets.Value("int8")),
145
  }
146
  )
147
 
 
157
  def _split_generators(self, dl_manager: datasets.DownloadManager):
158
  """Returns SplitGenerators.
159
  Uses local files if a data_dir is specified. Otherwise downloads the files from their official url."""
160
+
 
161
  if self.config.name in ["NER", "GENEPROD_ROLES", "SMALL_MOL_ROLES", "BORING"]:
162
+ url = self._URLS["NER"]
163
+ data_dir = dl_manager.download_and_extract(url)
164
  data_dir += "/sd_panels_general_tokenization"
165
  elif self.config.name == "PANELIZATION":
166
+ url = self._URLS[self.config.name]
167
+ data_dir = dl_manager.download_and_extract(url)
168
  data_dir += "/sd_fig_general_tokenization"
169
  else:
170
  raise ValueError(f"unkonwn config name: {self.config.name}")
 
192
  """Yields examples. This method will receive as arguments the `gen_kwargs` defined in the previous `_split_generators` method.
193
  It is in charge of opening the given file and yielding (key, example) tuples from the dataset
194
  The key is not important, it's more here for legacy reason (legacy from tfds)"""
195
+ print(" This line is taking place")
196
 
197
  with open(filepath, encoding="utf-8") as f:
198
  # logger.info("⏳ Generating examples from = %s", filepath)
 
216
  "tag_mask": tag_mask,
217
  }
218
  elif self.config.name == "SMALL_MOL_ROLES":
219
+ labels = data["label_ids"]["small_mol_roles"]
220
  small_mol = ["B-SMALL_MOLECULE", "I-SMALL_MOLECULE"]
221
  tag_mask = [1 if t in small_mol else 0 for t in labels]
222
  yield id_, {
 
225
  "tag_mask": tag_mask,
226
  }
227
  elif self.config.name == "BORING":
228
+ yield id_, {"words": data["words"],
229
+ "labels": data["label_ids"]["boring"]}
230
  elif self.config.name == "PANELIZATION":
231
  labels = data["label_ids"]["panel_start"]
232
  tag_mask = [1 if t == "B-PANEL_START" else 0 for t in labels]
233
  yield id_, {
234
+ "words": data["words"],
235
  "labels": data["label_ids"]["panel_start"],
236
  "tag_mask": tag_mask,
237
  }