File size: 11,136 Bytes
02af0df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241ad50
02af0df
241ad50
 
 
 
02af0df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
de9e147
 
02af0df
 
 
de9e147
02af0df
 
 
 
 
 
 
 
 
 
de9e147
02af0df
 
 
 
 
 
 
 
 
 
de9e147
02af0df
 
 
 
 
 
 
 
 
 
de9e147
02af0df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241ad50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
02af0df
241ad50
 
 
 
02af0df
 
241ad50
 
 
02af0df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Only Connect Wall (OCW) dataset"""

import json
import os

import datasets


_CITATION = """\
@article{Naeini2023LargeLM,
    title        = {Large Language Models are Fixated by Red Herrings: Exploring Creative Problem Solving and Einstellung Effect using the Only Connect Wall Dataset},
    author       = {Saeid Alavi Naeini and Raeid Saqur and Mozhgan Saeidi and John Giorgi and Babak Taati},
    year         = 2023,
    journal      = {ArXiv},
    volume       = {abs/2306.11167},
    url          = {https://api.semanticscholar.org/CorpusID:259203717}
}
"""

_DESCRIPTION = """\
The Only Connect Wall (OCW) dataset contains 618 "Connecting Walls" from the Round 3: Connecting Wall segment of the Only Connect quiz show, collected from 15 seasons' worth of episodes. Each wall contains the ground-truth groups and connections as well as recorded human performance.
"""

_HOMEPAGE_URL = "https://github.com/TaatiTeam/OCW/"

_LICENSE = "MIT"

_BASE_URL = "https://www.cs.toronto.edu/~taati/OCW/"
_URLS = {
    "ocw": _BASE_URL + "OCW.tar.gz",
    "ocw_randomized": _BASE_URL + "OCW_randomized.tar.gz",
    "ocw_wordnet": _BASE_URL + "OCW_wordnet.tar.gz"
    
}


class OCW(datasets.GeneratorBasedBuilder):
    """OCW dataset"""

    VERSION = datasets.Version("1.0.0")

    BUILDER_CONFIGS = [
        datasets.BuilderConfig(name="ocw", version=VERSION,
                               description="main OCW dataset"),
        datasets.BuilderConfig(name="ocw_randomized", version=VERSION,
                               description="Easy OCW dataset with randomized groups in each wall"),
        datasets.BuilderConfig(name="ocw_wordnet", version=VERSION,
                               description="Easy OCW dataset with wordnet synonyms replaced with original clues")
    ]

    DEFAULT_CONFIG_NAME = "ocw"

    def _info(self):
        features = datasets.Features(
            {
                # "total_walls_in_season": datasets.Value("int32"),
                # "season_start_date": datasets.Value("string"),
                # "season_end_date": datasets.Value("string"),
                "wall_id": datasets.Value("string"),
                "season": datasets.Value("int32"),
                "episode": datasets.Value("int32"),
                "words": datasets.features.Sequence(feature=datasets.Value("string")),
                "gt_connections": datasets.features.Sequence(feature=datasets.Value("string")),
                "group_1":
                    {
                        "group_id": datasets.Value("string"),
                        "gt_words":datasets.features.Sequence(feature=datasets.Value("string")),
                        "gt_connection": datasets.Value("string"),
                        "human_performance":
                            {
                            "grouping": datasets.Value("int32"),
                            "connection": datasets.Value("int32")
                            }
                    },
                "group_2":
                    {
                        "group_id": datasets.Value("string"),
                        "gt_words": datasets.features.Sequence(feature=datasets.Value("string")),
                        "gt_connection": datasets.Value("string"),
                        "human_performance": 
                            {
                            "grouping": datasets.Value("int32"),
                            "connection": datasets.Value("int32")
                            }
                    },
                "group_3":
                    {
                        "group_id": datasets.Value("string"),
                        "gt_words": datasets.features.Sequence(feature=datasets.Value("string")),
                        "gt_connection": datasets.Value("string"),
                        "human_performance":
                            {
                            "grouping": datasets.Value("int32"),
                            "connection": datasets.Value("int32")
                            }
                    },
                "group_4":
                    {
                        "group_id": datasets.Value("string"),
                        "gt_words": datasets.features.Sequence(feature=datasets.Value("string")),
                        "gt_connection": datasets.Value("string"),
                        "human_performance":
                            {
                            "grouping": datasets.Value("int32"),
                            "connection": datasets.Value("int32")
                            }
                    },

            }
        )
        return datasets.DatasetInfo(
            # This is the description that will appear on the datasets page.
            description=_DESCRIPTION,
            # This defines the different columns of the dataset and their types
            features= features,
            # Homepage of the dataset for documentation
            homepage=_HOMEPAGE_URL,
            # License for the dataset if available
            license=_LICENSE,
            # Citation for the dataset
            citation=_CITATION,
            # No default supervised_keys
            supervised_keys=None
        )

    def _split_generators(self, dl_manager):
        url = _URLS[self.config.name]
        if self.config.name == "ocw_randomized":
            url = [url, _URLS[self.DEFAULT_CONFIG_NAME]]
        path = dl_manager.download_and_extract(url)
        if self.config.name == self.DEFAULT_CONFIG_NAME:
            dir = 'dataset'
            train_filepath = os.path.join(path, dir, 'train.json')
            val_filepath = os.path.join(path, dir, 'validation.json')
            test_filepath = os.path.join(path, dir, 'test.json')
        elif self.config.name == "ocw_randomized":
            # OCW-randomized only contains a test set, we load main OCW train/validation files
            dir = 'OCW_randomized'
            dir2 = 'dataset'
            train_filepath = os.path.join(path[1], dir2, 'train.json')
            val_filepath = os.path.join(path[1], dir2, 'validation.json')
            test_filepath = os.path.join(path[0], dir, 'easy_test.json')
        else:
            dir = 'OCW_wordnet'
            train_filepath = os.path.join(path, dir, 'easy_train_wordnet.json')
            val_filepath = os.path.join(path, dir, 'easy_validation_wordnet.json')
            test_filepath = os.path.join(path, dir, 'easy_test_wordnet.json')

        return [
            datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_filepath}),
            datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": val_filepath}),
            datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": test_filepath}),
        ]


    def _generate_examples(self, filepath):
        """This function returns the examples in the raw (text) form."""
        key = 0
        with open(filepath, encoding="utf-8") as f:
            ocw = json.load(f)
            for data in ocw["dataset"]:
                wall_id = data.get("wall_id")
                season = data.get("season")
                # season_to_walls_map = ocw['season_to_walls_map'][str(season)]
                # total_walls_in_season = season_to_walls_map["num_walls"]
                # season_start_date = season_to_walls_map["start_date"]
                # season_end_date = season_to_walls_map["end_date"]
                episode = data.get("episode")
                words = data.get("words")
                gt_connections = data.get("gt_connections")
                group_1 = data['groups']['group_1']
                group_1_human_performance = group_1['human_performance']
                group_2 = data['groups']['group_2']
                group_2_human_performance = group_2['human_performance']
                group_3 = data['groups']['group_3']
                group_3_human_performance = group_3['human_performance']
                group_4 = data['groups']['group_4']
                group_4_human_performance = group_4['human_performance']
                yield key, {
                    # "total_walls_in_season": total_walls_in_season,
                    # "season_start_date": season_start_date,
                    # "season_end_date": season_end_date,
                    "wall_id": wall_id,
                    "season": season,
                    "episode": episode,
                    "words": words,
                    "gt_connections": gt_connections,
                    "group_1": {
                        "group_id": group_1.get("group_id"),
                        "gt_words": group_1.get("gt_words"),
                        "gt_connection": group_1.get("gt_connection"),
                        "human_performance": {
                            "grouping": group_1_human_performance.get("grouping"),
                            "connection": group_1_human_performance.get("connection")
                        }
                    },
                    "group_2": {
                        "group_id": group_2.get("group_id"),
                        "gt_words": group_2.get("gt_words"),
                        "gt_connection": group_2.get("gt_connection"),
                        "human_performance": {
                            "grouping": group_2_human_performance.get("grouping"),
                            "connection": group_2_human_performance.get("connection")
                        }
                    },
                    "group_3": {
                        "group_id": group_3.get("group_id"),
                        "gt_words": group_3.get("gt_words"),
                        "gt_connection": group_3.get("gt_connection"),
                        "human_performance": {
                            "grouping": group_3_human_performance.get("grouping"),
                            "connection": group_3_human_performance.get("connection")
                        }
                    },
                    "group_4": {
                        "group_id": group_4.get("group_id"),
                        "gt_words": group_4.get("gt_words"),
                        "gt_connection": group_4.get("gt_connection"),
                        "human_performance": {
                            "grouping": group_4_human_performance.get("grouping"),
                            "connection": group_4_human_performance.get("connection")
                        }
                    },
                }
                key += 1