yamasy1549 commited on
Commit
be73f3d
1 Parent(s): 1f7086f

:page_facing_up: Add a loading script

Browse files
Files changed (1) hide show
  1. real-persona-chat.py +223 -0
real-persona-chat.py ADDED
@@ -0,0 +1,223 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ """
17
+ RealPersonaChat: A Realistic Persona Chat Corpus with Interlocutors' Own Personalities
18
+
19
+ This script is based on
20
+ https://github.com/huggingface/datasets/blob/d69d1c654c4645a0474731794a20d4c012d2d214/templates/new_dataset_script.py
21
+ """
22
+
23
+
24
+ import json
25
+ from pathlib import Path
26
+
27
+ import datasets
28
+
29
+
30
+ _CITATION = """\
31
+ @inproceedings{yamashita-etal-2023-realpersonachat,
32
+ title = "{R}eal{P}ersona{C}hat: A Realistic Persona Chat Corpus with Interlocutors{'} Own Personalities",
33
+ author = "Yamashita, Sanae and
34
+ Inoue, Koji and
35
+ Guo, Ao and
36
+ Mochizuki, Shota and
37
+ Kawahara, Tatsuya and
38
+ Higashinaka, Ryuichiro",
39
+ booktitle = "Proceedings of the 37th Pacific Asia Conference on Language, Information and Computation",
40
+ year = "2023",
41
+ pages = "852--861"
42
+ }
43
+
44
+ @inproceedings{yamashita-etal-2024-realpersonachat-ja,
45
+ title = "{R}eal{P}ersona{C}hat: 話者本人のペルソナと性格特性を含んだ雑談対話コーパス",
46
+ author = "山下 紗苗 and 井上 昂治 and 郭 傲 and 望月 翔太 and 河原 達也 and 東中 竜一郎",
47
+ booktitle = "言語処理学会第30回年次大会発表論文集",
48
+ year = "2024",
49
+ pages = "2738--2743"
50
+ }
51
+ """
52
+
53
+ _DESCRIPTION = """\
54
+ RealPersonaChat: A Realistic Persona Chat Corpus with Interlocutors' Own Personalities
55
+ """
56
+
57
+ _HOMEPAGE = "https://github.com/nu-dialogue/real-persona-chat/"
58
+
59
+ _LICENSE = "CC BY-ND 4.0"
60
+
61
+ _VERSION = "1.0.0"
62
+
63
+ _URL = f"https://github.com/nu-dialogue/real-persona-chat/archive/refs/tags/v{_VERSION}.zip"
64
+
65
+
66
+ class RealPersonaChat(datasets.GeneratorBasedBuilder):
67
+ """RealPersonaChat consists of dialogues and interlocutor information."""
68
+
69
+ VERSION = datasets.Version(_VERSION)
70
+
71
+ BUILDER_CONFIGS = [
72
+ datasets.BuilderConfig(
73
+ name="dialogue",
74
+ version=VERSION,
75
+ description="This part contains dialogues"
76
+ ),
77
+ datasets.BuilderConfig(
78
+ name="interlocutor",
79
+ version=VERSION,
80
+ description="This part contains interlocutor information"
81
+ )
82
+ ]
83
+
84
+ DEFAULT_CONFIG_NAME = "dialogue"
85
+
86
+ def _info(self):
87
+ if self.config.name == "dialogue":
88
+ features = datasets.Features(
89
+ {
90
+ "dialogue_id": datasets.Value("int32"),
91
+ "interlocutors": datasets.Sequence(datasets.Value("string"), length=2),
92
+ "utterances": datasets.Sequence(
93
+ {
94
+ "utterance_id": datasets.Value("int32"),
95
+ "interlocutor_id": datasets.Value("string"),
96
+ "text": datasets.Value("string"),
97
+ "timestamp": datasets.Value("timestamp[us]")
98
+ }
99
+ ),
100
+ "evaluations": datasets.Sequence(
101
+ {
102
+ "interlocutor_id": datasets.Value("string"),
103
+ "informativeness": datasets.Value("int32"),
104
+ "comprehension": datasets.Value("int32"),
105
+ "familiarity": datasets.Value("int32"),
106
+ "interest": datasets.Value("int32"),
107
+ "proactiveness": datasets.Value("int32"),
108
+ "satisfaction": datasets.Value("int32")
109
+ }
110
+ )
111
+ }
112
+ )
113
+
114
+ elif self.config.name == "interlocutor":
115
+ features = datasets.Features(
116
+ {
117
+ "interlocutor_id": datasets.Value("string"),
118
+ "persona": datasets.Sequence(datasets.Value("string"), length=10),
119
+ "personality": {
120
+ "BigFive_Openness": datasets.Value("float32"),
121
+ "BigFive_Conscientiousness": datasets.Value("float32"),
122
+ "BigFive_Extraversion": datasets.Value("float32"),
123
+ "BigFive_Agreeableness": datasets.Value("float32"),
124
+ "BigFive_Neuroticism": datasets.Value("float32"),
125
+ "KiSS18_BasicSkill": datasets.Value("float32"),
126
+ "KiSS18_AdvancedSkill": datasets.Value("float32"),
127
+ "KiSS18_EmotionalManagementSkill": datasets.Value("float32"),
128
+ "KiSS18_OffenceManagementSkill": datasets.Value("float32"),
129
+ "KiSS18_StressManagementSkill": datasets.Value("float32"),
130
+ "KiSS18_PlanningSkill": datasets.Value("float32"),
131
+ "IOS": datasets.Value("int32"),
132
+ "ATQ_Fear": datasets.Value("float32"),
133
+ "ATQ_Frustration": datasets.Value("float32"),
134
+ "ATQ_Sadness": datasets.Value("float32"),
135
+ "ATQ_Discomfort": datasets.Value("float32"),
136
+ "ATQ_ActivationControl": datasets.Value("float32"),
137
+ "ATQ_AttentionalControl": datasets.Value("float32"),
138
+ "ATQ_InhibitoryControl": datasets.Value("float32"),
139
+ "ATQ_Sociability": datasets.Value("float32"),
140
+ "ATQ_HighIntensityPleasure": datasets.Value("float32"),
141
+ "ATQ_PositiveAffect": datasets.Value("float32"),
142
+ "ATQ_NeutralPerceptualSensitivity": datasets.Value("float32"),
143
+ "ATQ_AffectivePerceptualSensitivity": datasets.Value("float32"),
144
+ "ATQ_AssociativeSensitivity": datasets.Value("float32"),
145
+ "SMS_Extraversion": datasets.Value("float32"),
146
+ "SMS_OtherDirectedness": datasets.Value("float32"),
147
+ "SMS_Acting": datasets.Value("float32"),
148
+ },
149
+ "demographic_information": {
150
+ "gender": datasets.ClassLabel(names=["Male", "Female", "Other"]),
151
+ "age": datasets.ClassLabel(names=["-19", "20-29", "30-39", "40-49", "50-59", "60-69"]),
152
+ "education": datasets.ClassLabel(names=["High school graduate", "Two-year college", "Four-year college", "Postgraduate", "Other"]),
153
+ "employment_status": datasets.ClassLabel(names=["Employed", "Homemaker", "Student", "Retired", "Unable to work", "None"]),
154
+ "region_of_residence": datasets.ClassLabel(names=["Hokkaido", "Aomori", "Iwate", "Miyagi", "Akita", "Yamagata", "Fukushima", "Ibaraki", "Tochigi", "Gunma", "Saitama", "Chiba", "Tokyo", "Kanagawa", "Niigata", "Toyama", "Ishikawa", "Fukui", "Yamanashi", "Nagano", "Gifu", "Shizuoka", "Aichi", "Mie", "Shiga", "Kyoto", "Osaka", "Hyogo", "Nara", "Wakayama", "Tottori", "Shimane", "Okayama", "Hiroshima", "Yamaguchi", "Tokushima", "Kagawa", "Ehime", "Kochi", "Fukuoka", "Saga", "Nagasaki", "Kumamoto", "Oita", "Miyazaki", "Kagoshima", "Okinawa"]),
155
+ },
156
+ "text_chat_experience": {
157
+ "age_of_first_chat": datasets.ClassLabel(names=["-9", "10-19", "20-29", "30-39", "40-49", "50-59"]),
158
+ "frequency": datasets.ClassLabel(names=["Every day", "Once every few days", "Once a week", "Less frequent than these"]),
159
+ "chatting_partners": datasets.Sequence(datasets.ClassLabel(names=["Family", "Friend", "Colleague", "Other"])),
160
+ "typical_chat_content": datasets.Value("string"),
161
+ }
162
+ }
163
+ )
164
+
165
+ else:
166
+ raise ValueError(f"Config name `{self.config.name}` is invalid.")
167
+
168
+ return datasets.DatasetInfo(
169
+ description=_DESCRIPTION,
170
+ features=features,
171
+ homepage=_HOMEPAGE,
172
+ license=_LICENSE,
173
+ citation=_CITATION,
174
+ )
175
+
176
+ def _split_generators(self, dl_manager):
177
+ data_dir = dl_manager.download_and_extract(_URL)
178
+
179
+ if self.config.name == "dialogue":
180
+ filepath_list = Path(data_dir, f"real-persona-chat-{_VERSION}", "real_persona_chat", "dialogues").glob("*.json")
181
+ filepath_list = list(sorted(filepath_list, key=lambda x: int(x.stem)))
182
+
183
+ elif self.config.name == "interlocutor":
184
+ filepath_list = Path(data_dir, f"real-persona-chat-{_VERSION}", "real_persona_chat").glob("interlocutors.json")
185
+
186
+ else:
187
+ raise ValueError(f"Config name `{self.config.name}` is invalid.")
188
+
189
+ return [
190
+ datasets.SplitGenerator(
191
+ name=datasets.Split.TRAIN,
192
+ gen_kwargs={
193
+ "filepath_list": filepath_list
194
+ }
195
+ )
196
+ ]
197
+
198
+ def _generate_examples(self, filepath_list):
199
+ if self.config.name == "dialogue":
200
+ for filepath in filepath_list:
201
+ key = filepath.stem
202
+
203
+ with open(filepath, encoding="utf-8") as f:
204
+ example = json.load(f)
205
+
206
+ for utterance_id in range(len(example["utterances"])):
207
+ timestamp = example["utterances"][utterance_id]["timestamp"]
208
+
209
+ if timestamp == "NaT":
210
+ example["utterances"][utterance_id]["timestamp"] = "0001-01-01T00:00:00.000000"
211
+
212
+ yield key, example
213
+
214
+ elif self.config.name == "interlocutor":
215
+ for filepath in filepath_list:
216
+ with open(filepath, encoding="utf-8") as f:
217
+ interlocutors = json.load(f)
218
+
219
+ for key, example in interlocutors.items():
220
+ yield key, example
221
+
222
+ else:
223
+ raise ValueError(f"Config name `{self.config.name}` is invalid.")