File size: 22,237 Bytes
c9ac0a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
580e539
c9ac0a9
 
 
 
7f209de
 
c9ac0a9
 
 
7f209de
c9ac0a9
7f209de
c9ac0a9
 
 
 
 
 
7f209de
 
c9ac0a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
580e539
 
703826a
 
 
 
580e539
 
c9ac0a9
 
 
 
 
 
 
 
 
 
7f209de
99ccef4
7f209de
c9ac0a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
580e539
 
c9ac0a9
580e539
 
 
 
9862bb6
580e539
 
703826a
 
 
 
 
580e539
 
 
 
 
 
 
 
 
 
 
 
 
 
c9ac0a9
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
# coding=utf-8
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Lint as: python3
"""The SuperGLUE benchmark."""

import json
import os

import datasets

_CITATION = """\
"""

# You can copy an official description
_DESCRIPTION = """\
"""

_HOMEPAGE = ""

_LICENSE = ""

_GLUE_CITATION = """\
@inproceedings{wang2019glue,
  title={{GLUE}: A Multi-Task Benchmark and Analysis Platform for Natural Language Understanding},
  author={Wang, Alex and Singh, Amanpreet and Michael, Julian and Hill, Felix and Levy, Omer and Bowman, Samuel R.},
  note={In the Proceedings of ICLR.},
  year={2019}
}
"""

_GLUE_DESCRIPTION = """\
GLUE, the General Language Understanding Evaluation benchmark
(https://gluebenchmark.com/) is a collection of resources for training,
evaluating, and analyzing natural language understanding systems.

"""
_SST_DESCRIPTION = """\
The Stanford Sentiment Treebank consists of sentences from movie reviews and
human annotations of their sentiment. The task is to predict the sentiment of a
given sentence. We use the two-way (positive/negative) class split, and use only
sentence-level labels."""
_SST_CITATION = """\
@inproceedings{socher2013recursive,
    title={Recursive deep models for semantic compositionality over a sentiment treebank},
    author={Socher, Richard and Perelygin, Alex and Wu, Jean and Chuang, Jason and Manning, Christopher D and Ng, Andrew and Potts, Christopher},
    booktitle={Proceedings of the 2013 conference on empirical methods in natural language processing},
    pages={1631--1642},
    year={2013}
}"""
_MRPC_DESCRIPTION = """\
The Microsoft Research Paraphrase Corpus (Dolan & Brockett, 2005) is a corpus of
sentence pairs automatically extracted from online news sources, with human annotations
for whether the sentences in the pair are semantically equivalent."""
_MRPC_CITATION = """\
@inproceedings{dolan2005automatically,
    title={Automatically constructing a corpus of sentential paraphrases},
    author={Dolan, William B and Brockett, Chris},
    booktitle={Proceedings of the Third International Workshop on Paraphrasing (IWP2005)},
    year={2005}
}"""
_QQP_DESCRIPTION = """\
The Quora Question Pairs2 dataset is a collection of question pairs from the
community question-answering website Quora. The task is to determine whether a
pair of questions are semantically equivalent."""
_QQP_CITATION = """\
@online{WinNT,
author = {Iyer, Shankar and Dandekar, Nikhil and Csernai, Kornel},
title = {First Quora Dataset Release: Question Pairs},
year = {2017},
url = {https://data.quora.com/First-Quora-Dataset-Release-Question-Pairs},
urldate = {2019-04-03}
}"""
_STSB_DESCRIPTION = """\
The Semantic Textual Similarity Benchmark (Cer et al., 2017) is a collection of
sentence pairs drawn from news headlines, video and image captions, and natural
language inference data. Each pair is human-annotated with a similarity score
from 1 to 5."""
_STSB_CITATION = """\
@article{cer2017semeval,
    title={Semeval-2017 task 1: Semantic textual similarity-multilingual and cross-lingual focused evaluation},
    author={Cer, Daniel and Diab, Mona and Agirre, Eneko and Lopez-Gazpio, Inigo and Specia, Lucia},
    journal={arXiv preprint arXiv:1708.00055},
    year={2017}
}"""
_MNLI_DESCRIPTION = """\
The Multi-Genre Natural Language Inference Corpus is a crowdsourced
collection of sentence pairs with textual entailment annotations. Given a premise sentence
and a hypothesis sentence, the task is to predict whether the premise entails the hypothesis
(entailment), contradicts the hypothesis (contradiction), or neither (neutral). The premise sentences are
gathered from ten different sources, including transcribed speech, fiction, and government reports.
We use the standard test set, for which we obtained private labels from the authors, and evaluate
on both the matched (in-domain) and mismatched (cross-domain) section. We also use and recommend
the SNLI corpus as 550k examples of auxiliary training data."""
_MNLI_CITATION = """\
  @InProceedings{N18-1101,
    author = "Williams, Adina
              and Nangia, Nikita
              and Bowman, Samuel",
    title = "A Broad-Coverage Challenge Corpus for
             Sentence Understanding through Inference",
    booktitle = "Proceedings of the 2018 Conference of
                 the North American Chapter of the
                 Association for Computational Linguistics:
                 Human Language Technologies, Volume 1 (Long
                 Papers)",
    year = "2018",
    publisher = "Association for Computational Linguistics",
    pages = "1112--1122",
    location = "New Orleans, Louisiana",
    url = "http://aclweb.org/anthology/N18-1101"
  }
  @article{bowman2015large,
    title={A large annotated corpus for learning natural language inference},
    author={Bowman, Samuel R and Angeli, Gabor and Potts, Christopher and Manning, Christopher D},
    journal={arXiv preprint arXiv:1508.05326},
    year={2015}
  }"""
