yamasy1549 commited on
Commit
8aa16b2
·
1 Parent(s): f5719dc

:page_facing_up: Add a loading script

Browse files
multi-relational-multi-party-chat-corpus.py ADDED
@@ -0,0 +1,231 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ Multi-Relational Multi-Party Chat Corpus (MRMP): Japanese text-based chats comprising first-time-meeting dialogues and family-included dialogues
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
+ import re
26
+ from pathlib import Path
27
+
28
+ import datasets
29
+
30
+
31
+ _CITATION = """\
32
+ @inproceedings{tsuda-etal-2025-multi-relational-multi-party-chat-corpus,
33
+ title = "Constructing a Multi-Party Conversational Corpus Focusing on Interlocutor Relationships",
34
+ author = "Tsuda, Taro and
35
+ Yamashita, Sanae and
36
+ Inoue, Koji and
37
+ Kawahara, Tatsuya
38
+ and Higashinaka, Ryuichiro",
39
+ booktitle="Proceedings of the 29th Workshop on the Semantics and Pragmatics of Dialogue",
40
+ year = "2025",
41
+ pages = "193--202"
42
+ }
43
+
44
+ @inproceedings{tsuda-etal-2025-multi-relational-multi-party-chat-corpus-ja,
45
+ title = "{M}ulti-{R}elational {M}ulti-{P}arty {C}hat {C}orpus: 話者間の関係性に着目したマルチパーティ雑談対話コーパス",
46
+ author = "津田 太郎 and 山下 紗苗 and 井上 昂治 and 河原 達也 and 東中 竜一郎",
47
+ booktitle = "言語処理学会第31回年次大会発表論文集",
48
+ year = "2025",
49
+ pages = "4011--4016"
50
+ }
51
+ """
52
+
53
+ _DESCRIPTION = """\
54
+ Multi-Relational Multi-Party Chat Corpus (MRMP): Japanese text-based chats comprising first-time-meeting dialogues and family-included dialogues
55
+ """
56
+
57
+ _HOMEPAGE = "https://github.com/nu-dialogue/multi-relational-multi-party-chat-corpus/"
58
+
59
+ _LICENSE = "CC BY-ND 4.0"
60
+
61
+ _VERSION = "1.0.0"
62
+
63
+ _URL = f"https://github.com/nu-dialogue/multi-relational-multi-party-chat-corpus/archive/refs/tags/v{_VERSION}.zip"
64
+
65
+
66
+ class MultiRelationalMultiPartyChatCorpus(datasets.GeneratorBasedBuilder):
67
+ """MultiRelationalMultiPartyChatCorpus 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("string"),
91
+ "dialogue_type": datasets.ClassLabel(names=["First time", "Family"]),
92
+ "interlocutors": datasets.Sequence(datasets.Value("string"), length=3),
93
+ "relationship": datasets.Sequence(datasets.Value("string")),
94
+ "utterances": datasets.Sequence(
95
+ {
96
+ "utterance_id": datasets.Value("int32"),
97
+ "interlocutor_id": datasets.Value("string"),
98
+ "text": datasets.Value("string"),
99
+ "mention_to": datasets.Sequence(datasets.Value("string")),
100
+ }
101
+ ),
102
+ "evaluations": datasets.Sequence(
103
+ {
104
+ "interlocutor_id": datasets.Value("string"),
105
+ "informativeness": datasets.Value("int32"),
106
+ "comprehension": datasets.Value("int32"),
107
+ "familiarity": datasets.Value("int32"),
108
+ "interest": datasets.Value("int32"),
109
+ "proactiveness": datasets.Value("int32"),
110
+ "satisfaction": datasets.Value("int32")
111
+ }
112
+ )
113
+ }
114
+ )
115
+
116
+ elif self.config.name == "interlocutor":
117
+ features = datasets.Features(
118
+ {
119
+ "interlocutor_id": datasets.Value("string"),
120
+ "persona": datasets.Sequence(datasets.Value("string"), length=10),
121
+ "personality": {
122
+ "BigFive_Openness": datasets.Value("float32"),
123
+ "BigFive_Conscientiousness": datasets.Value("float32"),
124
+ "BigFive_Extraversion": datasets.Value("float32"),
125
+ "BigFive_Agreeableness": datasets.Value("float32"),
126
+ "BigFive_Neuroticism": datasets.Value("float32"),
127
+ "KiSS18_BasicSkill": datasets.Value("float32"),
128
+ "KiSS18_AdvancedSkill": datasets.Value("float32"),
129
+ "KiSS18_EmotionalManagementSkill": datasets.Value("float32"),
130
+ "KiSS18_OffenceManagementSkill": datasets.Value("float32"),
131
+ "KiSS18_StressManagementSkill": datasets.Value("float32"),
132
+ "KiSS18_PlanningSkill": datasets.Value("float32"),
133
+ "IOS": datasets.Value("int32"),
134
+ "ATQ_Fear": datasets.Value("float32"),
135
+ "ATQ_Frustration": datasets.Value("float32"),
136
+ "ATQ_Sadness": datasets.Value("float32"),
137
+ "ATQ_Discomfort": datasets.Value("float32"),
138
+ "ATQ_ActivationControl": datasets.Value("float32"),
139
+ "ATQ_AttentionalControl": datasets.Value("float32"),
140
+ "ATQ_InhibitoryControl": datasets.Value("float32"),
141
+ "ATQ_Sociability": datasets.Value("float32"),
142
+ "ATQ_HighIntensityPleasure": datasets.Value("float32"),
143
+ "ATQ_PositiveAffect": datasets.Value("float32"),
144
+ "ATQ_NeutralPerceptualSensitivity": datasets.Value("float32"),
145
+ "ATQ_AffectivePerceptualSensitivity": datasets.Value("float32"),
146
+ "ATQ_AssociativeSensitivity": datasets.Value("float32"),
147
+ "SMS_Extraversion": datasets.Value("float32"),
148
+ "SMS_OtherDirectedness": datasets.Value("float32"),
149
+ "SMS_Acting": datasets.Value("float32"),
150
+ },
151
+ "demographic_information": {
152
+ "gender": datasets.ClassLabel(names=["Male", "Female", "Other"]),
153
+ "age": datasets.ClassLabel(names=["-19", "20-29", "30-39", "40-49", "50-59", "60-69"]),
154
+ "education": datasets.ClassLabel(names=["High school graduate", "Two-year college", "Four-year college", "Postgraduate", "Other"]),
155
+ "employment_status": datasets.ClassLabel(names=["Employed", "Homemaker", "Student", "Retired", "Unable to work", "None"]),
156
+ "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"]),
157
+ },
158
+ "text_chat_experience": {
159
+ "age_of_first_chat": datasets.ClassLabel(names=["-9", "10-19", "20-29", "30-39", "40-49", "50-59"]),
160
+ "frequency": datasets.ClassLabel(names=["Every day", "Once every few days", "Once a week", "Less frequent than these"]),
161
+ "chatting_partners": datasets.Sequence(datasets.ClassLabel(names=["Family", "Friend", "Colleague", "Other"])),
162
+ "typical_chat_content": datasets.Value("string"),
163
+ },
164
+ "pair_information": {
165
+ "pair_flag": datasets.Value("bool"),
166
+ "relationship": datasets.Sequence(datasets.ClassLabel(names=["Frequent acquaintance", "Someone known for years", "Someone engaged in joint activities"])),
167
+ "relationship_detail": datasets.Value("string"),
168
+ "pair_interlocutor_id": datasets.Value("string"),
169
+ }
170
+ }
171
+ )
172
+
173
+ else:
174
+ raise ValueError(f"Config name `{self.config.name}` is invalid.")
175
+
176
+ return datasets.DatasetInfo(
177
+ description=_DESCRIPTION,
178
+ features=features,
179
+ homepage=_HOMEPAGE,
180
+ license=_LICENSE,
181
+ citation=_CITATION,
182
+ )
183
+
184
+ def _split_generators(self, dl_manager):
185
+ data_dir = dl_manager.download_and_extract(_URL)
186
+
187
+ if self.config.name == "dialogue":
188
+ filepath_list = Path(data_dir, f"multi-relational-multi-party-chat-corpus-{_VERSION}", "multi_relational_multi_party_chat_corpus", "dialogues").glob("**/*.json")
189
+ filepath_list = list(sorted(filepath_list, key=lambda x: self._natural_keys(x.stem)))
190
+
191
+ elif self.config.name == "interlocutor":
192
+ filepath_list = Path(data_dir, f"multi-relational-multi-party-chat-corpus-{_VERSION}", "multi_relational_multi_party_chat_corpus").glob("interlocutors.json")
193
+
194
+ else:
195
+ raise ValueError(f"Config name `{self.config.name}` is invalid.")
196
+
197
+ return [
198
+ datasets.SplitGenerator(
199
+ name=datasets.Split.TRAIN,
200
+ gen_kwargs={
201
+ "filepath_list": filepath_list
202
+ }
203
+ )
204
+ ]
205
+
206
+ def _generate_examples(self, filepath_list):
207
+ if self.config.name == "dialogue":
208
+ for filepath in filepath_list:
209
+ key = filepath.stem
210
+
211
+ with open(filepath, encoding="utf-8") as f:
212
+ example = json.load(f)
213
+
214
+ yield key, example
215
+
216
+ elif self.config.name == "interlocutor":
217
+ for filepath in filepath_list:
218
+ with open(filepath, encoding="utf-8") as f:
219
+ interlocutors = json.load(f)
220
+
221
+ for key, example in interlocutors.items():
222
+ yield key, example
223
+
224
+ else:
225
+ raise ValueError(f"Config name `{self.config.name}` is invalid.")
226
+
227
+ def _atoi(self, text):
228
+ return int(text) if text.isdigit() else text
229
+
230
+ def _natural_keys(self, text):
231
+ return [self._atoi(c) for c in re.split(r'(\d+)', text)]