glue.py 16.8 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
"""
GLUE: A Multi-Task Benchmark and Analysis Platform for Natural Language Understanding
https://openreview.net/pdf?id=rJ4km2R5t7

The General Language Understanding Evaluation (GLUE) benchmark is a collection of
resources for training, evaluating, and analyzing natural language understanding
systems. GLUE consists of:
- A benchmark of nine sentence- or sentence-pair language understanding tasks built
on established existing datasets and selected to cover a diverse range of dataset
sizes, text genres, and degrees of difficulty, and
- A diagnostic dataset designed to evaluate and analyze model performance with
respect to a wide range of linguistic phenomena found in natural language.

Homepage: https://gluebenchmark.com/
15
16
"""
import numpy as np
Jonathan Tow's avatar
Jonathan Tow committed
17
18
19
from lm_eval.base import rf, Task
from lm_eval.metrics import mean, matthews_corrcoef, f1_score, yesno
from lm_eval.utils import general_detokenize
20

21

22
23
# TODO(jon-tow): Add citations for the individual datasets/tasks that make up GLUE.
_CITATION = """
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
@inproceedings{wang-etal-2018-glue,
    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",
    booktitle = "Proceedings of the 2018 {EMNLP} Workshop {B}lackbox{NLP}: Analyzing and Interpreting Neural Networks for {NLP}",
    month = nov,
    year = "2018",
    address = "Brussels, Belgium",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/W18-5446",
    doi = "10.18653/v1/W18-5446",
    pages = "353--355",
    abstract = "Human ability to understand language is \textit{general, flexible, and robust}. In contrast, most NLU models above the word level are designed for a specific task and struggle with out-of-domain data. If we aspire to develop models with understanding beyond the detection of superficial correspondences between inputs and outputs, then it is critical to develop a unified model that can execute a range of linguistic tasks across different domains. To facilitate research in this direction, we present the General Language Understanding Evaluation (GLUE, gluebenchmark.com): a benchmark of nine diverse NLU tasks, an auxiliary dataset for probing models for understanding of specific linguistic phenomena, and an online platform for evaluating and comparing models. For some benchmark tasks, training data is plentiful, but for others it is limited or does not match the genre of the test set. GLUE thus favors models that can represent linguistic knowledge in a way that facilitates sample-efficient learning and effective knowledge-transfer across tasks. While none of the datasets in GLUE were created from scratch for the benchmark, four of them feature privately-held test data, which is used to ensure that the benchmark is used fairly. We evaluate baselines that use ELMo (Peters et al., 2018), a powerful transfer learning technique, as well as state-of-the-art sentence representation models. The best models still achieve fairly low absolute scores. Analysis with our diagnostic dataset yields similarly weak performance over all phenomena tested, with some exceptions.",
}
"""
43

Jonathan Tow's avatar
Jonathan Tow committed
44
45

# Single-Sentence Tasks
Jason Phang's avatar
Jason Phang committed
46
47


Jonathan Tow's avatar
Jonathan Tow committed
48
class CoLA(Task):
Leo Gao's avatar
Leo Gao committed
49
    VERSION = 0
sdtblck's avatar
sdtblck committed
50
51
    DATASET_PATH = "glue"
    DATASET_NAME = "cola"
Jonathan Tow's avatar
Jonathan Tow committed
52

Jason Phang's avatar
checkin  
Jason Phang committed
53
54
55
56
57
58
59
    def has_training_docs(self):
        return True

    def has_validation_docs(self):
        return True

    def has_test_docs(self):
60
        return False
Jason Phang's avatar
checkin  
Jason Phang committed
61

Jonathan Tow's avatar
Jonathan Tow committed
62
63
64
65
66
67
68
69
    def training_docs(self):
        if self._training_docs is None:
            self._training_docs = list(self.dataset["train"])
        return self._training_docs

    def validation_docs(self):
        return self.dataset["validation"]

70
    def doc_to_text(self, doc):
bzantium's avatar
bzantium committed
71
72
73
74
75
76
77
78
79
        return "{}\nQuestion: Does this sentence make sense?\nAnswer:".format(
            doc["sentence"]
        )

    def should_decontaminate(self):
        return True

    def doc_to_decontamination_query(self, doc):
        return doc["sentence"]
