AnonyCAD commited on
Commit
21c2295
·
verified ·
1 Parent(s): 451d80e

Upload hellaswag.py

Browse files
Files changed (1) hide show
  1. hellaswag.py +108 -0
hellaswag.py ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """TODO(hellaswag): Add a description here."""
2
+
3
+
4
+ import json
5
+
6
+ import datasets
7
+
8
+
9
+ # TODO(hellaswag): BibTeX citation
10
+ _CITATION = """\
11
+ @inproceedings{zellers2019hellaswag,
12
+ title={HellaSwag: Can a Machine Really Finish Your Sentence?},
13
+ author={Zellers, Rowan and Holtzman, Ari and Bisk, Yonatan and Farhadi, Ali and Choi, Yejin},
14
+ booktitle ={Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics},
15
+ year={2019}
16
+ }
17
+ """
18
+
19
+ _DESCRIPTION = """
20
+ HellaSwag: Can a Machine Really Finish Your Sentence? is a new dataset for commonsense NLI. A paper was published at ACL2019.
21
+ """
22
+ _URL = "https://raw.githubusercontent.com/rowanz/hellaswag/master/data/"
23
+ _URLS = {
24
+ "train": _URL + "hellaswag_train.jsonl",
25
+ "test": _URL + "hellaswag_test.jsonl",
26
+ "dev": _URL + "hellaswag_val.jsonl",
27
+ }
28
+
29
+
30
+ class Hellaswag(datasets.GeneratorBasedBuilder):
31
+ """TODO(hellaswag): Short description of my dataset."""
32
+
33
+ # TODO(hellaswag): Set up version.
34
+ VERSION = datasets.Version("0.1.0")
35
+
36
+ def _info(self):
37
+ # TODO(hellaswag): Specifies the datasets.DatasetInfo object
38
+ return datasets.DatasetInfo(
39
+ # This is the description that will appear on the datasets page.
40
+ description=_DESCRIPTION,
41
+ # datasets.features.FeatureConnectors
42
+ features=datasets.Features(
43
+ {
44
+ # These are the features of your dataset like images, labels ...
45
+ "ind": datasets.Value("int32"),
46
+ "activity_label": datasets.Value("string"),
47
+ "ctx_a": datasets.Value("string"),
48
+ "ctx_b": datasets.Value("string"),
49
+ "ctx": datasets.Value("string"),
50
+ "endings": datasets.features.Sequence(datasets.Value("string")),
51
+ "source_id": datasets.Value("string"),
52
+ "split": datasets.Value("string"),
53
+ "split_type": datasets.Value("string"),
54
+ "label": datasets.Value("string"),
55
+ }
56
+ ),
57
+ # If there's a common (input, target) tuple from the features,
58
+ # specify them here. They'll be used if as_supervised=True in
59
+ # builder.as_dataset.
60
+ supervised_keys=None,
61
+ # Homepage of the dataset for documentation
62
+ homepage="https://rowanzellers.com/hellaswag/",
63
+ citation=_CITATION,
64
+ )
65
+
66
+ def _split_generators(self, dl_manager):
67
+ """Returns SplitGenerators."""
68
+ # TODO(hellaswag): Downloads the data and defines the splits
69
+ # dl_manager is a datasets.download.DownloadManager that can be used to
70
+ # download and extract URLs
71
+ urls_to_download = _URLS
72
+ dl_dir = dl_manager.download_and_extract(urls_to_download)
73
+ return [
74
+ datasets.SplitGenerator(
75
+ name=datasets.Split.TRAIN,
76
+ # These kwargs will be passed to _generate_examples
77
+ gen_kwargs={"filepath": dl_dir["train"]},
78
+ ),
79
+ datasets.SplitGenerator(
80
+ name=datasets.Split.TEST,
81
+ # These kwargs will be passed to _generate_examples
82
+ gen_kwargs={"filepath": dl_dir["test"]},
83
+ ),
84
+ datasets.SplitGenerator(
85
+ name=datasets.Split.VALIDATION,
86
+ # These kwargs will be passed to _generate_examples
87
+ gen_kwargs={"filepath": dl_dir["dev"]},
88
+ ),
89
+ ]
90
+
91
+ def _generate_examples(self, filepath):
92
+ """Yields examples."""
93
+ # TODO(hellaswag): Yields (key, example) tuples from the dataset
94
+ with open(filepath, encoding="utf-8") as f:
95
+ for id_, row in enumerate(f):
96
+ data = json.loads(row)
97
+ yield id_, {
98
+ "ind": int(data["ind"]),
99
+ "activity_label": data["activity_label"],
100
+ "ctx_a": data.get("ctx_a", ""),
101
+ "ctx_b": data.get("ctx_b", ""),
102
+ "ctx": data["ctx"],
103
+ "endings": data.get("endings", []),
104
+ "source_id": data["source_id"],
105
+ "split": data["split"],
106
+ "split_type": data["split_type"],
107
+ "label": str(data.get("label", "")),
108
+ }