Datasets:

Tasks:
Other
Languages:
English
Multilinguality:
monolingual
Size Categories:
10K<n<100K
1M<n<10M
Language Creators:
found
Annotations Creators:
machine-generated
Source Datasets:
original
ArXiv:
Tags:
knowledge-base
License:
albertvillanova HF staff commited on
Commit
bceaf96
1 Parent(s): 7bd3fa9

Update loading script

Browse files
Files changed (1) hide show
  1. generics_kb.py +8 -50
generics_kb.py CHANGED
@@ -17,7 +17,6 @@
17
 
18
  import ast
19
  import csv
20
- import os
21
 
22
  import datasets
23
 
@@ -41,13 +40,13 @@ _HOMEPAGE = "https://allenai.org/data/genericskb"
41
 
42
  _LICENSE = "cc-by-4.0"
43
 
44
- _URL = "https://drive.google.com/u/0/uc?id={0}&export=download"
45
 
46
- _FILEPATHS = {
47
- "generics_kb_best": _URL.format("12DfIzoWyHIQqssgUgDvz3VG8_ScSh6ng"),
48
- "generics_kb": _URL.format("1UOIEzQTid7SzKx2tbwSSPxl7g-CjpoZa"),
49
- "generics_kb_simplewiki": _URL.format("1SpN9Qc7XRy5xs4tIfXkcLOEAP2IVaK15"),
50
- "generics_kb_waterloo": "cskb-waterloo-06-21-with-bert-scores.jsonl",
51
  }
52
 
53
 
@@ -60,7 +59,7 @@ class GenericsKb(datasets.GeneratorBasedBuilder):
60
  datasets.BuilderConfig(
61
  name="generics_kb_best",
62
  version=VERSION,
63
- description="This is the default and recommended config.Comprises of GENERICSKB generics with a score > 0.234 ",
64
  ),
65
  datasets.BuilderConfig(
66
  name="generics_kb", version=VERSION, description="This GENERICSKB that contains 3,433,000 sentences."
@@ -77,30 +76,10 @@ class GenericsKb(datasets.GeneratorBasedBuilder):
77
  ),
78
  ]
79
 
80
- @property
81
- def manual_download_instructions(self):
82
- return """\
83
- You need to manually download the files needed for the dataset config generics_kb_waterloo. The other configs like generics_kb_best don't need manual downloads.
84
- The <path/to/folder> can e.g. be `~/Downloads/GenericsKB`. Download the following required files from https://drive.google.com/drive/folders/1vqfVXhJXJWuiiXbUa4rZjOgQoJvwZUoT
85
- For working on "generics_kb_waterloo" data,
86
- 1. Manually download 'GenericsKB-Waterloo-WithContext.jsonl.zip' into your <path/to/folder>.Please ensure the filename is as is.
87
- The Waterloo is also generics from GenericsKB.tsv, but expanded to also include their surrounding context (before/after sentences). The Waterloo generics are the majority of GenericsKB. This zip file is 1.4GB expanding to 5.5GB.
88
- 2. Extract the GenericsKB-Waterloo-WithContext.jsonl.zip; It will create a file of 5.5 GB called cskb-waterloo-06-21-with-bert-scores.jsonl.
89
- Ensure you move this file into your <path/to/folder>.
90
-
91
- generics_kb can then be loaded using the following commands based on which data you want to work on. Data files must be present in the <path/to/folder> if using "generics_kb_waterloo" config.
92
- 1. `datasets.load_dataset("generics_kb","generics_kb_best")`.
93
- 2. `datasets.load_dataset("generics_kb","generics_kb")`
94
- 3. `datasets.load_dataset("generics_kb","generics_kb_simplewiki")`
95
- 4. `datasets.load_dataset("generics_kb","generics_kb_waterloo", data_dir="<path/to/folder>")`
96
-
97
- """
98
-
99
  DEFAULT_CONFIG_NAME = "generics_kb_best"
100
 
101
  def _info(self):
102
  if self.config.name == "generics_kb_waterloo" or self.config.name == "generics_kb_simplewiki":
