system HF staff commited on
Commit
0a4b7d8
0 Parent(s):

Update files from the datasets library (from 1.0.0)

Browse files

Release notes: https://github.com/huggingface/datasets/releases/tag/1.0.0

.gitattributes ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bin.* filter=lfs diff=lfs merge=lfs -text
5
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.model filter=lfs diff=lfs merge=lfs -text
12
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
13
+ *.onnx filter=lfs diff=lfs merge=lfs -text
14
+ *.ot filter=lfs diff=lfs merge=lfs -text
15
+ *.parquet filter=lfs diff=lfs merge=lfs -text
16
+ *.pb filter=lfs diff=lfs merge=lfs -text
17
+ *.pt filter=lfs diff=lfs merge=lfs -text
18
+ *.pth filter=lfs diff=lfs merge=lfs -text
19
+ *.rar filter=lfs diff=lfs merge=lfs -text
20
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
21
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
22
+ *.tflite filter=lfs diff=lfs merge=lfs -text
23
+ *.tgz filter=lfs diff=lfs merge=lfs -text
24
+ *.xz filter=lfs diff=lfs merge=lfs -text
25
+ *.zip filter=lfs diff=lfs merge=lfs -text
26
+ *.zstandard filter=lfs diff=lfs merge=lfs -text
27
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
cos_e.py ADDED
@@ -0,0 +1,196 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ # Lint as: python3
17
+ """Commonsense Explanations (CoS-E) Dataset."""
18
+
19
+ from __future__ import absolute_import, division, print_function
20
+
21
+ import json
22
+ import os
23
+
24
+ import datasets
25
+
26
+
27
+ _CITATION = """
28
+ @inproceedings{rajani2019explain,
29
+ title = {Explain Yourself! Leveraging Language models for Commonsense Reasoning},
30
+ author = {Rajani, Nazneen Fatema and
31
+ McCann, Bryan and
32
+ Xiong, Caiming and
33
+ Socher, Richard}
34
+ year={2019}
35
+ booktitle = {Proceedings of the 2019 Conference of the Association for Computational Linguistics (ACL2019)}
36
+ url ={https://arxiv.org/abs/1906.02361}
37
+ }
38
+ """
39
+
40
+ _DESCRIPTION = """
41
+ Common Sense Explanations (CoS-E) allows for training language models to
42
+ automatically generate explanations that can be used during training and
43
+ inference in a novel Commonsense Auto-Generated Explanation (CAGE) framework.
44
+ """
45
+
46
+ _COS_E_URL = "https://raw.githubusercontent.com/salesforce/cos-e/master/data/"
47
+
48
+ # COS E has explanations for the CQA dataset, which is joined by ID.
49
+ _CQA_V1_11_URL_TRAIN = "https://s3.amazonaws.com/commensenseqa/train_rand_split.jsonl"
50
+ _CQA_V1_11_URL_DEV = "https://s3.amazonaws.com/commensenseqa/dev_rand_split.jsonl"
51
+ _CQA_V1_11_URL_TEST = "https://s3.amazonaws.com/commensenseqa/test_rand_split_no_answers.jsonl"
52
+
53
+ _CQA_V1_0_URL_TRAIN = os.path.join(_COS_E_URL, "v1.0/train_rand_split.jsonl")
54
+ _CQA_V1_0_URL_DEV = os.path.join(_COS_E_URL, "v1.0/dev_rand_split.jsonl")
55
+ _CQA_V1_0_URL_TEST = os.path.join(_COS_E_URL, "v1.0/test_rand_split_no_answers.jsonl")
56
+
57
+
58
+ def _download_and_index_cqa(dl_manager, name):
59
+ """Downloads CQA and returns it, indexed by id, for joining with Cos-E."""
60
+
61
+ downloaded_files = dl_manager.download_and_extract(
62
+ {
63
+ "cqa_train": _CQA_V1_11_URL_TRAIN if name == "v1.11" else _CQA_V1_0_URL_TRAIN,
64
+ "cqa_dev": _CQA_V1_11_URL_DEV if name == "v1.11" else _CQA_V1_0_URL_DEV,
65
+ "cqa_test": _CQA_V1_11_URL_TEST if name == "v1.11" else _CQA_V1_0_URL_TEST,
66
+ }
67
+ )
68
+
69
+ # NB: "cqa_test" is included in the files, but not in any of the CoS-E splits.
70
+ cqa_splits = ["cqa_train", "cqa_dev"]
71
+ cqa_complete = []
72
+ for split in cqa_splits:
73
+ with open(downloaded_files[split], encoding="utf-8") as f:
74
+ for _, line in enumerate(f):
75
+ d = json.loads(line)
76
+ cqa_complete.append(d)
77
+
78
+ # Index the CQA dataset by id for joining with Cos-E.
79
+ cqa_indexed = {}
80
+ for d in cqa_complete:
81
+ cqa_indexed[d["id"]] = d
82
+ return cqa_indexed
83
+
84
+
85
+ def _get_choices_and_answer(cqa):
86
+ """Returns choices and the answer from a cqa example."""
87
+ choices = []
88
+ answer_key = cqa["answerKey"]
89
+ answer = None
90
+ for choice in cqa["question"]["choices"]:
91
+ choices.append(choice["text"])
92
+ if answer_key == choice["label"]:
93
+ answer = choice["text"]
94
+ return choices, answer
95
+
96
+
97
+ class CosEConfig(datasets.BuilderConfig):
98
+
99
+ """ BuilderConfig for CosE"""
100
+
101
+ def __init__(self, **kwargs):
102
+ """
103
+
104
+ Args:
105
+ **kwargs: keyword arguments forwarded to super.
106
+ """
107
+ super(CosEConfig, self).__init__(**kwargs)
108
+
109
+
110
+ class CosE(datasets.GeneratorBasedBuilder):
111
+ """CoS-E: Common Sense Explanations corpus."""
112
+
113
+ BUILDER_CONFIGS = [
114
+ CosEConfig(
115
+ name="v1.0",
116
+ description="cos-e version 1.0",
117
+ version=datasets.Version("1.0.0", ""),
118
+ ),
119
+ CosEConfig(
120
+ name="v1.11",
121
+ description="cos-e version 1.11",
122
+ version=datasets.Version("1.11.0", ""),
123
+ ),
124
+ ]
125
+
126
+ def _info(self):
127
+ return datasets.DatasetInfo(
128
+ description=_DESCRIPTION,
129
+ features=datasets.Features(
130
+ {
131
+ "id": datasets.Value("string"),
132
+ "question": datasets.Value("string"),
133
+ "choices": datasets.features.Sequence(datasets.Value("string")),
134
+ "answer": datasets.Value("string"),
135
+ "abstractive_explanation": datasets.Value("string"),
136
+ "extractive_explanation": datasets.Value("string"),
137
+ }
138
+ ),
139
+ supervised_keys=None,
140
+ homepage="https://github.com/salesforce/cos-e",
141
+ citation=_CITATION,
142
+ )
143
+
144
+ def _split_generators(self, dl_manager):
145
+ """Returns SplitGenerators."""
146
+
147
+ # NB: The CQA Dataset should be read only once, and only by callers who
148
+ # want to _create_ the Cos-E dataset from scratch.
149
+ cqa_indexed = _download_and_index_cqa(dl_manager, self.config.name)
150
+
151
+ if self.config.name == "v1.11":
152
+ files = dl_manager.download_and_extract(
153
+ {
154
+ "dev": [os.path.join(_COS_E_URL, "v1.11/cose_dev_v1.11_processed.jsonl")],
155
+ "train": [os.path.join(_COS_E_URL, "v1.11/cose_train_v1.11_processed.jsonl")],
156
+ }
157
+ )
158
+
159
+ elif self.config.name == "v1.0":
160
+ files = dl_manager.download_and_extract(
161
+ {
162
+ "dev": [os.path.join(_COS_E_URL, "v1.0/cose_dev_v1.0_processed.jsonl")],
163
+ "train": [os.path.join(_COS_E_URL, "v1.0/cose_train_v1.0_processed.jsonl")],
164
+ }
165
+ )
166
+ else:
167
+ raise ValueError("Unknown config name")
168
+ # We use the CoS-E/CQA dev set as our validation set.
169
+ return [
170
+ datasets.SplitGenerator(
171
+ name=datasets.Split.TRAIN,
172
+ gen_kwargs={"files": files["train"], "cqa_indexed": cqa_indexed},
173
+ ),
174
+ datasets.SplitGenerator(
175
+ name=datasets.Split.VALIDATION,
176
+ gen_kwargs={"files": files["dev"], "cqa_indexed": cqa_indexed},
177
+ ),
178
+ ]
179
+
180
+ def _generate_examples(self, files, **kwargs):
181
+ """Yields examples."""
182
+ cqa_indexed = kwargs["cqa_indexed"]
183
+ for filepath in files:
184
+ with open(filepath, encoding="utf-8") as f:
185
+ for line in f:
186
+ cos = json.loads(line)
187
+ cqa = cqa_indexed[cos["id"]]
188
+ choices, answer = _get_choices_and_answer(cqa)
189
+ yield cos["id"], {
190
+ "id": cos["id"],
191
+ "question": cqa["question"]["stem"],
192
+ "choices": choices,
193
+ "answer": answer,
194
+ "abstractive_explanation": cos["explanation"]["open-ended"],
195
+ "extractive_explanation": cos["explanation"]["selected"],
196
+ }
dataset_infos.json ADDED
@@ -0,0 +1 @@
 
