siyangliu commited on
Commit
47dcb7c
1 Parent(s): b3134f1

load_script

Browse files
Files changed (1) hide show
  1. loading_script.py +109 -0
loading_script.py ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # coding=utf-8
3
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ """PsyQA dataset."""
17
+
18
+
19
+ import json
20
+ import os
21
+
22
+ import datasets
23
+
24
+
25
+
26
+ _DESCRIPTION = """ FutureWarning
27
+ """
28
+ _CITATION = """ null """
29
+ _URLs = {
30
+ "train": "https://huggingface.co/datasets/siyangliu/PsyQA/resolve/main/train.json",
31
+ "valid": "https://huggingface.co/datasets/siyangliu/PsyQA/resolve/main/valid.json",
32
+ "test": "https://huggingface.co/datasets/siyangliu/PsyQA/resolve/main/test.json",
33
+ }
34
+
35
+
36
+ class PsyQA(datasets.GeneratorBasedBuilder):
37
+ """PsyQA dataset."""
38
+
39
+ VERSION = datasets.Version("1.1.0")
40
+
41
+ BUILDER_CONFIGS = [
42
+ datasets.BuilderConfig(
43
+ name="plain_text",
44
+ description="Plain text",
45
+ version=VERSION,
46
+ )
47
+ ]
48
+
49
+ def _info(self):
50
+ return datasets.DatasetInfo(
51
+ description=_DESCRIPTION,
52
+ features=datasets.Features(
53
+ {
54
+ "question": datasets.Value("string"),
55
+ "questionID": datasets.Value("int16"),
56
+ "description": datasets.Value("string"),
57
+ "keywords": datasets.Value("string"),
58
+ "answer": datasets.Value("string"),
59
+ "has_label": datasets.Value("bool"),
60
+ "label_sequence":datasets.features.Sequence(
61
+ {
62
+ "start": datasets.Value("int16"),
63
+ "end": datasets.Value("int16"),
64
+ "type": datasets.Value("string"),
65
+ }
66
+ ),
67
+ }
68
+ ),
69
+ supervised_keys=None,
70
+ homepage="https://huggingface.co/datasets/siyangliu/PsyQA",
71
+ citation=_CITATION,
72
+ )
73
+
74
+ def _split_generators(self, dl_manager):
75
+ """Returns SplitGenerators."""
76
+ data_dir = dl_manager.download_and_extract(_URLs)
77
+ return [
78
+ datasets.SplitGenerator(
79
+ name=datasets.Split.TRAIN,
80
+ gen_kwargs={
81
+ "filepath": data_dir["train"],
82
+ },
83
+ ),
84
+ datasets.SplitGenerator(
85
+ name=datasets.Split.TEST,
86
+ gen_kwargs={
87
+ "filepath": data_dir["test"],
88
+ },
89
+ ),
90
+ datasets.SplitGenerator(
91
+ name=datasets.Split.VALIDATION,
92
+ gen_kwargs={
93
+ "filepath": data_dir["valid"],
94
+ },
95
+ ),
96
+ ]
97
+
98
+ def _generate_examples(self, input_filepath, label_filepath=None):
99
+ """Yields examples."""
100
+ with open(input_filepath, encoding="utf-8") as input_file:
101
+ dataset = json.load(input_file)
102
+ idx = 0
103
+ for meta_data in dataset:
104
+ for ans in meta_data["answers"]:
105
+ yield idx, {"question": meta_data["question"], "description": meta_data["description"], "keywords": meta_data["keywords"], "answer": ans["answer_text"], \
106
+ "label_sequence": ans["label_sequence"], "questionID": meta_data["questionID"], "has_label": meta_data["has_label"],}
107
+ idx += 1
108
+
109
+