File size: 4,015 Bytes
773b156
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21ce35e
 
 
 
 
 
773b156
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21ce35e
773b156
 
 
 
21ce35e
 
773b156
 
 
 
 
21ce35e
 
773b156
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# coding=utf-8
# Copyright 2020 the HuggingFace Datasets Authors.
#
# 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.

# Lint as: python3
"""Dataset of task-like and hopefully-not-task-like examples."""


import json
import datasets

_DESCRIPTION = """\
This dataset is a collection of prompted examples from P3 and examples from C4.
The C4 examples are labeled "not-task-like" and the P3 examples are
"task-like". Examples were sampled from C4 so that the distribution of example
lengths is similar for C4 and P3 examples. Some datasets from P3 were ignored
because their examples were too long. Some datasets from P3 are held out for
validation. Non-tasky validation data was gathered from C4 without
intentionally matching the length distribution. Tasky data was gathered from
the validation set of certain held-out datasets from P3.
"""


class TaskyOrNot(datasets.GeneratorBasedBuilder):
    """Dataset of tasky and non-tasky text data."""
    _DATA_URLS = {
        "p3_train": "p3_examples_train.json",
        "p3_dev": "p3_examples_dev.json",
        "c4_train": "c4_examples_train.json",
        "c4_dev": "c4_examples_dev.json",
    }

    BUILDER_CONFIGS = [
        datasets.BuilderConfig(
            name="10xp3_10xc4",
            version=datasets.Version("1.0.0", ""),
            description=(
                "10 tasky examples per prompt/dataset combination; "
                "10 non-tasky examples per tasky example"),
        )
    ]

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features(
                {
                    "text": datasets.Value("string"),
                    "dataset": datasets.Value("string"),
                    "prompt": datasets.Value("string"),
                    "label": datasets.features.ClassLabel(
                        names=["not tasky", "tasky"]
                    ),
                }
            ),
            supervised_keys=None,
            homepage="https://github.com/craffel/tasky-data",
            citation="",
        )

    def _split_generators(self, dl_manager):
        files = dl_manager.download(self._DATA_URLS)
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={
                    "tasky_file": files["p3_train"],
                    "non_tasky_file": files["c4_train"],
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.VALIDATION,
                gen_kwargs={
                    "tasky_file": files["p3_dev"],
                    "non_tasky_file": files["c4_dev"],
                },
            ),
        ]

    def _generate_examples(self, tasky_file, non_tasky_file):
        with open(tasky_file) as f:
            tasky_examples = json.load(f)
        idx = 0
        for dataset, prompts in tasky_examples.items():
            for prompt, examples in prompts.items():
                for text in examples:
                    yield idx, {
                        "text": text,
                        "dataset": dataset,
                        "prompt": prompt,
                        "label": 1,
                    }
                    idx += 1

        with open(non_tasky_file) as f:
            non_tasky_examples = json.load(f)
        for text in non_tasky_examples:
            yield idx, {
                "text": text, "dataset": "c4", "prompt": "N/A", "label": 0
            }
            idx += 1