_QNLI_DESCRIPTION = """\
The Stanford Question Answering Dataset is a question-answering
dataset consisting of question-paragraph pairs, where one of the sentences in the paragraph (drawn
from Wikipedia) contains the answer to the corresponding question (written by an annotator). We
convert the task into sentence pair classification by forming a pair between each question and each
sentence in the corresponding context, and filtering out pairs with low lexical overlap between the
question and the context sentence. The task is to determine whether the context sentence contains
the answer to the question. This modified version of the original task removes the requirement that
the model select the exact answer, but also removes the simplifying assumptions that the answer
is always present in the input and that lexical overlap is a reliable cue."""
_QNLI_CITATION = """\
@article{rajpurkar2016squad,
    title={Squad: 100,000+ questions for machine comprehension of text},
    author={Rajpurkar, Pranav and Zhang, Jian and Lopyrev, Konstantin and Liang, Percy},
    journal={arXiv preprint arXiv:1606.05250},
    year={2016}
}"""
_WNLI_DESCRIPTION = """\
The Winograd Schema Challenge (Levesque et al., 2011) is a reading comprehension task
in which a system must read a sentence with a pronoun and select the referent of that pronoun from
a list of choices. The examples are manually constructed to foil simple statistical methods: Each
one is contingent on contextual information provided by a single word or phrase in the sentence.
To convert the problem into sentence pair classification, we construct sentence pairs by replacing
the ambiguous pronoun with each possible referent. The task is to predict if the sentence with the
pronoun substituted is entailed by the original sentence. We use a small evaluation set consisting of
new examples derived from fiction books that was shared privately by the authors of the original
corpus. While the included training set is balanced between two classes, the test set is imbalanced
between them (65% not entailment). Also, due to a data quirk, the development set is adversarial:
hypotheses are sometimes shared between training and development examples, so if a model memorizes the
training examples, they will predict the wrong label on corresponding development set
example. As with QNLI, each example is evaluated separately, so there is not a systematic correspondence
between a model's score on this task and its score on the unconverted original task. We
call converted dataset WNLI (Winograd NLI)."""
_WNLI_CITATION = """\
@inproceedings{levesque2012winograd,
    title={The winograd schema challenge},
    author={Levesque, Hector and Davis, Ernest and Morgenstern, Leora},
    booktitle={Thirteenth International Conference on the Principles of Knowledge Representation and Reasoning},
    year={2012}
}"""

_SUPER_GLUE_CITATION = """\
@article{wang2019superglue,
  title={SuperGLUE: A Stickier Benchmark for General-Purpose Language Understanding Systems},
  author={Wang, Alex and Pruksachatkun, Yada and Nangia, Nikita and Singh, Amanpreet and Michael, Julian and Hill, Felix and Levy, Omer and Bowman, Samuel R},
  journal={arXiv preprint arXiv:1905.00537},
  year={2019}
}

Note that each SuperGLUE dataset has its own citation. Please see the source to
get the correct citation for each contained dataset.
"""

