rajivmehtapy commited on
Commit
2a62cc4
1 Parent(s): 9f5bd91

Upload reddit-builder-config.py

Browse files
Files changed (1) hide show
  1. reddit-builder-config.py +72 -0
reddit-builder-config.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ import datasets
4
+ from datasets.tasks import QuestionAnsweringExtractive
5
+
6
+
7
+ logger = datasets.logging.get_logger(__name__)
8
+
9
+
10
+ _CITATION = """\
11
+ @article{2016arXiv160605250R,
12
+ author = {{Rajpurkar}, Pranav and {Zhang}, Jian and {Lopyrev},
13
+ Konstantin and {Liang}, Percy},
14
+ title = "{SQuAD: 100,000+ Questions for Machine Comprehension of Text}",
15
+ journal = {arXiv e-prints},
16
+ year = 2016,
17
+ eid = {arXiv:1606.05250},
18
+ pages = {arXiv:1606.05250},
19
+ archivePrefix = {arXiv},
20
+ eprint = {1606.05250},
21
+ }
22
+ """
23
+
24
+ _DESCRIPTION = """\
25
+ Demo...
26
+ """
27
+
28
+ _URL = "https://github.com/rajivmehtaflex/PythonExp/raw/main/HFDatasets/reddit_data.tar.gz"
29
+
30
+
31
+ class RedditTopicsTargz(datasets.GeneratorBasedBuilder):
32
+ """SQUAD: The Stanford Question Answering Dataset. Version 1.1."""
33
+ def _info(self):
34
+ return datasets.DatasetInfo(
35
+ description=_DESCRIPTION,
36
+ features=datasets.Features(
37
+ {
38
+ "sub": datasets.Value("string"),
39
+ "title": datasets.Value("string"),
40
+ "selftext": datasets.Value("string"),
41
+ "upvote_ratio": datasets.Value("float32"),
42
+ "id": datasets.Value("string"),
43
+ "created_utc": datasets.Value("float32"),
44
+ }
45
+ ),
46
+ # No default supervised_keys (as we have to pass both question
47
+ # and context as input).
48
+ supervised_keys=None,
49
+ homepage="https://github.com/rajivmehtapy/",
50
+ citation=_CITATION,
51
+ )
52
+
53
+ def _split_generators(self, dl_manager):
54
+ path = dl_manager.download_and_extract(_URL)
55
+
56
+ return [
57
+ datasets.SplitGenerator(
58
+ name=datasets.Split.TRAIN,
59
+ gen_kwargs={"filepath": path+'/reddit_data.jsonl'}
60
+ ),
61
+ ]
62
+
63
+ def _generate_examples(self, filepath):
64
+ """This function returns the examples in the raw (text) form."""
65
+ idx = 0
66
+ # open the file and read the lines
67
+ with open(filepath, encoding="utf-8") as fp:
68
+ for line in fp:
69
+ # load json line
70
+ obj = json.loads(line)
71
+ yield idx, obj
72
+ idx += 1