Support streaming

#1
by albertvillanova HF staff - opened
Files changed (1) hide show
  1. ehr_rel.py +17 -19
ehr_rel.py CHANGED
@@ -30,7 +30,7 @@ from .bigbiohub import pairs_features
30
  from .bigbiohub import BigBioConfig
31
  from .bigbiohub import Tasks
32
 
33
- _LANGUAGES = ['English']
34
  _PUBMED = False
35
  _LOCAL = False
36
  _CITATION = """\
@@ -64,10 +64,13 @@ A detailed analysis of the concepts in the dataset reveals a far larger coverage
64
 
65
  _HOMEPAGE = "https://github.com/babylonhealth/EHR-Rel"
66
 
67
- _LICENSE = 'Apache License 2.0'
68
 
69
  _URLS = {
70
- _DATASETNAME: "https://github.com/babylonhealth/EHR-Rel/archive/refs/heads/master.zip",
 
 
 
71
  }
72
 
73
  _SUPPORTED_TASKS = [Tasks.SEMANTIC_SIMILARITY]
@@ -152,30 +155,25 @@ class EHRRelDataset(datasets.GeneratorBasedBuilder):
152
  def _split_generators(self, dl_manager) -> List[datasets.SplitGenerator]:
153
  """Returns SplitGenerators."""
154
  urls = _URLS[_DATASETNAME]
155
- data_dir = Path(dl_manager.download_and_extract(urls))
156
- data_dir = data_dir.joinpath("EHR-Rel-master")
 
 
 
 
157
  return [
158
  datasets.SplitGenerator(
159
- name=datasets.Split.TRAIN,
160
- gen_kwargs={"data_dir": data_dir},
161
  ),
162
  ]
163
 
164
- def _generate_examples(self, data_dir: Path) -> Iterator[Tuple[str, Dict]]:
165
-
166
- if self.config.subset_id == "ehr_rel_a":
167
- files = ["EHR-RelA.tsv"]
168
- elif self.config.subset_id == "ehr_rel_b":
169
- files = ["EHR-RelB.tsv"]
170
- else:
171
- files = ["EHR-RelA.tsv", "EHR-RelB.tsv"]
172
 
173
  uid = -1 # want first instance to be 0
174
 
175
- for filename in files:
176
- file = data_dir.joinpath(filename)
177
- document_id = str(file.stem)
178
- with open(file, encoding="utf-8") as csv_file:
179
  csv_reader = csv.reader(csv_file, quotechar='"', delimiter="\t")
180
  next(csv_reader, None) # remove column headers
181
  for id_, row in enumerate(csv_reader):
 
30
  from .bigbiohub import BigBioConfig
31
  from .bigbiohub import Tasks
32
 
33
+ _LANGUAGES = ["English"]
34
  _PUBMED = False
35
  _LOCAL = False
36
  _CITATION = """\
 
64
 
65
  _HOMEPAGE = "https://github.com/babylonhealth/EHR-Rel"
66
 
67
+ _LICENSE = "Apache License 2.0"
68
 
69
  _URLS = {
70
+ _DATASETNAME: {
71
+ "ehr_rel_a": "https://raw.githubusercontent.com/babylonhealth/EHR-Rel/master/EHR-RelA.tsv",
72
+ "ehr_rel_b": "https://raw.githubusercontent.com/babylonhealth/EHR-Rel/master/EHR-RelB.tsv",
73
+ },
74
  }
75
 
76
  _SUPPORTED_TASKS = [Tasks.SEMANTIC_SIMILARITY]
 
155
  def _split_generators(self, dl_manager) -> List[datasets.SplitGenerator]:
156
  """Returns SplitGenerators."""
157
  urls = _URLS[_DATASETNAME]
158
+ urls = (
159
+ [urls[self.config.subset_id]]
160
+ if self.config.subset_id in urls
161
+ else list(urls.values())
162
+ )
163
+ paths = dl_manager.download(urls)
164
  return [
165
  datasets.SplitGenerator(
166
+ name=datasets.Split.TRAIN, gen_kwargs={"paths": paths},
 
167
  ),
168
  ]
169
 
170
+ def _generate_examples(self, paths: List[str]) -> Iterator[Tuple[str, Dict]]:
 
 
 
 
 
 
 
171
 
172
  uid = -1 # want first instance to be 0
173
 
174
+ for path in paths:
175
+ document_id = Path(path).stem
176
+ with open(path, encoding="utf-8", newline="") as csv_file:
 
177
  csv_reader = csv.reader(csv_file, quotechar='"', delimiter="\t")
178
  next(csv_reader, None) # remove column headers
179
  for id_, row in enumerate(csv_reader):