80
81

    def doc_to_target(self, doc):
Leo Gao's avatar
Leo Gao committed
82
        return " {}".format({1: "yes", 0: "no"}[doc["label"]])
Jason Phang's avatar
checkin  
Jason Phang committed
83

Jonathan Tow's avatar
Jonathan Tow committed
84
    def construct_requests(self, doc, ctx):
Leo Gao's avatar
Leo Gao committed
85
86
        ll_true, _ = rf.loglikelihood(ctx, " yes")
        ll_false, _ = rf.loglikelihood(ctx, " no")
Jonathan Tow's avatar
Jonathan Tow committed
87
        return ll_true, ll_false
88

Jonathan Tow's avatar
Jonathan Tow committed
89
90
91
92
    def process_results(self, doc, results):
        ll_true, ll_false = results
        pred = ll_true > ll_false
        gold = doc["label"]
bzantium's avatar
bzantium committed
93
        return {"mcc": (gold, pred)}
94

Jonathan Tow's avatar
Jonathan Tow committed
95
    def higher_is_better(self):
bzantium's avatar
bzantium committed
96
        return {"mcc": True}
Jonathan Tow's avatar
Jonathan Tow committed
97
98

    def aggregation(self):
bzantium's avatar
bzantium committed
99
        return {"mcc": matthews_corrcoef}
Jonathan Tow's avatar
Jonathan Tow committed
100
101


Jonathan Tow's avatar
Jonathan Tow committed
102
class SST(Task):
Leo Gao's avatar
Leo Gao committed
103
    VERSION = 0
Jonathan Tow's avatar
Jonathan Tow committed
104
105
106
107
108
109
110
111
112
113
    DATASET_PATH = "glue"
    DATASET_NAME = "sst2"

    def has_training_docs(self):
        return True

    def has_validation_docs(self):
        return True

    def has_test_docs(self):
114
        return False
Jonathan Tow's avatar
Jonathan Tow committed
115

Jonathan Tow's avatar
Jonathan Tow committed
116
117
118
119
120
121
122
123
    def training_docs(self):
        if self._training_docs is None:
            self._training_docs = list(self.dataset["train"])
        return self._training_docs

    def validation_docs(self):
        return self.dataset["validation"]

Jonathan Tow's avatar
Jonathan Tow committed
124
    def doc_to_text(self, doc):
Leo Gao's avatar
Fix  
Leo Gao committed
125
        return "{}\nQuestion: Is this sentence positive or negative?\nAnswer:".format(
Leo Gao's avatar
Leo Gao committed
126
            general_detokenize(doc["sentence"]),
Jonathan Tow's avatar
Jonathan Tow committed
127
128
129
        )

    def doc_to_target(self, doc):
Leo Gao's avatar
Fix  
Leo Gao committed
130
        return " {}".format({1: "positive", 0: "negative"}[doc["label"]])
Jonathan Tow's avatar
Jonathan Tow committed
131
132

    def construct_requests(self, doc, ctx):
Leo Gao's avatar
Fix  
Leo Gao committed
133
134
        ll_positive, _ = rf.loglikelihood(ctx, " positive")
        ll_negative, _ = rf.loglikelihood(ctx, " negative")
Jonathan Tow's avatar
Jonathan Tow committed
135
136
137
138
139
140
        return ll_positive, ll_negative

    def process_results(self, doc, results):
        ll_positive, ll_negative = results
        pred = ll_positive > ll_negative
        gold = doc["label"]
bzantium's avatar
bzantium committed
141
        return {"acc": pred == gold}
Jonathan Tow's avatar
Jonathan Tow committed
142
143

    def higher_is_better(self):
bzantium's avatar
bzantium committed
144
        return {"acc": True}
Jason Phang's avatar
checkin  
Jason Phang committed
145

Jonathan Tow's avatar
Jonathan Tow committed
146
    def aggregation(self):
bzantium's avatar
bzantium committed
147
        return {"acc": mean}
Jonathan Tow's avatar
Jonathan Tow committed
148
149
150
151


# Inference Tasks

Jason Phang's avatar
checkin  
Jason Phang committed
152

