system HF staff commited on
Commit
beb3616
1 Parent(s): 34891d3

Update files from the datasets library (from 1.16.0)

Browse files

Release notes: https://github.com/huggingface/datasets/releases/tag/1.16.0

Files changed (2) hide show
  1. README.md +1 -0
  2. paws.py +39 -38
README.md CHANGED
@@ -1,4 +1,5 @@
1
  ---
 
2
  annotations_creators:
3
  labeled_final:
4
  - expert-generated
 
1
  ---
2
+ pretty_name: "PAWS: Paraphrase Adversaries from Word Scrambling"
3
  annotations_creators:
4
  labeled_final:
5
  - expert-generated
paws.py CHANGED
@@ -16,7 +16,6 @@
16
 
17
 
18
  import csv
19
- import os
20
 
21
  import datasets
22
 
@@ -112,19 +111,19 @@ class PAWS(datasets.GeneratorBasedBuilder):
112
  """Returns SplitGenerators."""
113
 
114
  _DATA_URL = f"https://storage.googleapis.com/paws/english/paws_wiki_{self.config.name}.tar.gz"
115
- data_dir = dl_manager.download_and_extract(_DATA_URL)
116
 
117
  if self.config.name == "labeled_final":
118
- _TRAIN_FILE_NAME = os.path.join(data_dir, "final", "train.tsv")
119
- _VAL_FILE_NAME = os.path.join(data_dir, "final", "dev.tsv")
120
- _TEST_FILE_NAME = os.path.join(data_dir, "final", "test.tsv")
121
  return [
122
  datasets.SplitGenerator(
123
  name=datasets.Split.TRAIN,
124
  # These kwargs will be passed to _generate_examples
125
  gen_kwargs={
126
  "filepath": _TRAIN_FILE_NAME,
127
- "split": datasets.Split.TRAIN,
128
  },
129
  ),
130
  datasets.SplitGenerator(
@@ -132,7 +131,7 @@ class PAWS(datasets.GeneratorBasedBuilder):
132
  # These kwargs will be passed to _generate_examples
133
  gen_kwargs={
134
  "filepath": _TEST_FILE_NAME,
135
- "split": datasets.Split.TEST,
136
  },
137
  ),
138
  datasets.SplitGenerator(
@@ -140,34 +139,34 @@ class PAWS(datasets.GeneratorBasedBuilder):
140
  # These kwargs will be passed to _generate_examples
141
  gen_kwargs={
142
  "filepath": _VAL_FILE_NAME,
143
- "split": datasets.Split.VALIDATION,
144
  },
145
  ),
146
  ]
147
 
148
  elif self.config.name == "labeled_swap":
149
- _TRAIN_FILE_NAME = os.path.join(data_dir, "swap", "train.tsv")
150
  return [
151
  datasets.SplitGenerator(
152
  name=datasets.Split.TRAIN,
153
  # These kwargs will be passed to _generate_examples
154
  gen_kwargs={
155
  "filepath": _TRAIN_FILE_NAME,
156
- "split": datasets.Split.TRAIN,
157
  },
158
  ),
159
  ]
160
 
161
  elif self.config.name == "unlabeled_final":
162
- _TRAIN_FILE_NAME = os.path.join(data_dir, "unlabeled", "final", "train.tsv")
163
- _VAL_FILE_NAME = os.path.join(data_dir, "unlabeled", "final", "dev.tsv")
164
  return [
165
  datasets.SplitGenerator(
166
  name=datasets.Split.TRAIN,
167
  # These kwargs will be passed to _generate_examples
168
  gen_kwargs={
169
  "filepath": _TRAIN_FILE_NAME,
170
- "split": datasets.Split.TRAIN,
171
  },
172
  ),
173
  datasets.SplitGenerator(
@@ -175,34 +174,36 @@ class PAWS(datasets.GeneratorBasedBuilder):
175
  # These kwargs will be passed to _generate_examples
176
  gen_kwargs={
177
  "filepath": _VAL_FILE_NAME,
178
- "split": datasets.Split.VALIDATION,
179
  },
180
  ),
181
  ]
182
  else:
183
- raise NotImplementedError("{} does not exist".format(self.config.name))
184
 
185
- def _generate_examples(self, filepath, split):
186
  """Yields examples."""