_SUPER_GLUE_DESCRIPTION = """\
SuperGLUE (https://super.gluebenchmark.com/) is a new benchmark styled after
GLUE with a new set of more difficult language understanding tasks, improved
resources, and a new public leaderboard.

"""

_BOOLQ_DESCRIPTION = """\
BoolQ (Boolean Questions, Clark et al., 2019a) is a QA task where each example consists of a short
passage and a yes/no question about the passage. The questions are provided anonymously and
unsolicited by users of the Google search engine, and afterwards paired with a paragraph from a
Wikipedia article containing the answer. Following the original work, we evaluate with accuracy."""

_CB_DESCRIPTION = """\
The CommitmentBank (De Marneffe et al., 2019) is a corpus of short texts in which at least
one sentence contains an embedded clause. Each of these embedded clauses is annotated with the
degree to which we expect that the person who wrote the text is committed to the truth of the clause.
The resulting task framed as three-class textual entailment on examples that are drawn from the Wall
Street Journal, fiction from the British National Corpus, and Switchboard. Each example consists
of a premise containing an embedded clause and the corresponding hypothesis is the extraction of
that clause. We use a subset of the data that had inter-annotator agreement above 0.85. The data is
imbalanced (relatively fewer neutral examples), so we evaluate using accuracy and F1, where for
multi-class F1 we compute the unweighted average of the F1 per class."""

_COPA_DESCRIPTION = """\
The Choice Of Plausible Alternatives (COPA, Roemmele et al., 2011) dataset is a causal
reasoning task in which a system is given a premise sentence and two possible alternatives. The
system must choose the alternative which has the more plausible causal relationship with the premise.
The method used for the construction of the alternatives ensures that the task requires causal reasoning
to solve. Examples either deal with alternative possible causes or alternative possible effects of the
premise sentence, accompanied by a simple question disambiguating between the two instance
types for the model. All examples are handcrafted and focus on topics from online blogs and a
photography-related encyclopedia. Following the recommendation of the authors, we evaluate using
accuracy."""

_RTE_DESCRIPTION = """\
The Recognizing Textual Entailment (RTE) datasets come from a series of annual competitions
on textual entailment, the problem of predicting whether a given premise sentence entails a given
hypothesis sentence (also known as natural language inference, NLI). RTE was previously included
in GLUE, and we use the same data and format as before: We merge data from RTE1 (Dagan
et al., 2006), RTE2 (Bar Haim et al., 2006), RTE3 (Giampiccolo et al., 2007), and RTE5 (Bentivogli
et al., 2009). All datasets are combined and converted to two-class classification: entailment and
not_entailment. Of all the GLUE tasks, RTE was among those that benefited from transfer learning
the most, jumping from near random-chance performance (~56%) at the time of GLUE's launch to
85% accuracy (Liu et al., 2019c) at the time of writing. Given the eight point gap with respect to
human performance, however, the task is not yet solved by machines, and we expect the remaining
gap to be difficult to close."""

_BOOLQ_CITATION = """\
@inproceedings{clark2019boolq,
  title={BoolQ: Exploring the Surprising Difficulty of Natural Yes/No Questions},
  author={Clark, Christopher and Lee, Kenton and Chang, Ming-Wei, and Kwiatkowski, Tom and Collins, Michael, and Toutanova, Kristina},
  booktitle={NAACL},
  year={2019}
}"""

_CB_CITATION = """\
@article{de marneff_simons_tonhauser_2019,
  title={The CommitmentBank: Investigating projection in naturally occurring discourse},
  journal={proceedings of Sinn und Bedeutung 23},
  author={De Marneff, Marie-Catherine and Simons, Mandy and Tonhauser, Judith},
  year={2019}
}"""

_COPA_CITATION = """\
@inproceedings{roemmele2011choice,
  title={Choice of plausible alternatives: An evaluation of commonsense causal reasoning},
  author={Roemmele, Melissa and Bejan, Cosmin Adrian and Gordon, Andrew S},
  booktitle={2011 AAAI Spring Symposium Series},
  year={2011}
}"""

