File size: 2,157 Bytes
c7f1ebe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ddfee72
c7f1ebe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8eb4cf5
c7f1ebe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e1748d2
c7f1ebe
 
 
 
e1748d2
 
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
import json
import datasets

logger = datasets.logging.get_logger(__name__)


_DESCRIPTION = """\
Every prompt dataset.
Every Prompt is a data-driven approach to mining instructions from the web.
It contains over a million FAQs and HowTos from around the world in a structured format.
It also has basic pre-processing to calculate the length of the useful text and identify the language of that text with the help of GCLD3
"""


_URLS = [
    "every_prompt.jsonlines",
]


class EveryPromptDataset(datasets.GeneratorBasedBuilder):
    """Every Prompt Dataset"""

    VERSION = datasets.Version("1.0.0")
    DEFAULT_CONFIG_NAME = "default"
    BUILDER_CONFIGS = [
        datasets.BuilderConfig(name="default", version=VERSION, description=""),
    ]

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features(
                {
                    "language": datasets.Value("string"),
                    "language_is_reliable": datasets.Value("bool"),
                    "text_length": datasets.Value("int32"),
                    "data_length": datasets.Value("int32"),
                    "text_to_data_ratio": datasets.Value("float32"),
                    "url": datasets.Value("string"),
                    "schema_type": datasets.Value("string"),
                    "payload": datasets.Value("string"),
                }
            ),
        )

    def _split_generators(self, dl_manager):
        downloaded_files = dl_manager.download(_URLS)

        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN, gen_kwargs={"filepaths": downloaded_files}
            )
        ]

    def _generate_examples(self, filepaths):
        """This function returns the examples in the raw (text) form."""
        logger.info("generating examples from = %s", filepaths)
        key = 0
        for path in filepaths:
            with open(path, encoding="utf-8") as f:
                for instruction_str in f:
                    instruction = json.loads(instruction_str)
                    yield key, instruction
                    key += 1