siyangliu commited on
Commit
bb0ff34
1 Parent(s): f02ca70

Upload 7 files

Browse files
Files changed (2) hide show
  1. loading_script.py +41 -14
  2. psyqa_without_strategy.json +1 -0
loading_script.py CHANGED
@@ -18,7 +18,6 @@
18
 
19
  import json
20
  import os
21
-
22
  import datasets
23
 
24
 
@@ -32,6 +31,14 @@ _URLs = {
32
  "test": "https://huggingface.co/datasets/siyangliu/PsyQA/resolve/main/test.json",
33
  }
34
 
 
 
 
 
 
 
 
 
35
 
36
  class PsyQA(datasets.GeneratorBasedBuilder):
37
  """PsyQA dataset."""
@@ -40,8 +47,13 @@ class PsyQA(datasets.GeneratorBasedBuilder):
40
 
41
  BUILDER_CONFIGS = [
42
  datasets.BuilderConfig(
43
- name="plain_text",
44
- description="Plain text",
 
 
 
 
 
45
  version=VERSION,
46
  )
47
  ]
@@ -57,13 +69,14 @@ class PsyQA(datasets.GeneratorBasedBuilder):
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,
@@ -79,31 +92,45 @@ class PsyQA(datasets.GeneratorBasedBuilder):
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
 
 
18
 
19
  import json
20
  import os
 
21
  import datasets
22
 
23
 
 
31
  "test": "https://huggingface.co/datasets/siyangliu/PsyQA/resolve/main/test.json",
32
  }
33
 
34
+ _STRATEGY={"Approval and Reassurance": "[AR]",
35
+ "Interpretation": "[IN]",
36
+ "Self-disclosure": "[SELF]",
37
+ "Direct Guidance": "[DG]",
38
+ "Others": "[OT]",
39
+ "Restatement": "[RES]",
40
+ "Information": "[INFO]"}
41
+
42
 
43
  class PsyQA(datasets.GeneratorBasedBuilder):
44
  """PsyQA dataset."""
 
47
 
48
  BUILDER_CONFIGS = [
49
  datasets.BuilderConfig(
50
+ name="wo strategy",
51
+ description="",
52
+ version=VERSION,
53
+ ),
54
+ datasets.BuilderConfig(
55
+ name="w strategy",
56
+ description="",
57
  version=VERSION,
58
  )
59
  ]
 
69
  "keywords": datasets.Value("string"),
70
  "answer": datasets.Value("string"),
71
  "has_label": datasets.Value("bool"),
72
+ "reference":datasets.features.Sequence(datasets.Value("string"))
73
+ # "labels_sequence":datasets.features.Sequence(
74
+ # {
75
+ # "start": datasets.Value("int16"),
76
+ # "end": datasets.Value("int16"),
77
+ # "type": datasets.Value("string"),
78
+ # }
79
+ # ),
80
  }
81
  ),
82
  supervised_keys=None,
 
92
  name=datasets.Split.TRAIN,
93
  gen_kwargs={
94
  "filepath": data_dir["train"],
95
+ "strategy": self.config.name == "w strategy"
96
  },
97
  ),
98
  datasets.SplitGenerator(
99
  name=datasets.Split.TEST,
100
  gen_kwargs={
101
  "filepath": data_dir["test"],
102
+ "strategy": self.config.name == "w strategy"
103
  },
104
  ),
105
  datasets.SplitGenerator(
106
  name=datasets.Split.VALIDATION,
107
  gen_kwargs={
108
  "filepath": data_dir["valid"],
109
+ "strategy": self.config.name == "w strategy"
110
  },
111
  ),
112
  ]
113
 
114
+ def _generate_examples(self, filepath, label_filepath=None, strategy=False):
115
  """Yields examples."""
116
+ with open(filepath, encoding="utf-8") as input_file:
117
  dataset = json.load(input_file)
118
  idx = 0
119
  for meta_data in dataset:
120
+ reference = [ans["answer_text"] for ans in meta_data["answers"]]
121
  for ans in meta_data["answers"]:
122
+ if strategy and ans["labels_sequence"] is None:
123
+ continue
124
+ elif strategy and ans["labels_sequence"] is not None:
125
+ pieces = []
126
+ for label in ans["labels_sequence"]:
127
+ pieces.append(_STRATEGY[label["type"]]+ans["answer_text"][label["start"]:label["end"]])
128
+ ans_w_strategy = "".join(pieces)
129
+ yield idx, {"question": meta_data["question"], "description": meta_data["description"], "keywords": meta_data["keywords"], "answer": ans_w_strategy, \
130
+ "questionID": meta_data["questionID"], "has_label": ans["has_label"], "reference": reference}
131
+ else:
132
+ yield idx, {"question": meta_data["question"], "description": meta_data["description"], "keywords": meta_data["keywords"], "answer": ans["answer_text"], \
133
+ "questionID": meta_data["questionID"], "has_label": ans["has_label"], "reference":reference}
134
  idx += 1
135
 
136
 
psyqa_without_strategy.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"name":"w/ strategy", "description":"", "version":"1.1.0"}