Jonathan Tow's avatar
Jonathan Tow committed
153
class MNLI(Task):
Leo Gao's avatar
Leo Gao committed
154
    VERSION = 0
sdtblck's avatar
sdtblck committed
155
156
    DATASET_PATH = "glue"
    DATASET_NAME = "mnli"
Jason Phang's avatar
Jason Phang committed
157

Jason Phang's avatar
checkin  
Jason Phang committed
158
159
160
161
162
163
164
    def has_training_docs(self):
        return True

    def has_validation_docs(self):
        return True

    def has_test_docs(self):
165
        return False
Jason Phang's avatar
checkin  
Jason Phang committed
166

Jonathan Tow's avatar
Jonathan Tow committed
167
168
169
170
171
    def training_docs(self):
        if self._training_docs is None:
            self._training_docs = list(self.dataset["train"])
        return self._training_docs

Jason Phang's avatar
checkin  
Jason Phang committed
172
173
    def validation_docs(self):
        if self.has_validation_docs():
Jonathan Tow's avatar
Jonathan Tow committed
174
            return self.dataset["validation_matched"]
Jason Phang's avatar
checkin  
Jason Phang committed
175
176
177

    def test_docs(self):
        if self.has_test_docs():
Jonathan Tow's avatar
Jonathan Tow committed
178
            return self.dataset["test_matched"]
Jason Phang's avatar
checkin  
Jason Phang committed
179

180
    def doc_to_text(self, doc):
Leo Gao's avatar
Leo Gao committed
181
        return "{}\nQuestion: {} True, False or Neither?\nAnswer:".format(
Jason Phang's avatar
Jason Phang committed
182
            doc["premise"],
bzantium's avatar
bzantium committed
183
184
            doc["hypothesis"].strip()
            + ("" if doc["hypothesis"].strip().endswith(".") else "."),
Jason Phang's avatar
checkin  
Jason Phang committed
185
        )
186
187
188
189
190
191

    def doc_to_target(self, doc):
        # True = entailment
        # False = contradiction
        # Neither = neutral
        return " {}".format({0: "True", 1: "Neither", 2: "False"}[doc["label"]])
Jason Phang's avatar
checkin  
Jason Phang committed
192

Jonathan Tow's avatar
Jonathan Tow committed
193
194
195
196
197
    def construct_requests(self, doc, ctx):
        ll_true, _ = rf.loglikelihood(ctx, " True")
        ll_neither, _ = rf.loglikelihood(ctx, " Neither")
        ll_false, _ = rf.loglikelihood(ctx, " False")
        return ll_true, ll_neither, ll_false
198

Jonathan Tow's avatar
Jonathan Tow committed
199
200
201
    def process_results(self, doc, results):
        gold = doc["label"]
        pred = np.argmax(results)
bzantium's avatar
bzantium committed
202
        return {"acc": pred == gold}
Jonathan Tow's avatar
Jonathan Tow committed
203
204

    def higher_is_better(self):
bzantium's avatar
bzantium committed
205
        return {"acc": True}
Jonathan Tow's avatar
Jonathan Tow committed
206
207

    def aggregation(self):
bzantium's avatar
bzantium committed
208
        return {"acc": mean}
Jason Phang's avatar
checkin  
Jason Phang committed
209
210


Jason Phang's avatar
Jason Phang committed
211
class MNLIMismatched(MNLI):
Leo Gao's avatar
Leo Gao committed
212
    VERSION = 0
Jason Phang's avatar
Jason Phang committed
213
214
215

    def validation_docs(self):
        if self.has_validation_docs():
Jonathan Tow's avatar
Jonathan Tow committed
216
            return self.dataset["validation_mismatched"]
Jason Phang's avatar
Jason Phang committed
217
218
219

    def test_docs(self):
        if self.has_test_docs():
Jonathan Tow's avatar
Jonathan Tow committed
220
            return self.dataset["test_mismatched"]
Jason Phang's avatar
Jason Phang committed
221
222


Jonathan Tow's avatar
Jonathan Tow committed
223
class QNLI(Task):
Leo Gao's avatar
Leo Gao committed
224
    VERSION = 0
