jamescalam commited on
Commit
8517dbb
1 Parent(s): eec7f57

Create new file

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