103
-
104
  featuredict = {
105
  "source_name": datasets.Value("string"),
106
  "sentence": datasets.Value("string"),
@@ -118,7 +97,6 @@ class GenericsKb(datasets.GeneratorBasedBuilder):
118
  features = datasets.Features(featuredict)
119
 
120
  else:
121
-
122
  features = datasets.Features(
123
  {
124
  "source": datasets.Value("string"),
@@ -148,24 +126,7 @@ class GenericsKb(datasets.GeneratorBasedBuilder):
148
  )
149
 
150
  def _split_generators(self, dl_manager):
151
-
152
- if self.config.name == "generics_kb_waterloo":
153
- data_dir = os.path.abspath(os.path.expanduser(dl_manager.manual_dir))
154
- # check if manual folder exists
155
- if not os.path.exists(data_dir):
156
- raise FileNotFoundError(
157
- f"{data_dir} does not exist. Make sure you insert a manual dir via `datasets.load_dataset('generics_kb', data_dir=...)`. Manual download instructions: {self.manual_download_instructions})"
158
- )
159
-
160
- # Check if required files exist in the folder
161
- filepath = os.path.join(data_dir, _FILEPATHS[self.config.name])
162
-
163
- if not os.path.exists(filepath):
164
- raise FileNotFoundError(
165
- f"{filepath} does not exist. Make sure you required files are present in {data_dir} `. Manual download instructions: {self.manual_download_instructions})"
166
- )
167
- else:
168
- filepath = dl_manager.download(_FILEPATHS[self.config.name])
169
 
170
  return [
171
  datasets.SplitGenerator(
@@ -181,7 +142,6 @@ class GenericsKb(datasets.GeneratorBasedBuilder):
181
  """Yields examples."""
182
 
183
  if self.config.name == "generics_kb_waterloo" or self.config.name == "generics_kb_simplewiki":
184
-
185
  with open(filepath, encoding="utf-8") as f:
186
  for id_, row in enumerate(f):
187
  data = ast.literal_eval(row)
@@ -202,7 +162,6 @@ class GenericsKb(datasets.GeneratorBasedBuilder):
202
 
203
  yield id_, result
204
  else:
205
-
206
  with open(filepath, encoding="utf-8") as f:
207
  # Skip the header
208
  next(f)
@@ -210,7 +169,6 @@ class GenericsKb(datasets.GeneratorBasedBuilder):
210
  read_tsv = csv.reader(f, delimiter="\t")
211
 
212
  for id_, row in enumerate(read_tsv):
213
-
214
  quantifier = row[2]
215
  quantifier_frequency = ""
216
  quantifier_number = ""
 
17
 
18
  import ast
19
  import csv
 
20
 
21
  import datasets
22
 
 
40
 
41
  _LICENSE = "cc-by-4.0"
42
 
43
+ _BASE_URL = "data/{0}"
44
 
45
+ _URLS = {
46
+ "generics_kb_best": _BASE_URL.format("GenericsKB-Best.tsv.gz"),
47
+ "generics_kb": _BASE_URL.format("GenericsKB.tsv.gz"),
48
+ "generics_kb_simplewiki": _BASE_URL.format("GenericsKB-SimpleWiki-With-Context.jsonl.gz"),
49
+ "generics_kb_waterloo": _BASE_URL.format("GenericsKB-Waterloo-With-Context.jsonl.gz"),
50
  }
51
 
52
 
 
59
  datasets.BuilderConfig(
60
  name="generics_kb_best",
61
  version=VERSION,
62
+ description="This is the default and recommended config. Comprises of GENERICSKB generics with a score > 0.234 ",
63
  ),
64
  datasets.BuilderConfig(
65
  name="generics_kb", version=VERSION, description="This GENERICSKB that contains 3,433,000 sentences."
 
76
  ),
77
  ]
78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  DEFAULT_CONFIG_NAME = "generics_kb_best"
80
 
81
  def _info(self):
82
  if self.config.name == "generics_kb_waterloo" or self.config.name == "generics_kb_simplewiki":
 
83
  featuredict = {
84
  "source_name": datasets.Value("string"),
85
  "sentence": datasets.Value("string"),
 
97
  features = datasets.Features(featuredict)
98
 
99
  else:
 
100
  features = datasets.Features(
101
  {
102
  "source": datasets.Value("string"),
 
126
  )
127
 
128
  def _split_generators(self, dl_manager):
129
+ filepath = dl_manager.download_and_extract(_URLS[self.config.name])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
 
131
  return [
132
  datasets.SplitGenerator(
 
142
  """Yields examples."""
143
 
144
  if self.config.name == "generics_kb_waterloo" or self.config.name == "generics_kb_simplewiki":
 
145
  with open(filepath, encoding="utf-8") as f:
146
  for id_, row in enumerate(f):
147
  data = ast.literal_eval(row)
 
162
 
163
  yield id_, result
164
  else:
 
165
  with open(filepath, encoding="utf-8") as f:
166
  # Skip the header
167
  next(f)
 
169
  read_tsv = csv.reader(f, delimiter="\t")
170
 
171
  for id_, row in enumerate(read_tsv):
 
172
  quantifier = row[2]
173
  quantifier_frequency = ""
174
  quantifier_number = ""