lambada.py 1.59 KB
Newer Older
Leo Gao's avatar
Leo Gao committed
1
2
# REMINDER: this code needs to be rewritten for the new framework. Remove this comment when the code is fully converted.

sdtblck's avatar
sdtblck committed
3
from lm_eval.base import Dataset
sdtblck's avatar
sdtblck committed
4
from lm_eval.utils import sh
sdtblck's avatar
sdtblck committed
5
6
7
8
9
10
import json
import requests
import ftfy


class Lambada(Dataset):
11
12
    def __init__(self):
        self.download()
sdtblck's avatar
sdtblck committed
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
    def download(self):
        sh("mkdir -p data/lambada")
        with open("data/lambada/lambada_test.json", 'w') as f:
            req = requests.get("https://storage.googleapis.com/gpt-2/data/lambada_test.jsonl")
            req.raise_for_status()
            jsons = [json.loads(l) for l in req.iter_lines()]
            texts = [ftfy.fix_text(j['text'], normalization='NFKC') for j in jsons]
            json.dump(texts, f)

    def has_training_docs(self):
        return False

    def has_validation_docs(self):
        return False

    def has_test_docs(self):
        return True

    def training_docs(self):
        pass

    def validation_docs(self):
        pass

    def load_doc(self, myjson):
38
        return [doc for doc in myjson]
sdtblck's avatar
sdtblck committed
39
40
41
42
43
44

    def test_docs(self):
        myjson = json.load(open("data/lambada/lambada_test.json"))
        return self.load_doc(myjson)

    def doc_to_text(self, doc, include_target=True):
45
46
47
        #TODO: check if this is how OA does it
        #label = doc[]
        return doc
sdtblck's avatar
sdtblck committed
48

49
50
51
52
53
    # TODO: Implement evaluation code

    # ***IMPORTANT***: this evaluation function needs to be written for the new framework. 
    # For more info, check out the interface in base.py and the example BoolQ implementation in superglue.py. 
    # Remove this comment when the evaluation code is implemented.