sdtblck's avatar
sdtblck committed
225
    DATASET_PATH = "glue"
Jonathan Tow's avatar
Jonathan Tow committed
226
    DATASET_NAME = "qnli"
Jason Phang's avatar
Jason Phang committed
227
228
229
230
231
232
233
234

    def has_training_docs(self):
        return True

    def has_validation_docs(self):
        return True

    def has_test_docs(self):
235
        return False
Jason Phang's avatar
Jason Phang committed
236

Jonathan Tow's avatar
Jonathan Tow committed
237
238
239
240
241
242
243
244
    def training_docs(self):
        if self._training_docs is None:
            self._training_docs = list(self.dataset["train"])
        return self._training_docs

    def validation_docs(self):
        return self.dataset["validation"]

Jonathan Tow's avatar
Jonathan Tow committed
245
    def doc_to_text(self, doc):
bzantium's avatar
bzantium committed
246
247
248
249
250
        return (
            "{}\n{}\nQuestion: Does this response answer the question?\nAnswer:".format(
                doc["question"],
                doc["sentence"],
            )
Jonathan Tow's avatar
Jonathan Tow committed
251
252
253
254
255
        )

    def doc_to_target(self, doc):
        # True = entailment
        # False = not entailment
Leo Gao's avatar
Fix  
Leo Gao committed
256
        return " {}".format({0: "yes", 1: "no"}[doc["label"]])
Jonathan Tow's avatar
Jonathan Tow committed
257
258

    def construct_requests(self, doc, ctx):
Leo Gao's avatar
Fix  
Leo Gao committed
259
260
        ll_yes, _ = rf.loglikelihood(ctx, " yes")
        ll_no, _ = rf.loglikelihood(ctx, " no")
Jonathan Tow's avatar
Jonathan Tow committed
261
262
263
264
265
266
        return ll_yes, ll_no

    def process_results(self, doc, results):
        ll_yes, ll_no = results
        pred = ll_no > ll_yes
        gold = doc["label"]
bzantium's avatar
bzantium committed
267
        return {"acc": pred == gold}
Jonathan Tow's avatar
Jonathan Tow committed
268
269

    def higher_is_better(self):
bzantium's avatar
bzantium committed
270
        return {"acc": True}
Jonathan Tow's avatar
Jonathan Tow committed
271
272

    def aggregation(self):
bzantium's avatar
bzantium committed
273
        return {"acc": mean}
Jonathan Tow's avatar
Jonathan Tow committed
274
275


Jonathan Tow's avatar
Jonathan Tow committed
276
class WNLI(Task):
thomasw21's avatar
thomasw21 committed
277
    VERSION = 1
Jonathan Tow's avatar
Jonathan Tow committed
278
279
280
281
282
283
284
285
286
287
    DATASET_PATH = "glue"
    DATASET_NAME = "wnli"

    def has_training_docs(self):
        return True

    def has_validation_docs(self):
        return True

    def has_test_docs(self):
288
        return False
Jason Phang's avatar
Jason Phang committed
289

Jonathan Tow's avatar
Jonathan Tow committed
290
291
292
293
294
295
296
297
    def training_docs(self):
        if self._training_docs is None:
            self._training_docs = list(self.dataset["train"])
        return self._training_docs

    def validation_docs(self):
        return self.dataset["validation"]

298
    def doc_to_text(self, doc):
thomasw21's avatar
thomasw21 committed
299
        return "{}\nQuestion: {} True or False?\nAnswer:".format(
Jason Phang's avatar
Jason Phang committed
300
301
302
            doc["sentence1"],
            doc["sentence2"],
        )
303
304

    def doc_to_target(self, doc):
Jonathan Tow's avatar
Jonathan Tow committed
305
        # True = entailment
thomasw21's avatar
thomasw21 committed
306
307
        # False = not_entailment
        return " {}".format({0: "False", 1: "True"}[doc["label"]])
Jason Phang's avatar
Jason Phang committed
308

Jonathan Tow's avatar
Jonathan Tow committed
309
310
311
    def construct_requests(self, doc, ctx):
        ll_true, _ = rf.loglikelihood(ctx, " True")
        ll_false, _ = rf.loglikelihood(ctx, " False")
