TunahanGokcimen commited on
Commit
51883bf
1 Parent(s): 66925c0

Create HomeAppliancesDataset.py

Browse files
Files changed (1) hide show
  1. HomeAppliancesDataset.py +120 -0
HomeAppliancesDataset.py ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """QnAData Question Answering Dataset"""
2
+
3
+
4
+ import json
5
+
6
+ import datasets
7
+ from datasets.tasks import QuestionAnsweringExtractive
8
+
9
+
10
+ logger = datasets.logging.get_logger(__name__)
11
+
12
+
13
+ _CITATION = """\
14
+ a
15
+ """
16
+
17
+ _DESCRIPTION = """\
18
+ a
19
+ """
20
+
21
+ _URL = "https://raw.githubusercontent.com/Gokcimen/Home_Appliance_Dataset/master/"
22
+ _URLS = {
23
+ "train": _URL + "train.json",
24
+ "test": _URL + "test.json",
25
+ "dev": _URL + "dev.json",
26
+ }
27
+
28
+
29
+ class QnADataConfig(datasets.BuilderConfig):
30
+ """BuilderConfig for QnAData."""
31
+
32
+ def __init__(self, **kwargs):
33
+ """BuilderConfig for QnAData.
34
+ Args:
35
+ **kwargs: keyword arguments forwarded to super.
36
+ """
37
+ super(QnADataConfig, self).__init__(**kwargs)
38
+
39
+
40
+ class QnAData(datasets.GeneratorBasedBuilder):
41
+ """The QnAData Question Answering Dataset. Version 1.0."""
42
+
43
+ BUILDER_CONFIGS = [
44
+ QnADataConfig(
45
+ name="plain_text",
46
+ version=datasets.Version("1.0.0"),
47
+ description="Plain text",
48
+ ),
49
+ ]
50
+
51
+ def _info(self):
52
+ return datasets.DatasetInfo(
53
+ description=_DESCRIPTION,
54
+ features=datasets.Features(
55
+ {
56
+ "id": datasets.Value("string"),
57
+ "title": datasets.Value("string"),
58
+ "context": datasets.Value("string"),
59
+ "question": datasets.Value("string"),
60
+ "answers": datasets.features.Sequence(
61
+ {
62
+ "text": datasets.Value("string"),
63
+ "answer_start": datasets.Value("int32"),
64
+ "answer_end": datasets.Value("int32"),
65
+ }
66
+ ),
67
+ }
68
+ ),
69
+ # No default supervised_keys (as we have to pass both question
70
+ # and context as input).
71
+ supervised_keys=None,
72
+ homepage="https://raw.githubusercontent.com/Gokcimen/Home_Appliance_Dataset/master/train.json",
73
+ citation=_CITATION,
74
+ task_templates=[
75
+ QuestionAnsweringExtractive(
76
+ question_column="question", context_column="context", answers_column="answers"
77
+ )
78
+ ],
79
+ )
80
+
81
+ def _split_generators(self, dl_manager):
82
+ urls_to_download = _URLS
83
+ downloaded_files = dl_manager.download_and_extract(urls_to_download)
84
+
85
+ return [
86
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
87
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
88
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
89
+ ]
90
+
91
+ def _generate_examples(self, filepath):
92
+ """This function returns the examples in the raw (text) form."""
93
+ logger.info("generating examples from = %s", filepath)
94
+ with open(filepath, encoding="utf-8") as f:
95
+ dataset = json.load(f)
96
+ for article in dataset["data"]:
97
+ title = article.get("title", "").strip()
98
+ for paragraph in article["paragraphs"]:
99
+ context = paragraph["context"].strip()
100
+ for qa in paragraph["qas"]:
101
+ question = qa["question"].strip()
102
+ id_ = qa["id"]
103
+
104
+ answer_starts = [answer["answer_start"] for answer in qa["answers"]]
105
+ answer_end = [answer["answer_end"] for answer in qa["answers"]]
106
+ answers = [answer["text"].strip() for answer in qa["answers"]]
107
+
108
+ # Features currently used are "context", "question", and "answers".
109
+ # Others are extracted here for the ease of future expansions.
110
+ yield id_, {
111
+ "title": title,
112
+ "context": context,
113
+ "question": question,
114
+ "id": id_,
115
+ "answers": {
116
+ "answer_start": answer_starts,
117
+ "answer_end": answer_end,
118
+ "text": answers,
119
+ },
120
+ }