Datasets:

Languages:
English
Multilinguality:
monolingual
Size Categories:
10K<n<100K
Language Creators:
crowdsourced
Annotations Creators:
crowdsourced
ArXiv:
Tags:
License:
albertvillanova HF staff commited on
Commit
29e6cdd
1 Parent(s): 247d103

Delete loading script

Browse files
Files changed (1) hide show
  1. cos_e.py +0 -194
cos_e.py DELETED
@@ -1,194 +0,0 @@
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
-
20
- import json
21
-
22
- import datasets
23
-
24
-
25
- _CITATION = """
26
- @inproceedings{rajani2019explain,
27
- title = {Explain Yourself! Leveraging Language models for Commonsense Reasoning},
28
- author = {Rajani, Nazneen Fatema and
29
- McCann, Bryan and
30
- Xiong, Caiming and
31
- Socher, Richard}
32
- year={2019}
33
- booktitle = {Proceedings of the 2019 Conference of the Association for Computational Linguistics (ACL2019)}
34
- url ={https://arxiv.org/abs/1906.02361}
35
- }
36
- """
37
-
38
- _DESCRIPTION = """
39
- Common Sense Explanations (CoS-E) allows for training language models to
40
- automatically generate explanations that can be used during training and
41
- inference in a novel Commonsense Auto-Generated Explanation (CAGE) framework.
42
- """
43
-
44
- _COS_E_URL = "https://raw.githubusercontent.com/salesforce/cos-e/master/data/"
45
-
46
- # COS E has explanations for the CQA dataset, which is joined by ID.
47
- _CQA_V1_11_URL_TRAIN = "https://s3.amazonaws.com/commensenseqa/train_rand_split.jsonl"
48
- _CQA_V1_11_URL_DEV = "https://s3.amazonaws.com/commensenseqa/dev_rand_split.jsonl"
49
- _CQA_V1_11_URL_TEST = "https://s3.amazonaws.com/commensenseqa/test_rand_split_no_answers.jsonl"
50
-
51
- _CQA_V1_0_URL_TRAIN = _COS_E_URL + "v1.0/train_rand_split.jsonl"
52
- _CQA_V1_0_URL_DEV = _COS_E_URL + "v1.0/dev_rand_split.jsonl"
53
- _CQA_V1_0_URL_TEST = _COS_E_URL + "v1.0/test_rand_split_no_answers.jsonl"
54
-
55
-
56
- def _download_and_index_cqa(dl_manager, name):
57
- """Downloads CQA and returns it, indexed by id, for joining with Cos-E."""
58
-
59
- downloaded_files = dl_manager.download_and_extract(
60
- {
61
- "cqa_train": _CQA_V1_11_URL_TRAIN if name == "v1.11" else _CQA_V1_0_URL_TRAIN,
62
- "cqa_dev": _CQA_V1_11_URL_DEV if name == "v1.11" else _CQA_V1_0_URL_DEV,
63
- "cqa_test": _CQA_V1_11_URL_TEST if name == "v1.11" else _CQA_V1_0_URL_TEST,
64
- }
65
- )
66
-
67
- # NB: "cqa_test" is included in the files, but not in any of the CoS-E splits.
68
- cqa_splits = ["cqa_train", "cqa_dev"]
69
- cqa_complete = []
70
- for split in cqa_splits:
71
- with open(downloaded_files[split], encoding="utf-8") as f:
72
- for _, line in enumerate(f):
73
- d = json.loads(line)
74
- cqa_complete.append(d)
75
-
76
- # Index the CQA dataset by id for joining with Cos-E.
77
- cqa_indexed = {}
78
- for d in cqa_complete:
79
- cqa_indexed[d["id"]] = d
80
- return cqa_indexed
81
-
82
-
83
- def _get_choices_and_answer(cqa):
84
- """Returns choices and the answer from a cqa example."""
85
- choices = []
86
- answer_key = cqa["answerKey"]
87
- answer = None
88
- for choice in cqa["question"]["choices"]:
89
- choices.append(choice["text"])
90
- if answer_key == choice["label"]:
91
- answer = choice["text"]
92
- return choices, answer
93
-
94
-
95
- class CosEConfig(datasets.BuilderConfig):
96
-
97
- """BuilderConfig for CosE"""
98
-
99
- def __init__(self, **kwargs):
100
- """
101
-
102
- Args:
103
- **kwargs: keyword arguments forwarded to super.
104
- """
105
- super(CosEConfig, self).__init__(**kwargs)
106
-
107
-
108
- class CosE(datasets.GeneratorBasedBuilder):
109
- """CoS-E: Common Sense Explanations corpus."""
110
-
111
- BUILDER_CONFIGS = [
112
- CosEConfig(
113
- name="v1.0",
114
- description="cos-e version 1.0",
115
- version=datasets.Version("1.0.0", ""),
116
- ),
117
- CosEConfig(
118
- name="v1.11",
119
- description="cos-e version 1.11",
120
- version=datasets.Version("1.11.0", ""),
121
- ),
122
- ]
123
-
124
- def _info(self):
125
- return datasets.DatasetInfo(
126
- description=_DESCRIPTION,
127
- features=datasets.Features(
128
- {
129
- "id": datasets.Value("string"),
130
- "question": datasets.Value("string"),
131
- "choices": datasets.features.Sequence(datasets.Value("string")),
132
- "answer": datasets.Value("string"),
133
- "abstractive_explanation": datasets.Value("string"),
134
- "extractive_explanation": datasets.Value("string"),
135
- }
136
- ),
137
- supervised_keys=None,
138
- homepage="https://github.com/salesforce/cos-e",
139
- citation=_CITATION,
140
- )
141
-
142
- def _split_generators(self, dl_manager):
143
- """Returns SplitGenerators."""
144
-
145
- # NB: The CQA Dataset should be read only once, and only by callers who
146
- # want to _create_ the Cos-E dataset from scratch.
147
- cqa_indexed = _download_and_index_cqa(dl_manager, self.config.name)
148
-
149
- if self.config.name == "v1.11":
150
- files = dl_manager.download_and_extract(
151
- {
152
- "dev": [_COS_E_URL + "v1.11/cose_dev_v1.11_processed.jsonl"],
153
- "train": [_COS_E_URL + "v1.11/cose_train_v1.11_processed.jsonl"],
154
- }
155
- )
156
-
157
- elif self.config.name == "v1.0":
158
- files = dl_manager.download_and_extract(
159
- {
160
- "dev": [_COS_E_URL + "v1.0/cose_dev_v1.0_processed.jsonl"],
161
- "train": [_COS_E_URL + "v1.0/cose_train_v1.0_processed.jsonl"],
162
- }
163
- )
164
- else:
165
- raise ValueError("Unknown config name")
166
- # We use the CoS-E/CQA dev set as our validation set.
167
- return [
168
- datasets.SplitGenerator(
169
- name=datasets.Split.TRAIN,
170
- gen_kwargs={"files": files["train"], "cqa_indexed": cqa_indexed},
171
- ),
172
- datasets.SplitGenerator(
173
- name=datasets.Split.VALIDATION,
174
- gen_kwargs={"files": files["dev"], "cqa_indexed": cqa_indexed},
175
- ),
176
- ]
177
-
178
- def _generate_examples(self, files, **kwargs):
179
- """Yields examples."""
180
- cqa_indexed = kwargs["cqa_indexed"]
181
- for filepath in files:
182
- with open(filepath, encoding="utf-8") as f:
183
- for line in f:
184
- cos = json.loads(line)
185
- cqa = cqa_indexed[cos["id"]]
186
- choices, answer = _get_choices_and_answer(cqa)
187
- yield cos["id"], {
188
- "id": cos["id"],
189
- "question": cqa["question"]["stem"],
190
- "choices": choices,
191
- "answer": answer,
192
- "abstractive_explanation": cos["explanation"]["open-ended"],
193
- "extractive_explanation": cos["explanation"]["selected"],
194
- }