lambada_cloze.py 1.93 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
"""
The LAMBADA dataset: Word prediction requiring a broad discourse context∗
https://arxiv.org/pdf/1606.06031.pdf

Cloze-style LAMBADA dataset.
LAMBADA is a dataset to evaluate the capabilities of computational models for text
understanding by means of a word prediction task. LAMBADA is a collection of narrative
passages sharing the characteristic that human subjects are able to guess their last
word if they are exposed to the whole passage, but not if they only see the last
sentence preceding the target word. To succeed on LAMBADA, computational models
cannot simply rely on local context, but must be able to keep track of information
in the broader discourse.

Homepage: https://zenodo.org/record/2630551#.X4Xzn5NKjUI
"""
bzantium's avatar
bzantium committed
16
from lm_eval.tasks.lambada import LambadaOpenAI, LambadaStandard
17
18


19
20
_CITATION = """
@misc{
bzantium's avatar
bzantium committed
21
    author={Paperno, Denis and Kruszewski, Germán and Lazaridou, Angeliki and Pham, Quan Ngoc and Bernardi, Raffaella and Pezzelle, Sandro and Baroni, Marco and Boleda, Gemma and Fernández, Raquel},
22
23
24
25
26
27
28
29
30
    title={The LAMBADA dataset},
    DOI={10.5281/zenodo.2630551},
    publisher={Zenodo},
    year={2016},
    month={Aug}
}
"""


bzantium's avatar
bzantium committed
31
32
33
class LambadaStandardCloze(LambadaStandard):
    """Cloze-style LambadaStandard."""

Leo Gao's avatar
Leo Gao committed
34
    VERSION = 0
Jonathan Tow's avatar
Jonathan Tow committed
35

36
    def doc_to_text(self, doc):
bzantium's avatar
bzantium committed
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
        return doc["text"].rsplit(" ", 1)[0] + " ____. ->"

    def should_decontaminate(self):
        return True

    def doc_to_decontamination_query(self, doc):
        return doc["text"]

    def doc_to_target(self, doc):
        return " " + doc["text"].rsplit(" ", 1)[1]


class LambadaOpenAICloze(LambadaOpenAI):
    """Cloze-style LambadaOpenAI."""

    VERSION = 0

    def doc_to_text(self, doc):
        return doc["text"].rsplit(" ", 1)[0] + " ____. ->"

    def should_decontaminate(self):
        return True

    def doc_to_decontamination_query(self, doc):
        return doc["text"]
62
63

    def doc_to_target(self, doc):
bzantium's avatar
bzantium committed
64
        return " " + doc["text"].rsplit(" ", 1)[1]