_RTE_CITATION = """\
@inproceedings{dagan2005pascal,
  title={The PASCAL recognising textual entailment challenge},
  author={Dagan, Ido and Glickman, Oren and Magnini, Bernardo},
  booktitle={Machine Learning Challenges Workshop},
  pages={177--190},
  year={2005},
  organization={Springer}
}
@inproceedings{bar2006second,
  title={The second pascal recognising textual entailment challenge},
  author={Bar-Haim, Roy and Dagan, Ido and Dolan, Bill and Ferro, Lisa and Giampiccolo, Danilo and Magnini, Bernardo and Szpektor, Idan},
  booktitle={Proceedings of the second PASCAL challenges workshop on recognising textual entailment},
  volume={6},
  number={1},
  pages={6--4},
  year={2006},
  organization={Venice}
}
@inproceedings{giampiccolo2007third,
  title={The third pascal recognizing textual entailment challenge},
  author={Giampiccolo, Danilo and Magnini, Bernardo and Dagan, Ido and Dolan, Bill},
  booktitle={Proceedings of the ACL-PASCAL workshop on textual entailment and paraphrasing},
  pages={1--9},
  year={2007},
  organization={Association for Computational Linguistics}
}
@inproceedings{bentivogli2009fifth,
  title={The Fifth PASCAL Recognizing Textual Entailment Challenge.},
  author={Bentivogli, Luisa and Clark, Peter and Dagan, Ido and Giampiccolo, Danilo},
  booktitle={TAC},
  year={2009}
}"""

# TODO: Add link to the official dataset URLs here
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
_URL = "https://huggingface.co/datasets/KBLab/overlim/resolve/main/data/"
_TASKS = {
    "boolq": "boolq.tar.gz",
    "cb": "cb.tar.gz",
    "copa": "copa.tar.gz",
    "mnli": "mnli.tar.gz",
    "mrpc": "mrpc.tar.gz",
    "qnli": "qnli.tar.gz",
    "qqp": "qqp.tar.gz",
    "rte": "rte.tar.gz",
    "sst": "sst.tar.gz",
    "stsb": "stsb.tar.gz",
    "wnli": "wnli.tar.gz"
}
_LANGUAGES = {"sv", "da", "nb"}


class OverLimConfig(datasets.BuilderConfig):
    """BuilderConfig for Suc."""
    def __init__(self, name, description, features, citation, language, label_classes=None, **kwargs):
        """BuilderConfig for OverLim.
        """
        self.full_name = name + "_" + language
        super(OverLimConfig,
              self).__init__(name=self.full_name, version=datasets.Version("1.0.2"), **kwargs)
        self.features = features + ["label"]
        self.label_classes = label_classes
        self.citation = citation
        self.description = description
        self.task_name = name
        self.language = language
        self.data_url = _TASKS[name]