1
+ {"v1.0": {"description": "\nCommon Sense Explanations (CoS-E) allows for training language models to\nautomatically generate explanations that can be used during training and\ninference in a novel Commonsense Auto-Generated Explanation (CAGE) framework.\n", "citation": "\n@inproceedings{rajani2019explain,\n title = \"Explain Yourself! Leveraging Language models for Commonsense Reasoning\",\n author = \"Rajani, Nazneen Fatema and\n McCann, Bryan and\n Xiong, Caiming and\n Socher, Richard\",\n year=\"2019\",\n booktitle = \"Proceedings of the 2019 Conference of the Association for Computational Linguistics (ACL2019)\",\n url =\"https://arxiv.org/abs/1906.02361\"\n}\n", "homepage": "https://github.com/salesforce/cos-e", "license": "", "features": {"id": {"dtype": "string", "id": null, "_type": "Value"}, "question": {"dtype": "string", "id": null, "_type": "Value"}, "choices": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "answer": {"dtype": "string", "id": null, "_type": "Value"}, "abstractive_explanation": {"dtype": "string", "id": null, "_type": "Value"}, "extractive_explanation": {"dtype": "string", "id": null, "_type": "Value"}}, "supervised_keys": null, "builder_name": "cos_e", "config_name": "v1.0", "version": {"version_str": "1.0.0", "description": "", "datasets_version_to_prepare": null, "major": 1, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 2077517, "num_examples": 7610, "dataset_name": "cos_e"}, "validation": {"name": "validation", "num_bytes": 261887, "num_examples": 950, "dataset_name": "cos_e"}}, "download_checksums": {"https://raw.githubusercontent.com/salesforce/cos-e/master/data/v1.0/train_rand_split.jsonl": {"num_bytes": 2160200, "checksum": "1989ce97e24d8572113d6a18f44e0f11ee9d206fb9bf9a1133937645583e697e"}, "https://raw.githubusercontent.com/salesforce/cos-e/master/data/v1.0/dev_rand_split.jsonl": {"num_bytes": 268531, "checksum": "790dd2a8492e7f3b51ded04116de603115b7acaded32ea84f6a7101f9d571ac1"}, "https://raw.githubusercontent.com/salesforce/cos-e/master/data/v1.0/test_rand_split_no_answers.jsonl": {"num_bytes": 250752, "checksum": "b9c3d1319667ea1569be6f7b3ed0546bd8222d2f3a759f928307343a0282e190"}, "https://raw.githubusercontent.com/salesforce/cos-e/master/data/v1.0/cose_dev_v1.0_processed.jsonl": {"num_bytes": 182444, "checksum": "ab7b8ac91bca1a6ba798816af6aca703a739f576c919360ddc376d9d3046be53"}, "https://raw.githubusercontent.com/salesforce/cos-e/master/data/v1.0/cose_train_v1.0_processed.jsonl": {"num_bytes": 1433393, "checksum": "df9f83ac4891f38e0771470858d5f1c4b5bb08fee5c53f38f9df9b3d3675ea74"}}, "download_size": 4295320, "dataset_size": 2339404, "size_in_bytes": 6634724}, "v1.11": {"description": "\nCommon Sense Explanations (CoS-E) allows for training language models to\nautomatically generate explanations that can be used during training and\ninference in a novel Commonsense Auto-Generated Explanation (CAGE) framework.\n", "citation": "\n@inproceedings{rajani2019explain,\n title = \"Explain Yourself! Leveraging Language models for Commonsense Reasoning\",\n author = \"Rajani, Nazneen Fatema and\n McCann, Bryan and\n Xiong, Caiming and\n Socher, Richard\",\n year=\"2019\",\n booktitle = \"Proceedings of the 2019 Conference of the Association for Computational Linguistics (ACL2019)\",\n url =\"https://arxiv.org/abs/1906.02361\"\n}\n", "homepage": "https://github.com/salesforce/cos-e", "license": "", "features": {"id": {"dtype": "string", "id": null, "_type": "Value"}, "question": {"dtype": "string", "id": null, "_type": "Value"}, "choices": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "answer": {"dtype": "string", "id": null, "_type": "Value"}, "abstractive_explanation": {"dtype": "string", "id": null, "_type": "Value"}, "extractive_explanation": {"dtype": "string", "id": null, "_type": "Value"}}, "supervised_keys": null, "builder_name": "cos_e", "config_name": "v1.11", "version": {"version_str": "1.11.0", "description": "", "datasets_version_to_prepare": null, "major": 1, "minor": 11, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 2717420, "num_examples": 9741, "dataset_name": "cos_e"}, "validation": {"name": "validation", "num_bytes": 331760, "num_examples": 1221, "dataset_name": "cos_e"}}, "download_checksums": {"https://s3.amazonaws.com/commensenseqa/train_rand_split.jsonl": {"num_bytes": 3785890, "checksum": "58ffa3c8472410e24b8c43f423d89c8a003d8284698a6ed7874355dedd09a2fb"}, "https://s3.amazonaws.com/commensenseqa/dev_rand_split.jsonl": {"num_bytes": 471653, "checksum": "3210497fdaae614ac085d9eb873dd7f4d49b6f965a93adadc803e1229fd8a02a"}, "https://s3.amazonaws.com/commensenseqa/test_rand_split_no_answers.jsonl": {"num_bytes": 423148, "checksum": "b426896d71a9cd064cf01cfaf6e920817c51701ef66028883ac1af2e73ad5f29"}, "https://raw.githubusercontent.com/salesforce/cos-e/master/data/v1.11/cose_dev_v1.11_processed.jsonl": {"num_bytes": 200867, "checksum": "a8367c94901ba249e48bcec76eaff9e7b91cec0f0e4d94879975d7d1b952bc41"}, "https://raw.githubusercontent.com/salesforce/cos-e/master/data/v1.11/cose_train_v1.11_processed.jsonl": {"num_bytes": 1653976, "checksum": "4c0ccfd34243cf7af62b441643437769663edcb980b991487f766b97a547e9bd"}}, "download_size": 6535534, "dataset_size": 3049180, "size_in_bytes": 9584714}}
dummy/v1.0/1.0.0/dummy_data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:412f23ac1e2385dff4f5b9a60acec2d64206ea76c63921acea172a5bd38fc3a6
3
+ size 2840
dummy/v1.11/1.11.0/dummy_data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:eb8c9d91a32a215f1df06f5ff34130f1ff18b730092c243e2fa91bdcf4006739
3
+ size 3118