albertvillanova HF staff commited on
Commit
11762d9
1 Parent(s): 9236b36

Delete loading script

Browse files
Files changed (1) hide show
  1. glue.py +0 -628
glue.py DELETED
@@ -1,628 +0,0 @@
1
- # coding=utf-8
2
- # Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
3
- #
4
- # Licensed under the Apache License, Version 2.0 (the "License");
5
- # you may not use this file except in compliance with the License.
6
- # You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS,
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- # See the License for the specific language governing permissions and
14
- # limitations under the License.
15
-
16
- # Lint as: python3
17
- """The General Language Understanding Evaluation (GLUE) benchmark."""
18
-
19
-
20
- import csv
21
- import os
22
- import textwrap
23
-
24
- import numpy as np
25
-
26
- import datasets
27
-
28
-
29
- _GLUE_CITATION = """\
30
- @inproceedings{wang2019glue,
31
- title={{GLUE}: A Multi-Task Benchmark and Analysis Platform for Natural Language Understanding},
32
- author={Wang, Alex and Singh, Amanpreet and Michael, Julian and Hill, Felix and Levy, Omer and Bowman, Samuel R.},
33
- note={In the Proceedings of ICLR.},
34
- year={2019}
35
- }
36
- """
37
-
38
- _GLUE_DESCRIPTION = """\
39
- GLUE, the General Language Understanding Evaluation benchmark
40
- (https://gluebenchmark.com/) is a collection of resources for training,
41
- evaluating, and analyzing natural language understanding systems.
42
-
43
- """
44
-
45
- _MRPC_DEV_IDS = "https://dl.fbaipublicfiles.com/glue/data/mrpc_dev_ids.tsv"
46
- _MRPC_TRAIN = "https://dl.fbaipublicfiles.com/senteval/senteval_data/msr_paraphrase_train.txt"
47
- _MRPC_TEST = "https://dl.fbaipublicfiles.com/senteval/senteval_data/msr_paraphrase_test.txt"
48
-
49
- _MNLI_BASE_KWARGS = dict(
50
- text_features={
51
- "premise": "sentence1",
52
- "hypothesis": "sentence2",
53
- },
54
- label_classes=["entailment", "neutral", "contradiction"],
55
- label_column="gold_label",
56
- data_url="https://dl.fbaipublicfiles.com/glue/data/MNLI.zip",
57
- data_dir="MNLI",
58
- citation=textwrap.dedent(
59
- """\
60
- @InProceedings{N18-1101,
61
- author = "Williams, Adina
62
- and Nangia, Nikita
63
- and Bowman, Samuel",
64
- title = "A Broad-Coverage Challenge Corpus for
65
- Sentence Understanding through Inference",
66
- booktitle = "Proceedings of the 2018 Conference of
67
- the North American Chapter of the
68
- Association for Computational Linguistics:
69
- Human Language Technologies, Volume 1 (Long
70
- Papers)",
71
- year = "2018",
72
- publisher = "Association for Computational Linguistics",
73
- pages = "1112--1122",
74
- location = "New Orleans, Louisiana",
75
- url = "http://aclweb.org/anthology/N18-1101"
76
- }
77
- @article{bowman2015large,
78
- title={A large annotated corpus for learning natural language inference},
79
- author={Bowman, Samuel R and Angeli, Gabor and Potts, Christopher and Manning, Christopher D},
80
- journal={arXiv preprint arXiv:1508.05326},
81
- year={2015}
82
- }"""
83
- ),
84
- url="http://www.nyu.edu/projects/bowman/multinli/",
85
- )
86
-
87
-
88
- class GlueConfig(datasets.BuilderConfig):
89
- """BuilderConfig for GLUE."""
90
-
91
- def __init__(
92
- self,
93
- text_features,
94
- label_column,
95
- data_url,
96
- data_dir,
97
- citation,
98
- url,
99
- label_classes=None,
100
- process_label=lambda x: x,
101
- **kwargs,
102
- ):
103
- """BuilderConfig for GLUE.
104
-
105
- Args:
106
- text_features: `dict[string, string]`, map from the name of the feature
107
- dict for each text field to the name of the column in the tsv file
108
- label_column: `string`, name of the column in the tsv file corresponding
109
- to the label
110
- data_url: `string`, url to download the zip file from
111
- data_dir: `string`, the path to the folder containing the tsv files in the
112
- downloaded zip
113
- citation: `string`, citation for the data set
114
- url: `string`, url for information about the data set
115
- label_classes: `list[string]`, the list of classes if the label is
116
- categorical. If not provided, then the label will be of type
117
- `datasets.Value('float32')`.
118
- process_label: `Function[string, any]`, function taking in the raw value
119
- of the label and processing it to the form required by the label feature
120
- **kwargs: keyword arguments forwarded to super.
121
- """
122
- super(GlueConfig, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs)
123
- self.text_features = text_features
124
- self.label_column = label_column
125
- self.label_classes = label_classes
126
- self.data_url = data_url
127
- self.data_dir = data_dir
128
- self.citation = citation
129
- self.url = url
130
- self.process_label = process_label
131
-
132
-
133
- class Glue(datasets.GeneratorBasedBuilder):
134
- """The General Language Understanding Evaluation (GLUE) benchmark."""
135
-
136
- BUILDER_CONFIGS = [
137
- GlueConfig(
138
- name="cola",
139
- description=textwrap.dedent(
140
- """\
141
- The Corpus of Linguistic Acceptability consists of English
142
- acceptability judgments drawn from books and journal articles on
143
- linguistic theory. Each example is a sequence of words annotated
144
- with whether it is a grammatical English sentence."""
145
- ),
146
- text_features={"sentence": "sentence"},
147
- label_classes=["unacceptable", "acceptable"],
148
- label_column="is_acceptable",
149
- data_url="https://dl.fbaipublicfiles.com/glue/data/CoLA.zip",
150
- data_dir="CoLA",
151
- citation=textwrap.dedent(
152
- """\
153
- @article{warstadt2018neural,
154
- title={Neural Network Acceptability Judgments},
155
- author={Warstadt, Alex and Singh, Amanpreet and Bowman, Samuel R},
156
- journal={arXiv preprint arXiv:1805.12471},
157
- year={2018}
158
- }"""
159
- ),
160
- url="https://nyu-mll.github.io/CoLA/",
161
- ),
162
- GlueConfig(
163
- name="sst2",
164
- description=textwrap.dedent(
165
- """\
166
- The Stanford Sentiment Treebank consists of sentences from movie reviews and
167
- human annotations of their sentiment. The task is to predict the sentiment of a
168
- given sentence. We use the two-way (positive/negative) class split, and use only
169
- sentence-level labels."""
170
- ),
171
- text_features={"sentence": "sentence"},
172
- label_classes=["negative", "positive"],
173
- label_column="label",
174
- data_url="https://dl.fbaipublicfiles.com/glue/data/SST-2.zip",
175
- data_dir="SST-2",
176
- citation=textwrap.dedent(
177
- """\
178
- @inproceedings{socher2013recursive,
179
- title={Recursive deep models for semantic compositionality over a sentiment treebank},
180
- author={Socher, Richard and Perelygin, Alex and Wu, Jean and Chuang, Jason and Manning, Christopher D and Ng, Andrew and Potts, Christopher},
181
- booktitle={Proceedings of the 2013 conference on empirical methods in natural language processing},
182
- pages={1631--1642},
183
- year={2013}
184
- }"""
185
- ),
186
- url="https://datasets.stanford.edu/sentiment/index.html",
187
- ),
188
- GlueConfig(
189
- name="mrpc",
190
- description=textwrap.dedent(
191
- """\
192
- The Microsoft Research Paraphrase Corpus (Dolan & Brockett, 2005) is a corpus of
193
- sentence pairs automatically extracted from online news sources, with human annotations
194
- for whether the sentences in the pair are semantically equivalent."""
195
- ), # pylint: disable=line-too-long
196
- text_features={"sentence1": "", "sentence2": ""},
197
- label_classes=["not_equivalent", "equivalent"],
198
- label_column="Quality",
199
- data_url="", # MRPC isn't hosted by GLUE.
200
- data_dir="MRPC",
201
- citation=textwrap.dedent(
202
- """\
203
- @inproceedings{dolan2005automatically,
204
- title={Automatically constructing a corpus of sentential paraphrases},
205
- author={Dolan, William B and Brockett, Chris},
206
- booktitle={Proceedings of the Third International Workshop on Paraphrasing (IWP2005)},
207
- year={2005}
208
- }"""
209
- ),
210
- url="https://www.microsoft.com/en-us/download/details.aspx?id=52398",
211
- ),
212
- GlueConfig(
213
- name="qqp",
214
- description=textwrap.dedent(
215
- """\
216
- The Quora Question Pairs2 dataset is a collection of question pairs from the
217
- community question-answering website Quora. The task is to determine whether a
218
- pair of questions are semantically equivalent."""
219
- ),
220
- text_features={
221
- "question1": "question1",
222
- "question2": "question2",
223
- },
224
- label_classes=["not_duplicate", "duplicate"],
225
- label_column="is_duplicate",
226
- data_url="https://dl.fbaipublicfiles.com/glue/data/QQP-clean.zip",
227
- data_dir="QQP",
228
- citation=textwrap.dedent(
229
- """\
230
- @online{WinNT,
231
- author = {Iyer, Shankar and Dandekar, Nikhil and Csernai, Kornel},
232
- title = {First Quora Dataset Release: Question Pairs},
233
- year = {2017},
234
- url = {https://data.quora.com/First-Quora-Dataset-Release-Question-Pairs},
235
- urldate = {2019-04-03}
236
- }"""
237
- ),
238
- url="https://data.quora.com/First-Quora-Dataset-Release-Question-Pairs",
239
- ),
240
- GlueConfig(
241
- name="stsb",
242
- description=textwrap.dedent(
243
- """\
244
- The Semantic Textual Similarity Benchmark (Cer et al., 2017) is a collection of
245
- sentence pairs drawn from news headlines, video and image captions, and natural
246
- language inference data. Each pair is human-annotated with a similarity score
247
- from 1 to 5."""
248
- ),
249
- text_features={
250
- "sentence1": "sentence1",
251
- "sentence2": "sentence2",
252
- },
253
- label_column="score",
254
- data_url="https://dl.fbaipublicfiles.com/glue/data/STS-B.zip",
255
- data_dir="STS-B",
256
- citation=textwrap.dedent(
257
- """\
258
- @article{cer2017semeval,
259
- title={Semeval-2017 task 1: Semantic textual similarity-multilingual and cross-lingual focused evaluation},
260
- author={Cer, Daniel and Diab, Mona and Agirre, Eneko and Lopez-Gazpio, Inigo and Specia, Lucia},
261
- journal={arXiv preprint arXiv:1708.00055},
262
- year={2017}
263
- }"""
264
- ),
265
- url="http://ixa2.si.ehu.es/stswiki/index.php/STSbenchmark",
266
- process_label=np.float32,
267
- ),
268
- GlueConfig(
269
- name="mnli",
270
- description=textwrap.dedent(
271
- """\
272
- The Multi-Genre Natural Language Inference Corpus is a crowdsourced
273
- collection of sentence pairs with textual entailment annotations. Given a premise sentence
274
- and a hypothesis sentence, the task is to predict whether the premise entails the hypothesis
275
- (entailment), contradicts the hypothesis (contradiction), or neither (neutral). The premise sentences are
276
- gathered from ten different sources, including transcribed speech, fiction, and government reports.
277
- We use the standard test set, for which we obtained private labels from the authors, and evaluate
278
- on both the matched (in-domain) and mismatched (cross-domain) section. We also use and recommend
279
- the SNLI corpus as 550k examples of auxiliary training data."""
280
- ),
281
- **_MNLI_BASE_KWARGS,
282
- ),
283
- GlueConfig(
284
- name="mnli_mismatched",
285
- description=textwrap.dedent(
286
- """\
287
- The mismatched validation and test splits from MNLI.
288
- See the "mnli" BuilderConfig for additional information."""
289
- ),
290
- **_MNLI_BASE_KWARGS,
291
- ),
292
- GlueConfig(
293
- name="mnli_matched",
294
- description=textwrap.dedent(
295
- """\
296
- The matched validation and test splits from MNLI.
297
- See the "mnli" BuilderConfig for additional information."""
298
- ),
299
- **_MNLI_BASE_KWARGS,
300
- ),
301
- GlueConfig(
302
- name="qnli",
303
- description=textwrap.dedent(
304
- """\
305
- The Stanford Question Answering Dataset is a question-answering
306
- dataset consisting of question-paragraph pairs, where one of the sentences in the paragraph (drawn
307
- from Wikipedia) contains the answer to the corresponding question (written by an annotator). We
308
- convert the task into sentence pair classification by forming a pair between each question and each
309
- sentence in the corresponding context, and filtering out pairs with low lexical overlap between the
310
- question and the context sentence. The task is to determine whether the context sentence contains
311
- the answer to the question. This modified version of the original task removes the requirement that
312
- the model select the exact answer, but also removes the simplifying assumptions that the answer
313
- is always present in the input and that lexical overlap is a reliable cue."""
314
- ), # pylint: disable=line-too-long
315
- text_features={
316
- "question": "question",
317
- "sentence": "sentence",
318
- },
319
- label_classes=["entailment", "not_entailment"],
320
- label_column="label",
321
- data_url="https://dl.fbaipublicfiles.com/glue/data/QNLIv2.zip",
322
- data_dir="QNLI",
323
- citation=textwrap.dedent(
324
- """\
325
- @article{rajpurkar2016squad,
326
- title={Squad: 100,000+ questions for machine comprehension of text},
327
- author={Rajpurkar, Pranav and Zhang, Jian and Lopyrev, Konstantin and Liang, Percy},
328
- journal={arXiv preprint arXiv:1606.05250},
329
- year={2016}
330
- }"""
331
- ),
332
- url="https://rajpurkar.github.io/SQuAD-explorer/",
333
- ),
334
- GlueConfig(
335
- name="rte",
336
- description=textwrap.dedent(
337
- """\
338
- The Recognizing Textual Entailment (RTE) datasets come from a series of annual textual
339
- entailment challenges. We combine the data from RTE1 (Dagan et al., 2006), RTE2 (Bar Haim
340
- et al., 2006), RTE3 (Giampiccolo et al., 2007), and RTE5 (Bentivogli et al., 2009).4 Examples are
341
- constructed based on news and Wikipedia text. We convert all datasets to a two-class split, where
342
- for three-class datasets we collapse neutral and contradiction into not entailment, for consistency."""
343
- ), # pylint: disable=line-too-long
344
- text_features={
345
- "sentence1": "sentence1",
346
- "sentence2": "sentence2",
347
- },
348
- label_classes=["entailment", "not_entailment"],
349
- label_column="label",
350
- data_url="https://dl.fbaipublicfiles.com/glue/data/RTE.zip",
351
- data_dir="RTE",
352
- citation=textwrap.dedent(
353
- """\
354
- @inproceedings{dagan2005pascal,
355
- title={The PASCAL recognising textual entailment challenge},
356
- author={Dagan, Ido and Glickman, Oren and Magnini, Bernardo},
357
- booktitle={Machine Learning Challenges Workshop},
358
- pages={177--190},
359
- year={2005},
360
- organization={Springer}
361
- }
362
- @inproceedings{bar2006second,
363
- title={The second pascal recognising textual entailment challenge},
364
- author={Bar-Haim, Roy and Dagan, Ido and Dolan, Bill and Ferro, Lisa and Giampiccolo, Danilo and Magnini, Bernardo and Szpektor, Idan},
365
- booktitle={Proceedings of the second PASCAL challenges workshop on recognising textual entailment},
366
- volume={6},
367
- number={1},
368
- pages={6--4},
369
- year={2006},
370
- organization={Venice}
371
- }
372
- @inproceedings{giampiccolo2007third,
373
- title={The third pascal recognizing textual entailment challenge},
374
- author={Giampiccolo, Danilo and Magnini, Bernardo and Dagan, Ido and Dolan, Bill},
375
- booktitle={Proceedings of the ACL-PASCAL workshop on textual entailment and paraphrasing},
376
- pages={1--9},
377
- year={2007},
378
- organization={Association for Computational Linguistics}
379
- }
380
- @inproceedings{bentivogli2009fifth,
381
- title={The Fifth PASCAL Recognizing Textual Entailment Challenge.},
382
- author={Bentivogli, Luisa and Clark, Peter and Dagan, Ido and Giampiccolo, Danilo},
383
- booktitle={TAC},
384
- year={2009}
385
- }"""
386
- ),
387
- url="https://aclweb.org/aclwiki/Recognizing_Textual_Entailment",
388
- ),
389
- GlueConfig(
390
- name="wnli",
391
- description=textwrap.dedent(
392
- """\
393
- The Winograd Schema Challenge (Levesque et al., 2011) is a reading comprehension task
394
- in which a system must read a sentence with a pronoun and select the referent of that pronoun from
395
- a list of choices. The examples are manually constructed to foil simple statistical methods: Each
396
- one is contingent on contextual information provided by a single word or phrase in the sentence.
397
- To convert the problem into sentence pair classification, we construct sentence pairs by replacing
398
- the ambiguous pronoun with each possible referent. The task is to predict if the sentence with the
399
- pronoun substituted is entailed by the original sentence. We use a small evaluation set consisting of
400
- new examples derived from fiction books that was shared privately by the authors of the original
401
- corpus. While the included training set is balanced between two classes, the test set is imbalanced
402
- between them (65% not entailment). Also, due to a data quirk, the development set is adversarial:
403
- hypotheses are sometimes shared between training and development examples, so if a model memorizes the
404
- training examples, they will predict the wrong label on corresponding development set
405
- example. As with QNLI, each example is evaluated separately, so there is not a systematic correspondence
406
- between a model's score on this task and its score on the unconverted original task. We
407
- call converted dataset WNLI (Winograd NLI)."""
408
- ),
409
- text_features={
410
- "sentence1": "sentence1",
411
- "sentence2": "sentence2",
412
- },
413
- label_classes=["not_entailment", "entailment"],
414
- label_column="label",
415
- data_url="https://dl.fbaipublicfiles.com/glue/data/WNLI.zip",
416
- data_dir="WNLI",
417
- citation=textwrap.dedent(
418
- """\
419
- @inproceedings{levesque2012winograd,
420
- title={The winograd schema challenge},
421
- author={Levesque, Hector and Davis, Ernest and Morgenstern, Leora},
422
- booktitle={Thirteenth International Conference on the Principles of Knowledge Representation and Reasoning},
423
- year={2012}
424
- }"""
425
- ),
426
- url="https://cs.nyu.edu/faculty/davise/papers/WinogradSchemas/WS.html",
427
- ),
428
- GlueConfig(
429
- name="ax",
430
- description=textwrap.dedent(
431
- """\
432
- A manually-curated evaluation dataset for fine-grained analysis of
433
- system performance on a broad range of linguistic phenomena. This
434
- dataset evaluates sentence understanding through Natural Language
435
- Inference (NLI) problems. Use a model trained on MulitNLI to produce
436
- predictions for this dataset."""
437
- ),
438
- text_features={
439
- "premise": "sentence1",
440
- "hypothesis": "sentence2",
441
- },
442
- label_classes=["entailment", "neutral", "contradiction"],
443
- label_column="", # No label since we only have test set.
444
- # We must use a URL shortener since the URL from GLUE is very long and
445
- # causes issues in TFDS.
446
- data_url="https://dl.fbaipublicfiles.com/glue/data/AX.tsv",
447
- data_dir="", # We are downloading a tsv.
448
- citation="", # The GLUE citation is sufficient.
449
- url="https://gluebenchmark.com/diagnostics",
450
- ),
451
- ]
452
-
453
- def _info(self):
454
- features = {text_feature: datasets.Value("string") for text_feature in self.config.text_features.keys()}
455
- if self.config.label_classes:
456
- features["label"] = datasets.features.ClassLabel(names=self.config.label_classes)
457
- else:
458
- features["label"] = datasets.Value("float32")
459
- features["idx"] = datasets.Value("int32")
460
- return datasets.DatasetInfo(
461
- description=_GLUE_DESCRIPTION,
462
- features=datasets.Features(features),
463
- homepage=self.config.url,
464
- citation=self.config.citation + "\n" + _GLUE_CITATION,
465
- )
466
-
467
- def _split_generators(self, dl_manager):
468
- if self.config.name == "ax":
469
- data_file = dl_manager.download(self.config.data_url)
470
- return [
471
- datasets.SplitGenerator(
472
- name=datasets.Split.TEST,
473
- gen_kwargs={
474
- "data_file": data_file,
475
- "split": "test",
476
- },
477
- )
478
- ]
479
-
480
- if self.config.name == "mrpc":
481
- data_dir = None
482
- mrpc_files = dl_manager.download(
483
- {
484
- "dev_ids": _MRPC_DEV_IDS,
485
- "train": _MRPC_TRAIN,
486
- "test": _MRPC_TEST,
487
- }
488
- )
489
- else:
490
- dl_dir = dl_manager.download_and_extract(self.config.data_url)
491
- data_dir = os.path.join(dl_dir, self.config.data_dir)
492
- mrpc_files = None
493
- train_split = datasets.SplitGenerator(
494
- name=datasets.Split.TRAIN,
495
- gen_kwargs={
496
- "data_file": os.path.join(data_dir or "", "train.tsv"),
497
- "split": "train",
498
- "mrpc_files": mrpc_files,
499
- },
500
- )
501
- if self.config.name == "mnli":
502
- return [
503
- train_split,
504
- _mnli_split_generator("validation_matched", data_dir, "dev", matched=True),
505
- _mnli_split_generator("validation_mismatched", data_dir, "dev", matched=False),
506
- _mnli_split_generator("test_matched", data_dir, "test", matched=True),
507
- _mnli_split_generator("test_mismatched", data_dir, "test", matched=False),
508
- ]
509
- elif self.config.name == "mnli_matched":
510
- return [
511
- _mnli_split_generator("validation", data_dir, "dev", matched=True),
512
- _mnli_split_generator("test", data_dir, "test", matched=True),
513
- ]
514
- elif self.config.name == "mnli_mismatched":
515
- return [
516
- _mnli_split_generator("validation", data_dir, "dev", matched=False),
517
- _mnli_split_generator("test", data_dir, "test", matched=False),
518
- ]
519
- else:
520
- return [
521
- train_split,
522
- datasets.SplitGenerator(
523
- name=datasets.Split.VALIDATION,
524
- gen_kwargs={
525
- "data_file": os.path.join(data_dir or "", "dev.tsv"),
526
- "split": "dev",
527
- "mrpc_files": mrpc_files,
528
- },
529
- ),
530
- datasets.SplitGenerator(
531
- name=datasets.Split.TEST,
532
- gen_kwargs={
533
- "data_file": os.path.join(data_dir or "", "test.tsv"),
534
- "split": "test",
535
- "mrpc_files": mrpc_files,
536
- },
537
- ),
538
- ]
539
-
540
- def _generate_examples(self, data_file, split, mrpc_files=None):
541
- if self.config.name == "mrpc":
542
- # We have to prepare the MRPC dataset from the original sources ourselves.
543
- examples = self._generate_example_mrpc_files(mrpc_files=mrpc_files, split=split)
544
- for example in examples:
545
- yield example["idx"], example
546
- else:
547
- process_label = self.config.process_label
548
- label_classes = self.config.label_classes
549
-
550
- # The train and dev files for CoLA are the only tsv files without a
551
- # header.
552
- is_cola_non_test = self.config.name == "cola" and split != "test"
553
-
554
- with open(data_file, encoding="utf8") as f:
555
- reader = csv.DictReader(f, delimiter="\t", quoting=csv.QUOTE_NONE)
556
- if is_cola_non_test:
557
- reader = csv.reader(f, delimiter="\t", quoting=csv.QUOTE_NONE)
558
-
559
- for n, row in enumerate(reader):
560
- if is_cola_non_test:
561
- row = {
562
- "sentence": row[3],
563
- "is_acceptable": row[1],
564
- }
565
-
566
- example = {feat: row[col] for feat, col in self.config.text_features.items()}
567
- example["idx"] = n
568
-
569
- if self.config.label_column in row:
570
- label = row[self.config.label_column]
571
- # For some tasks, the label is represented as 0 and 1 in the tsv
572
- # files and needs to be cast to integer to work with the feature.
573
- if label_classes and label not in label_classes:
574
- label = int(label) if label else None
575
- example["label"] = process_label(label)
576
- else:
577
- example["label"] = process_label(-1)
578
-
579
- # Filter out corrupted rows.
580
- for value in example.values():
581
- if value is None:
582
- break
583
- else:
584
- yield example["idx"], example
585
-
586
- def _generate_example_mrpc_files(self, mrpc_files, split):
587
- if split == "test":
588
- with open(mrpc_files["test"], encoding="utf8") as f:
589
- # The first 3 bytes are the utf-8 BOM \xef\xbb\xbf, which messes with
590
- # the Quality key.
591
- f.seek(3)
592
- reader = csv.DictReader(f, delimiter="\t", quoting=csv.QUOTE_NONE)
593
- for n, row in enumerate(reader):
594
- yield {
595
- "sentence1": row["#1 String"],
596
- "sentence2": row["#2 String"],
597
- "label": int(row["Quality"]),
598
- "idx": n,
599
- }
600
- else:
601
- with open(mrpc_files["dev_ids"], encoding="utf8") as f:
602
- reader = csv.reader(f, delimiter="\t", quoting=csv.QUOTE_NONE)
603
- dev_ids = [[row[0], row[1]] for row in reader]
604
- with open(mrpc_files["train"], encoding="utf8") as f:
605
- # The first 3 bytes are the utf-8 BOM \xef\xbb\xbf, which messes with
606
- # the Quality key.
607
- f.seek(3)
608
- reader = csv.DictReader(f, delimiter="\t", quoting=csv.QUOTE_NONE)
609
- for n, row in enumerate(reader):
610
- is_row_in_dev = [row["#1 ID"], row["#2 ID"]] in dev_ids
611
- if is_row_in_dev == (split == "dev"):
612
- yield {
613
- "sentence1": row["#1 String"],
614
- "sentence2": row["#2 String"],
615
- "label": int(row["Quality"]),
616
- "idx": n,
617
- }
618
-
619
-
620
- def _mnli_split_generator(name, data_dir, split, matched):
621
- return datasets.SplitGenerator(
622
- name=name,
623
- gen_kwargs={
624
- "data_file": os.path.join(data_dir, "%s_%s.tsv" % (split, "matched" if matched else "mismatched")),
625
- "split": split,
626
- "mrpc_files": None,
627
- },
628
- )