thomasw21's avatar
thomasw21 committed
312
        return ll_true, ll_false
Jonathan Tow's avatar
Jonathan Tow committed
313
314

    def process_results(self, doc, results):
thomasw21's avatar
thomasw21 committed
315
316
        ll_true, ll_false = results
        pred = ll_true > ll_false
Jonathan Tow's avatar
Jonathan Tow committed
317
        gold = doc["label"]
bzantium's avatar
bzantium committed
318
        return {"acc": pred == gold}
Jonathan Tow's avatar
Jonathan Tow committed
319
320

    def higher_is_better(self):
bzantium's avatar
bzantium committed
321
        return {"acc": True}
Jonathan Tow's avatar
Jonathan Tow committed
322
323

    def aggregation(self):
bzantium's avatar
bzantium committed
324
        return {"acc": mean}
325

Jason Phang's avatar
Jason Phang committed
326

Jonathan Tow's avatar
Jonathan Tow committed
327
class RTE(Task):
Leo Gao's avatar
Leo Gao committed
328
    VERSION = 0
sdtblck's avatar
sdtblck committed
329
330
    DATASET_PATH = "glue"
    DATASET_NAME = "rte"
Jason Phang's avatar
checkin  
Jason Phang committed
331
332
333
334
335
336
337
338

    def has_training_docs(self):
        return True

    def has_validation_docs(self):
        return True

    def has_test_docs(self):
339
        return False
Jason Phang's avatar
checkin  
Jason Phang committed
340

Jonathan Tow's avatar
Jonathan Tow committed
341
342
343
344
345
346
347
348
    def training_docs(self):
        if self._training_docs is None:
            self._training_docs = list(self.dataset["train"])
        return self._training_docs

    def validation_docs(self):
        return self.dataset["validation"]

349
    def doc_to_text(self, doc):
Leo Gao's avatar
Leo Gao committed
350
        return "{}\nQuestion: {} True or False?\nAnswer:".format(
Jason Phang's avatar
checkin  
Jason Phang committed
351
352
353
            doc["sentence1"],
            doc["sentence2"],
        )
354
355
356
357
358

    def doc_to_target(self, doc):
        # 0 = entailment
        # 1 = not_entailment
        return " {}".format({0: "True", 1: "False"}[doc["label"]])
Jason Phang's avatar
checkin  
Jason Phang committed
359

Jonathan Tow's avatar
Jonathan Tow committed
360
361
362
363
    def construct_requests(self, doc, ctx):
        ll_true, _ = rf.loglikelihood(ctx, " True")
        ll_false, _ = rf.loglikelihood(ctx, " False")
        return ll_true, ll_false
364

Jonathan Tow's avatar
Jonathan Tow committed
365
366
367
368
    def process_results(self, doc, results):
        ll_true, ll_false = results
        pred = ll_false > ll_true
        gold = doc["label"]
bzantium's avatar
bzantium committed
369
        return {"acc": pred == gold}
Jonathan Tow's avatar
Jonathan Tow committed
370
371

    def higher_is_better(self):
bzantium's avatar
bzantium committed
372
        return {"acc": True}
Jason Phang's avatar
Jason Phang committed
373

Jonathan Tow's avatar
Jonathan Tow committed
374
    def aggregation(self):
bzantium's avatar
bzantium committed
375
        return {"acc": mean}
Jason Phang's avatar
Jason Phang committed
376

Jonathan Tow's avatar
Jonathan Tow committed
377
378
379
380

# Similarity and Paraphrase Tasks


Jonathan Tow's avatar
Jonathan Tow committed
381
class MRPC(Task):
Leo Gao's avatar
Leo Gao committed
382
    VERSION = 0
sdtblck's avatar
sdtblck committed
383
    DATASET_PATH = "glue"
Jonathan Tow's avatar
Jonathan Tow committed
384
    DATASET_NAME = "mrpc"
Jason Phang's avatar
Jason Phang committed
385
386
387
388
389
390
391
392

    def has_training_docs(self):
        return True

    def has_validation_docs(self):
        return True

    def has_test_docs(self):
Leo Gao's avatar
Leo Gao committed
393
        return False