187
-
188
- with open(filepath, encoding="utf-8") as f:
189
- data = csv.DictReader(f, delimiter="\t")
190
- for id_, row in enumerate(data):
191
- if self.config.name != "unlabeled_final":
192
- if row["label"] not in ["0", "1"]:
193
- row["label"] = -1
194
- yield id_, {
195
- "id": row["id"],
196
- "sentence1": row["sentence1"],
197
- "sentence2": row["sentence2"],
198
- "label": row["label"],
199
- }
200
- else:
201
- if row["noisy_label"] not in ["0", "1"]:
202
- row["noisy_label"] = -1
203
- yield id_, {
204
- "id": row["id"],
205
- "sentence1": row["sentence1"],
206
- "sentence2": row["sentence2"],
207
- "label": row["noisy_label"],
208
- }
 
 
 
16
 
17
 
18
  import csv
 
19
 
20
  import datasets
21
 
 
111
  """Returns SplitGenerators."""
112
 
113
  _DATA_URL = f"https://storage.googleapis.com/paws/english/paws_wiki_{self.config.name}.tar.gz"
114
+ archive = dl_manager.download(_DATA_URL)
115
 
116
  if self.config.name == "labeled_final":
117
+ _TRAIN_FILE_NAME = "/".join(["final", "train.tsv"])
118
+ _VAL_FILE_NAME = "/".join(["final", "dev.tsv"])
119
+ _TEST_FILE_NAME = "/".join(["final", "test.tsv"])
120
  return [
121
  datasets.SplitGenerator(
122
  name=datasets.Split.TRAIN,
123
  # These kwargs will be passed to _generate_examples
124
  gen_kwargs={
125
  "filepath": _TRAIN_FILE_NAME,
126
+ "files": dl_manager.iter_archive(archive),
127
  },
128
  ),
129
  datasets.SplitGenerator(
 
131
  # These kwargs will be passed to _generate_examples
132
  gen_kwargs={
133
  "filepath": _TEST_FILE_NAME,
134
+ "files": dl_manager.iter_archive(archive),
135
  },
136
  ),
137
  datasets.SplitGenerator(
 
139
  # These kwargs will be passed to _generate_examples
140
  gen_kwargs={
141
  "filepath": _VAL_FILE_NAME,
142
+ "files": dl_manager.iter_archive(archive),
143
  },
144
  ),
145
  ]
146
 
147
  elif self.config.name == "labeled_swap":
148
+ _TRAIN_FILE_NAME = "/".join(["swap", "train.tsv"])
149
  return [
150
  datasets.SplitGenerator(
151
  name=datasets.Split.TRAIN,
152
  # These kwargs will be passed to _generate_examples
153
  gen_kwargs={
154
  "filepath": _TRAIN_FILE_NAME,
155
+ "files": dl_manager.iter_archive(archive),
156
  },
157
  ),
158
  ]
159
 
160
  elif self.config.name == "unlabeled_final":
161
+ _TRAIN_FILE_NAME = "/".join(["unlabeled", "final", "train.tsv"])
162
+ _VAL_FILE_NAME = "/".join(["unlabeled", "final", "dev.tsv"])
163
  return [
164
  datasets.SplitGenerator(
165
  name=datasets.Split.TRAIN,
166
  # These kwargs will be passed to _generate_examples
167
  gen_kwargs={
168
  "filepath": _TRAIN_FILE_NAME,
169
+ "files": dl_manager.iter_archive(archive),
170
  },
171
  ),
172
  datasets.SplitGenerator(
 
174
  # These kwargs will be passed to _generate_examples
175
  gen_kwargs={
176
  "filepath": _VAL_FILE_NAME,
177
+ "files": dl_manager.iter_archive(archive),
178
  },
179
  ),
180
  ]
181
  else:
182
+ raise NotImplementedError(f"{self.config.name} does not exist")
183
 
184
+ def _generate_examples(self, filepath, files):
185
  """Yields examples."""
186
+ for path, f in files:
187
+ if path == filepath:
188
+ lines = (line.decode("utf-8") for line in f)
189
+ data = csv.DictReader(lines, delimiter="\t")
190
+ for id_, row in enumerate(data):
191
+ if self.config.name != "unlabeled_final":
192
+ if row["label"] not in ["0", "1"]:
193
+ row["label"] = -1
194
+ yield id_, {
195
+ "id": row["id"],
196
+ "sentence1": row["sentence1"],
197
+ "sentence2": row["sentence2"],
198
+ "label": row["label"],
199
+ }
200
+ else:
201
+ if row["noisy_label"] not in ["0", "1"]:
202
+ row["noisy_label"] = -1
203
+ yield id_, {
204
+ "id": row["id"],
205
+ "sentence1": row["sentence1"],
206
+ "sentence2": row["sentence2"],
207
+ "label": row["noisy_label"],
208
+ }
209
+ break