Unverified Commit f348fa2c authored by Leo Gao's avatar Leo Gao Committed by GitHub
Browse files

Merge pull request #39 from EleutherAI/add_lambada

add_lambada
parents 43978e3b f161731c
...@@ -4,14 +4,14 @@ import random ...@@ -4,14 +4,14 @@ import random
from ..base import Dataset from ..base import Dataset
class HFNLPTask(Dataset): class HFTask(Dataset):
NLP_PATH = None DATASET_PATH = None
NLP_NAME = None DATASET_NAME = None
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self._training_docs = None self._training_docs = None
self.data = datasets.load_dataset(path=self.NLP_PATH, name=self.NLP_NAME) self.data = datasets.load_dataset(path=self.DATASET_PATH, name=self.DATASET_NAME)
def has_training_docs(self): def has_training_docs(self):
"""Whether the task has a training set""" """Whether the task has a training set"""
......
...@@ -2,8 +2,7 @@ import numpy as np ...@@ -2,8 +2,7 @@ import numpy as np
from scipy.stats import pearsonr, spearmanr from scipy.stats import pearsonr, spearmanr
from sklearn.metrics import f1_score, matthews_corrcoef from sklearn.metrics import f1_score, matthews_corrcoef
from tqdm import auto as tqdm_lib from tqdm import auto as tqdm_lib
from . common import HFNLPTask, simple_accuracy_metric, yesno from . common import HFTask, simple_accuracy_metric, yesno
def get_accuracy_and_f1(preds, golds): def get_accuracy_and_f1(preds, golds):
golds = np.array(golds) golds = np.array(golds)
...@@ -22,10 +21,10 @@ def get_accuracy_and_f1(preds, golds): ...@@ -22,10 +21,10 @@ def get_accuracy_and_f1(preds, golds):
} }
class CoLA(HFNLPTask): class CoLA(HFTask):
NLP_PATH = "glue" DATASET_PATH = "glue"
NLP_NAME = "cola" DATASET_NAME = "cola"
def has_training_docs(self): def has_training_docs(self):
return True return True
...@@ -64,9 +63,9 @@ class CoLA(HFNLPTask): ...@@ -64,9 +63,9 @@ class CoLA(HFNLPTask):
} }
class MNLI(HFNLPTask): class MNLI(HFTask):
NLP_PATH = "glue" DATASET_PATH = "glue"
NLP_NAME = "mnli" DATASET_NAME = "mnli"
def has_training_docs(self): def has_training_docs(self):
return True return True
...@@ -79,11 +78,11 @@ class MNLI(HFNLPTask): ...@@ -79,11 +78,11 @@ class MNLI(HFNLPTask):
def validation_docs(self): def validation_docs(self):
if self.has_validation_docs(): if self.has_validation_docs():
return self._load_nlp_dataset()["validation_matched"] return self.data["validation_matched"]
def test_docs(self): def test_docs(self):
if self.has_test_docs(): if self.has_test_docs():
return self._load_nlp_dataset()["test_matched"] return self.data["test_matched"]
def doc_to_text(self, doc, include_target=True): def doc_to_text(self, doc, include_target=True):
text = "{}\nquestion:\t{}\tTrue, False or Neither?\nanswer:".format( text = "{}\nquestion:\t{}\tTrue, False or Neither?\nanswer:".format(
...@@ -115,9 +114,9 @@ class MNLI(HFNLPTask): ...@@ -115,9 +114,9 @@ class MNLI(HFNLPTask):
return simple_accuracy_metric(preds=preds, golds=golds) return simple_accuracy_metric(preds=preds, golds=golds)
class MRPC(HFNLPTask): class MRPC(HFTask):
NLP_PATH = "glue" DATASET_PATH = "glue"
NLP_NAME = "mrpc" DATASET_NAME = "mrpc"
def has_training_docs(self): def has_training_docs(self):
return True return True
...@@ -152,10 +151,10 @@ class MRPC(HFNLPTask): ...@@ -152,10 +151,10 @@ class MRPC(HFNLPTask):
preds.append(lm.loglikelihood(ctx, 'yes') > lm.loglikelihood(ctx, 'no')) preds.append(lm.loglikelihood(ctx, 'yes') > lm.loglikelihood(ctx, 'no'))
return get_accuracy_and_f1(preds=preds, golds=golds) return get_accuracy_and_f1(preds=preds, golds=golds)
class RTE(HFNLPTask): class RTE(HFTask):
NLP_PATH = "glue" DATASET_PATH = "glue"
NLP_NAME = "rte" DATASET_NAME = "rte"
def has_training_docs(self): def has_training_docs(self):
return True return True
...@@ -190,9 +189,9 @@ class RTE(HFNLPTask): ...@@ -190,9 +189,9 @@ class RTE(HFNLPTask):
return simple_accuracy_metric(preds=preds, golds=golds) return simple_accuracy_metric(preds=preds, golds=golds)
class QNLI(HFNLPTask): class QNLI(HFTask):
NLP_PATH = "glue" DATASET_PATH = "glue"
NLP_NAME = "qnli" DATASET_NAME = "qnli"
def has_training_docs(self): def has_training_docs(self):
return True return True
...@@ -227,9 +226,9 @@ class QNLI(HFNLPTask): ...@@ -227,9 +226,9 @@ class QNLI(HFNLPTask):
return simple_accuracy_metric(preds=preds, golds=golds) return simple_accuracy_metric(preds=preds, golds=golds)
class QQP(HFNLPTask): class QQP(HFTask):
NLP_PATH = "glue" DATASET_PATH = "glue"
NLP_NAME = "qqp" DATASET_NAME = "qqp"
def has_training_docs(self): def has_training_docs(self):
return True return True
...@@ -265,9 +264,9 @@ class QQP(HFNLPTask): ...@@ -265,9 +264,9 @@ class QQP(HFNLPTask):
return get_accuracy_and_f1(preds=preds, golds=golds) return get_accuracy_and_f1(preds=preds, golds=golds)
class STSB(HFNLPTask): class STSB(HFTask):
NLP_PATH = "glue" DATASET_PATH = "glue"
NLP_NAME = "stsb" DATASET_NAME = "stsb"
def has_training_docs(self): def has_training_docs(self):
return True return True
...@@ -322,9 +321,9 @@ class STSB(HFNLPTask): ...@@ -322,9 +321,9 @@ class STSB(HFNLPTask):
} }
class SST(HFNLPTask): class SST(HFTask):
NLP_PATH = "glue" DATASET_PATH = "glue"
NLP_NAME = "sst2" DATASET_NAME = "sst2"
def has_training_docs(self): def has_training_docs(self):
return True return True
...@@ -359,10 +358,10 @@ class SST(HFNLPTask): ...@@ -359,10 +358,10 @@ class SST(HFNLPTask):
return simple_accuracy_metric(preds=preds, golds=golds) return simple_accuracy_metric(preds=preds, golds=golds)
class WNLI(HFNLPTask): class WNLI(HFTask):
NLP_PATH = "glue" DATASET_PATH = "glue"
NLP_NAME = "wnli" DATASET_NAME = "wnli"
def has_training_docs(self): def has_training_docs(self):
return True return True
......
from lm_eval.base import Dataset
from lm_eval.utils import sh
import json
import requests
import ftfy
class Lambada(Dataset):
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):
return [doc['text'] for doc in myjson]
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):
pass
def evaluate(self, docs, lm, provide_description, num_fewshot):
pass
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment