dchaplinsky commited on
Commit
c7f1ebe
1 Parent(s): 730c9a4

Upload every_prompt.py

Browse files
Files changed (1) hide show
  1. every_prompt.py +62 -0
every_prompt.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import datasets
3
+
4
+ logger = datasets.logging.get_logger(__name__)
5
+
6
+
7
+ _DESCRIPTION = """\
8
+ Every prompt dataset.
9
+ Every Prompt is a data-driven approach to mining instructions from the web.
10
+ It contains over a million FAQs and HowTos from around the world in a structured format.
11
+ 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
12
+ """
13
+
14
+
15
+ _URLS = [
16
+ "every_prompt_sample.jsonlines",
17
+ ]
18
+
19
+
20
+ class EveryPromptDataset(datasets.GeneratorBasedBuilder):
21
+ """Every Prompt Dataset"""
22
+
23
+ VERSION = datasets.Version("1.0.0")
24
+ DEFAULT_CONFIG_NAME = "default"
25
+ BUILDER_CONFIGS = [
26
+ datasets.BuilderConfig(name="default", version=VERSION, description=""),
27
+ ]
28
+
29
+ def _info(self):
30
+ return datasets.DatasetInfo(
31
+ description=_DESCRIPTION,
32
+ features=datasets.Features(
33
+ {
34
+ "language": datasets.Value("string"),
35
+ "language_is_reliable": datasets.Value("bool"),
36
+ "text_length": datasets.Value("int32"),
37
+ "data_length": datasets.Value("int32"),
38
+ "text_to_data_ratio": datasets.Value("float32"),
39
+ "url": datasets.Value("string"),
40
+ "schema_type": datasets.Value("string"),
41
+ "payload": {},
42
+ }
43
+ ),
44
+ )
45
+
46
+ def _split_generators(self, dl_manager):
47
+ downloaded_files = dl_manager.download(_URLS)
48
+
49
+ return [
50
+ datasets.SplitGenerator(
51
+ name=datasets.Split.TRAIN, gen_kwargs={"filepaths": downloaded_files}
52
+ )
53
+ ]
54
+
55
+ def _generate_examples(self, filepaths):
56
+ """This function returns the examples in the raw (text) form."""
57
+ logger.info("generating examples from = %s", filepaths)
58
+ for path in filepaths:
59
+ with open(path, encoding="utf-8") as f:
60
+ for instruction_str in f:
61
+ instruction = json.loads(instruction_str)
62
+ yield instruction["url"], instruction