main-horse commited on
Commit
e4bfb2b
1 Parent(s): 2109e62

add code for using the ds

Browse files
Files changed (2) hide show
  1. dataset_code.py +99 -0
  2. example_usage.py +10 -0
dataset_code.py ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datasets
2
+ import logging
3
+ import csv
4
+ import sys
5
+ from csv import DictReader
6
+ csv.field_size_limit(sys.maxsize)
7
+
8
+ logger = logging.getLogger(__name__)
9
+
10
+ class FFV4Config(datasets.BuilderConfig):
11
+ """BuilderConfig for SuperGLUE."""
12
+
13
+ def __init__(self, filename: str, info: str, **kwargs):
14
+ """BuilderConfig for SuperGLUE.
15
+
16
+ Args:
17
+ features: *list[string]*, list of the features that will appear in the
18
+ feature dict. Should not include "label".
19
+ filename: *string*, csvfile for the dataset.
20
+ info: *string*, for information about the data set.
21
+ **kwargs: keyword arguments forwarded to super.
22
+ """
23
+ # Version history:
24
+ # 0.0.1: Initial version
25
+ super().__init__(version=datasets.Version("0.0.1"), **kwargs)
26
+ self.filename = filename
27
+ self.info = info
28
+
29
+ class FFV4(datasets.GeneratorBasedBuilder):
30
+ """The thing"""
31
+
32
+ BUILDER_CONFIGS = [
33
+ FFV4Config(
34
+ name="notebook_defaults",
35
+ filename="notebook_defaults.csv",
36
+ info="the result of using the default values in the V4 ffarchive notebook, except without the TS/RD filter",
37
+ ),
38
+ FFV4Config(
39
+ name="notebook_defaults_ratio0.8_likes10",
40
+ filename="ratio0.8_likes10.csv",
41
+ info="default filter, but with the score filter replaced with '.ratio > 0.8, .likes > 10'",
42
+ ),
43
+ ]
44
+ DEFAULT_CONFIG_NAME = "notebook_defaults"
45
+
46
+
47
+ def _info(self):
48
+ return datasets.DatasetInfo(
49
+ description="Garbage datasets for LLM training",
50
+ features=datasets.Features(
51
+ {
52
+ "id": datasets.Value("int32"),
53
+ "header": datasets.Value("string"),
54
+ "story": datasets.Value("string"),
55
+ }
56
+ ),
57
+ homepage="https://main.horse",
58
+ )
59
+
60
+
61
+ def _split_generators(self, x):
62
+ return [
63
+ datasets.SplitGenerator('everything', gen_kwargs={"filepath": self.config.filename}),
64
+ ]
65
+ '''
66
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
67
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
68
+ '''
69
+
70
+ def _generate_examples(self, filepath):
71
+ """This function returns the examples in the raw (text) form."""
72
+ logger.info("generating examples from = %s", filepath)
73
+ with open(filepath, encoding="utf-8") as f:
74
+ dr = DictReader(f)
75
+ for d in dr:
76
+ yield d['id'],d
77
+ '''
78
+ squad = json.load(f)
79
+ for article in squad["data"]:
80
+ title = article.get("title", "")
81
+ for paragraph in article["paragraphs"]:
82
+ context = paragraph["context"] # do not strip leading blank spaces GH-2585
83
+ for qa in paragraph["qas"]:
84
+ answer_starts = [answer["answer_start"] for answer in qa["answers"]]
85
+ answers = [answer["text"] for answer in qa["answers"]]
86
+ # Features currently used are "context", "question", and "answers".
87
+ # Others are extracted here for the ease of future expansions.
88
+ yield key, {
89
+ "title": title,
90
+ "context": context,
91
+ "question": qa["question"],
92
+ "id": qa["id"],
93
+ "answers": {
94
+ "answer_start": answer_starts,
95
+ "text": answers,
96
+ },
97
+ }
98
+ key += 1
99
+ '''
example_usage.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ import datasets
2
+
3
+ ds = datasets.load_dataset('./dataset_code.py', 'notebook_defaults')
4
+
5
+ ds_real = ds['everything'] # there is no such thing as a train/test split here
6
+ one_item = ds_real[0] # grab first story, and truncuate the text of it to first 1000 characters
7
+ one_item_truncuated = one_item | {'story': one_item['story'][:1000]}
8
+
9
+ print(ds)
10
+ print(one_item_truncuated)