albertvillanova HF staff commited on
Commit
b6b76b7
1 Parent(s): 2dbcffe

Support streaming blimp dataset (#4016)

Browse files

* Support streaming blimp dataset

* Simplify code

* Add encoding

* Fix dataset card

Commit from https://github.com/huggingface/datasets/commit/e70732a60b2cab2f23b5d582542d884ffd0357bc

Files changed (2) hide show
  1. README.md +17 -1
  2. blimp.py +8 -19
README.md CHANGED
@@ -1,8 +1,24 @@
1
  ---
 
 
 
 
2
  languages:
3
  - en
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  paperswithcode_id: blimp
5
- pretty_name: Benchmark of Linguistic Minimal Pairs
6
  ---
7
 
8
  # Dataset Card for "blimp"
1
  ---
2
+ annotations_creators:
3
+ - crowdsourced
4
+ language_creators:
5
+ - machine-generated
6
  languages:
7
  - en
8
+ licenses:
9
+ - unknown
10
+ multilinguality:
11
+ - monolingual
12
+ pretty_name: BLiMP
13
+ size_categories:
14
+ - "10K<n<100K"
15
+ source_datasets:
16
+ - original
17
+ task_categories:
18
+ - text-classification
19
+ task_ids:
20
+ - acceptability-classification
21
  paperswithcode_id: blimp
 
22
  ---
23
 
24
  # Dataset Card for "blimp"
blimp.py CHANGED
@@ -46,21 +46,17 @@ _DOWNLOAD_URL = "https://raw.githubusercontent.com/alexwarstadt/blimp/master/"
46
  class BlimpConfig(datasets.BuilderConfig):
47
  """BuilderConfig for Blimp."""
48
 
49
- def __init__(self, paradigm_uid, **kwargs):
50
  """BuilderConfig for Blimp.
51
 
52
  Args:
53
- paradigm_uid: string, UID of the linguistic paradigm
54
  **kwargs: keyword arguments forwarded to super.
55
  """
56
- name = paradigm_uid
57
-
58
  description = _DESCRIPTION
59
  description += f"This configuration includes the paradigm {name}."
60
 
61
- super(BlimpConfig, self).__init__(
62
- name=name, description=description, version=datasets.Version("0.1.0"), **kwargs
63
- )
64
 
65
 
66
  class Blimp(datasets.GeneratorBasedBuilder):
@@ -136,7 +132,7 @@ class Blimp(datasets.GeneratorBasedBuilder):
136
  "wh_vs_that_with_gap_long_distance",
137
  ]
138
 
139
- BUILDER_CONFIGS = [BlimpConfig(paradigm_uid=paradigm) for paradigm in all_paradigms]
140
 
141
  def _info(self):
142
  return datasets.DatasetInfo(
@@ -155,26 +151,19 @@ class Blimp(datasets.GeneratorBasedBuilder):
155
  "pair_id": datasets.Value("int32"),
156
  }
157
  ),
158
- supervised_keys=None,
159
- # Homepage of the dataset for documentation
160
  homepage=_PROJECT_URL,
161
  citation=_CITATION,
162
  )
163
 
164
  def _split_generators(self, dl_manager):
165
  """Returns SplitGenerators."""
166
- cfg = self.config
167
- download_urls = {cfg.name: _DOWNLOAD_URL + f"data/{cfg.name}.jsonl"}
168
-
169
- downloaded_files = dl_manager.download_and_extract(download_urls)
170
-
171
- return [
172
- datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files[cfg.name]})
173
- ]
174
 
175
  def _generate_examples(self, filepath):
176
  """Yields examples."""
177
- with open(filepath, "rb") as f:
178
  for line in f:
179
  line_dict = json.loads(line)
180
  id_ = line_dict["UID"] + "_" + line_dict["pairID"]
46
  class BlimpConfig(datasets.BuilderConfig):
47
  """BuilderConfig for Blimp."""
48
 
49
+ def __init__(self, name, version=datasets.Version("0.1.0"), **kwargs):
50
  """BuilderConfig for Blimp.
51
 
52
  Args:
53
+ name (str): UID of the linguistic paradigm
54
  **kwargs: keyword arguments forwarded to super.
55
  """
 
 
56
  description = _DESCRIPTION
57
  description += f"This configuration includes the paradigm {name}."
58
 
59
+ super().__init__(name=name, description=description, version=version, **kwargs)
 
 
60
 
61
 
62
  class Blimp(datasets.GeneratorBasedBuilder):
132
  "wh_vs_that_with_gap_long_distance",
133
  ]
134
 
135
+ BUILDER_CONFIGS = [BlimpConfig(paradigm) for paradigm in all_paradigms]
136
 
137
  def _info(self):
138
  return datasets.DatasetInfo(
151
  "pair_id": datasets.Value("int32"),
152
  }
153
  ),
 
 
154
  homepage=_PROJECT_URL,
155
  citation=_CITATION,
156
  )
157
 
158
  def _split_generators(self, dl_manager):
159
  """Returns SplitGenerators."""
160
+ download_urls = _DOWNLOAD_URL + f"data/{self.config.name}.jsonl"
161
+ downloaded_file = dl_manager.download_and_extract(download_urls)
162
+ return [datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_file})]
 
 
 
 
 
163
 
164
  def _generate_examples(self, filepath):
165
  """Yields examples."""
166
+ with open(filepath, "r", encoding="utf-8") as f:
167
  for line in f:
168
  line_dict = json.loads(line)
169
  id_ = line_dict["UID"] + "_" + line_dict["pairID"]