Jason Phang's avatar
Jason Phang committed
394

Jonathan Tow's avatar
Jonathan Tow committed
395
396
397
398
399
400
401
402
    def training_docs(self):
        if self._training_docs is None:
            self._training_docs = list(self.dataset["train"])
        return self._training_docs

    def validation_docs(self):
        return self.dataset["validation"]

403
    def doc_to_text(self, doc):
Leo Gao's avatar
Leo Gao committed
404
405
406
        return "Sentence 1: {}\nSentence 2: {}\nQuestion: Do both sentences mean the same thing?\nAnswer:".format(
            general_detokenize(doc["sentence1"]),
            general_detokenize(doc["sentence2"]),
Jason Phang's avatar
Jason Phang committed
407
        )
408
409

    def doc_to_target(self, doc):
Jonathan Tow's avatar
Jonathan Tow committed
410
        return " {}".format(yesno(doc["label"]))
Jason Phang's avatar
Jason Phang committed
411

Jonathan Tow's avatar
Jonathan Tow committed
412
    def construct_requests(self, doc, ctx):
Leo Gao's avatar
Fix  
Leo Gao committed
413
414
        ll_yes, _ = rf.loglikelihood(ctx, " yes")
        ll_no, _ = rf.loglikelihood(ctx, " no")
Jonathan Tow's avatar
Jonathan Tow committed
415
        return ll_yes, ll_no
416

Jonathan Tow's avatar
Jonathan Tow committed
417
418
419
420
421
422
423
424
425
426
    def process_results(self, doc, results):
        ll_yes, ll_no = results
        gold = doc["label"]
        pred = ll_yes > ll_no
        return {
            "acc": pred == gold,
            "f1": (gold, pred),
        }

    def higher_is_better(self):
bzantium's avatar
bzantium committed
427
        return {"acc": True, "f1": True}
Jonathan Tow's avatar
Jonathan Tow committed
428
429

    def aggregation(self):
bzantium's avatar
bzantium committed
430
        return {"acc": mean, "f1": f1_score}
Jason Phang's avatar
Jason Phang committed
431
432


Jonathan Tow's avatar
Jonathan Tow committed
433
class QQP(Task):
Leo Gao's avatar
Leo Gao committed
434
    VERSION = 0
sdtblck's avatar
sdtblck committed
435
436
    DATASET_PATH = "glue"
    DATASET_NAME = "qqp"
Jason Phang's avatar
Jason Phang committed
437
438
439
440
441
442
443
444

    def has_training_docs(self):
        return True

    def has_validation_docs(self):
        return True

    def has_test_docs(self):
Leo Gao's avatar
Leo Gao committed
445
        return False
Jason Phang's avatar
Jason Phang committed
446

Jonathan Tow's avatar
Jonathan Tow committed
447
448
449
450
451
452
453
454
    def training_docs(self):
        if self._training_docs is None:
            self._training_docs = list(self.dataset["train"])
        return self._training_docs

    def validation_docs(self):
        return self.dataset["validation"]

455
    def doc_to_text(self, doc):
Leo Gao's avatar
Leo Gao committed
456
        return "Question 1: {}\nQuestion 2: {}\nQuestion: Do both questions ask the same thing?\nAnswer:".format(
Jason Phang's avatar
Jason Phang committed
457
458
459
            doc["question1"],
            doc["question2"],
        )
460
461
462

    def doc_to_target(self, doc):
        return " {}".format(yesno(doc["label"]))
Jason Phang's avatar
Jason Phang committed
463

Jonathan Tow's avatar
Jonathan Tow committed
464
465
466
467
    def construct_requests(self, doc, ctx):
        ll_yes, _ = rf.loglikelihood(ctx, " yes")
        ll_no, _ = rf.loglikelihood(ctx, " no")
        return ll_yes, ll_no
468

Jonathan Tow's avatar
Jonathan Tow committed
469
470
471
472
473
474
475
476
477
478
    def process_results(self, doc, results):
        ll_yes, ll_no = results
        gold = doc["label"]
        pred = ll_yes > ll_no
        return {
            "acc": pred == gold,
            "f1": (gold, pred),
        }

    def higher_is_better(self):