class OverLim(datasets.GeneratorBasedBuilder):
    """OverLim"""

    BUILDER_CONFIGS = [[
        OverLimConfig(
            name="boolq",
            description=_BOOLQ_DESCRIPTION,
            features=["question", "passage"],
            label_classes=["False", "True"],
            citation=_BOOLQ_CITATION,
            language=lang,
        ),
        OverLimConfig(
            name="cb",
            description=_CB_DESCRIPTION,
            features=["premise", "hypothesis"],
            label_classes=["entailment", "contradiction", "neutral"],
            citation=_CB_CITATION,
            language=lang,
        ),
        OverLimConfig(
            name="copa",
            description=_COPA_DESCRIPTION,
            label_classes=["choice1", "choice2"],
            # Note that question will only be the X in the statement "What's
            # the X for this?".
            features=["premise", "choice1", "choice2", "question"],
            citation=_COPA_CITATION,
            language=lang,
        ),
        OverLimConfig(
            name="rte",
            description=_RTE_DESCRIPTION,
            features=["premise", "hypothesis"],
            label_classes=["entailment", "not_entailment"],
            citation=_RTE_CITATION,
            language=lang,
        ),
        OverLimConfig(
            name="qqp",
            description=_QQP_DESCRIPTION,
            features=["text_a", "text_b"],
            label_classes=["not_duplicate", "duplicate"],
            citation=_QQP_CITATION,
            language=lang,
        ),
        OverLimConfig(
            name="qnli",
            description=_QNLI_DESCRIPTION,
            features=["premise", "hypothesis"],
            label_classes=["entailment", "not_entailment"],
            citation=_QNLI_CITATION,
            language=lang,
        ),
        OverLimConfig(
            name="stsb",
            description=_STSB_DESCRIPTION,
            features=["text_a", "text_b"],
            citation=_STSB_CITATION,
            language=lang,
        ),
        OverLimConfig(
            name="mnli",
            description=_MNLI_DESCRIPTION,
            features=["premise", "hypothesis"],
            label_classes=["entailment", "neutral", "contradiction"],
            citation=_MNLI_CITATION,
            language=lang,
        ),
        OverLimConfig(
            name="mrpc",
            description=_MRPC_DESCRIPTION,
            features=["text_a", "text_b"],
            label_classes=["not_equivalent", "equivalent"],
            citation=_MRPC_CITATION,
            language=lang,
        ),
        OverLimConfig(
            name="wnli",
            description=_WNLI_DESCRIPTION,
            features=["premise", "hypothesis"],
            label_classes=["not_entailment", "entailment"],
            citation=_WNLI_CITATION,
            language=lang,
        ),
        OverLimConfig(
            name="sst",
            description=_SST_DESCRIPTION,
            features=["text"],
            label_classes=["negative", "positive"],
            citation=_SST_CITATION,
            language=lang,
        )

    ] for lang in _LANGUAGES]
    BUILDER_CONFIGS = [element for inner in BUILDER_CONFIGS for element in inner]

    def _info(self):
        features = {feature: datasets.Value("string") for feature in self.config.features if feature != "label"}
        if self.config.label_classes:
            #if self.config.task_name in ["cb", "mnli", "qnli", "rte"]:
            #    features["label"] = datasets.Value("string")
            #else:
            features["label"] = datasets.features.ClassLabel(names=self.config.label_classes)
        else:
            features["label"] = datasets.Value("float32")
        features["idx"] = datasets.Value("int32")

        return datasets.DatasetInfo(
            description=_GLUE_DESCRIPTION + self.config.description,
            features=datasets.Features(features),
            homepage=_HOMEPAGE,
            citation=self.config.citation + "\n" + _SUPER_GLUE_CITATION,
        )

    def _split_generators(self, dl_manager):
        dl_dir = dl_manager.download_and_extract(os.path.join(_URL, self.config.language, self.config.data_url))
        # dl_dir = dl_manager.iter_archive(os.path.join(_URL, self.config.language, self.config.data_url))
        dl_dir = os.path.join(dl_dir, self.config.task_name)
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={
                    "data_file": os.path.join(dl_dir, "train.jsonl"),
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.VALIDATION,
                gen_kwargs={
                    "data_file": os.path.join(dl_dir, "val.jsonl"),
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                gen_kwargs={
                    "data_file": os.path.join(dl_dir, "test.jsonl"),
                },
            ),
        ]

    def _generate_examples(self, data_file):
        with open(data_file, encoding="utf-8") as f:
            for line in f:
                row = json.loads(line)
                example = {feature: row[feature] for feature in self.config.features}
                example["idx"] = row["idx"]

                if self.config.name == "copa":
                    example["label"] = "choice2" if row["label"] else "choice1"
                else:
                    example["label"] = _cast_label(row["label"])
                yield example["idx"], example


def _cast_label(label):
    """Converts the label into the appropriate string version."""
    try:
        label = float(label)
        return label
    except ValueError:
        pass
    try:
        label = int(label)
        return label
    except ValueError:
        pass
    # try:
    #     label = int(bool(label))
    #     return label
    # except ValueError:
    #     pass
    return label
    

    # if isinstance(label, str):
    #     return label
    # elif isinstance(label, bool):
    #     return "True" if label else "False"
    # # return label
    # elif isinstance(label, int):
    #     assert label in (0, 1)
    #     return label
    # elif isinstance(label, float):
    #     return label
    #     # return str(label)
    # else:
    #     raise ValueError("Invalid label format.")