bzantium's avatar
bzantium committed
479
        return {"acc": True, "f1": True}
Jonathan Tow's avatar
Jonathan Tow committed
480
481

    def aggregation(self):
bzantium's avatar
bzantium committed
482
        return {"acc": mean, "f1": f1_score}
Jason Phang's avatar
Jason Phang committed
483
484


Jonathan Tow's avatar
Jonathan Tow committed
485
class STSB(Task):
Leo Gao's avatar
Leo Gao committed
486
    VERSION = 0
sdtblck's avatar
sdtblck committed
487
488
    DATASET_PATH = "glue"
    DATASET_NAME = "stsb"
Jason Phang's avatar
Jason Phang committed
489
490
491
492
493
494
495
496
497
498

    def has_training_docs(self):
        return True

    def has_validation_docs(self):
        return True

    def has_test_docs(self):
        return True

Jonathan Tow's avatar
Jonathan Tow committed
499
500
501
502
503
504
505
506
507
508
509
    def training_docs(self):
        if self._training_docs is None:
            self._training_docs = list(self.dataset["train"])
        return self._training_docs

    def validation_docs(self):
        return self.dataset["validation"]

    def test_docs(self):
        return self.dataset["test"]

510
    def doc_to_text(self, doc):
Leo Gao's avatar
Leo Gao committed
511
        return "sentence 1: {}\nsentence 2: {}\nAnswer:".format(
Jason Phang's avatar
Jason Phang committed
512
513
514
            doc["sentence1"],
            doc["sentence2"],
        )
515
516
517

    def doc_to_target(self, doc):
        return " {}".format(doc["label"])
Jason Phang's avatar
Jason Phang committed
518

Leo Gao's avatar
Leo Gao committed
519
    def construct_requests(self, doc, ctx):
bzantium's avatar
bzantium committed
520
        """Uses RequestFactory to construct Requests and returns an iterable of
Leo Gao's avatar
Leo Gao committed
521
522
523
524
525
        Requests which will be sent to the LM.

        :param doc:
            The document as returned from training_docs, validation_docs, or test_docs.
        :param ctx: str
bzantium's avatar
bzantium committed
526
            The context string, generated by fewshot_context. This includes the natural
Leo Gao's avatar
Leo Gao committed
527
            language description, as well as the few shot examples, and the question
bzantium's avatar
bzantium committed
528
            part of the document for `doc`.
Leo Gao's avatar
Leo Gao committed
529
530
        """
        # TODO: implement evaluation.
bzantium's avatar
bzantium committed
531
532
        raise NotImplementedError("Evaluation not implemented")

Leo Gao's avatar
Leo Gao committed
533
    def process_results(self, doc, results):
bzantium's avatar
bzantium committed
534
535
        """Take a single document and the LM results and evaluates, returning a
        dict where keys are the names of submetrics and values are the values of
Leo Gao's avatar
Leo Gao committed
536
537
538
539
540
541
542
543
        the metric for that one document

        :param doc:
            The document as returned from training_docs, validation_docs, or test_docs.
        :param results:
            The results of the requests created in construct_requests.
        """
        # TODO: implement evaluation.
bzantium's avatar
bzantium committed
544
        raise NotImplementedError("Evaluation not implemented")
Leo Gao's avatar
Leo Gao committed
545
546
547
548

    def aggregation(self):
        """
        :returns: {str: [float] -> float}
bzantium's avatar
bzantium committed
549
            A dictionary where keys are the names of submetrics and values are
Leo Gao's avatar
Leo Gao committed
550
551
552
            functions that aggregate a list of metrics
        """
        # TODO: implement evaluation.
bzantium's avatar
bzantium committed
553
        raise NotImplementedError("Evaluation not implemented")
Leo Gao's avatar
Leo Gao committed
554
555
556
557

    def higher_is_better(self):
        """
        :returns: {str: bool}
bzantium's avatar
bzantium committed
558
            A dictionary where keys are the names of submetrics and values are
Leo Gao's avatar
Leo Gao committed
559
560
561
            whether a higher value of the submetric is better
        """
        # TODO: implement evaluation.
bzantium's avatar
bzantium committed
562
        raise NotImplementedError("Evaluation not implemented")