Datasets:
Tasks:
Text Classification
Sub-tasks:
multi-label-classification
Languages:
English
Size:
10K<n<100K
License:
Commit
•
8e60184
1
Parent(s):
4107b38
Support streaming daily_dialog dataset (#4008)
Browse filesCommit from https://github.com/huggingface/datasets/commit/0153001de162f6bc7d0288e033e40a845b5a784e
- daily_dialog.py +30 -58
daily_dialog.py
CHANGED
@@ -82,69 +82,41 @@ class DailyDialog(datasets.GeneratorBasedBuilder):
|
|
82 |
)
|
83 |
|
84 |
def _split_generators(self, dl_manager: datasets.DownloadManager):
|
85 |
-
"""Returns SplitGenerators."""
|
86 |
-
# dl_manager is a datasets.download.DownloadManager that can be used to
|
87 |
-
# download and extract URLs
|
88 |
dl_dir = dl_manager.download_and_extract(_URL)
|
89 |
data_dir = os.path.join(dl_dir, "ijcnlp_dailydialog")
|
90 |
-
|
91 |
-
# The splits are nested inside the zip
|
92 |
-
for name in ("train", "validation", "test"):
|
93 |
-
zip_fpath = os.path.join(data_dir, f"{name}.zip")
|
94 |
-
with ZipFile(zip_fpath) as zip_file:
|
95 |
-
zip_file.extractall(path=data_dir)
|
96 |
-
zip_file.close()
|
97 |
-
|
98 |
return [
|
99 |
datasets.SplitGenerator(
|
100 |
-
name=
|
101 |
-
# These kwargs will be passed to _generate_examples
|
102 |
-
gen_kwargs={
|
103 |
-
"file_path": os.path.join(data_dir, "train", "dialogues_train.txt"),
|
104 |
-
"act_path": os.path.join(data_dir, "train", "dialogues_act_train.txt"),
|
105 |
-
"emotion_path": os.path.join(data_dir, "train", "dialogues_emotion_train.txt"),
|
106 |
-
"split": "train",
|
107 |
-
},
|
108 |
-
),
|
109 |
-
datasets.SplitGenerator(
|
110 |
-
name=datasets.Split.TEST,
|
111 |
-
# These kwargs will be passed to _generate_examples
|
112 |
gen_kwargs={
|
113 |
-
"
|
114 |
-
"
|
115 |
-
"
|
116 |
-
"
|
117 |
},
|
118 |
-
)
|
119 |
-
|
120 |
-
name=datasets.Split.VALIDATION,
|
121 |
-
# These kwargs will be passed to _generate_examples
|
122 |
-
gen_kwargs={
|
123 |
-
"file_path": os.path.join(data_dir, "validation", "dialogues_validation.txt"),
|
124 |
-
"act_path": os.path.join(data_dir, "validation", "dialogues_act_validation.txt"),
|
125 |
-
"emotion_path": os.path.join(data_dir, "validation", "dialogues_emotion_validation.txt"),
|
126 |
-
"split": "dev",
|
127 |
-
},
|
128 |
-
),
|
129 |
]
|
130 |
|
131 |
-
def _generate_examples(self,
|
132 |
-
""
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
|
|
|
|
|
82 |
)
|
83 |
|
84 |
def _split_generators(self, dl_manager: datasets.DownloadManager):
|
|
|
|
|
|
|
85 |
dl_dir = dl_manager.download_and_extract(_URL)
|
86 |
data_dir = os.path.join(dl_dir, "ijcnlp_dailydialog")
|
87 |
+
splits = [datasets.Split.TRAIN, datasets.Split.VALIDATION, datasets.Split.TEST]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
return [
|
89 |
datasets.SplitGenerator(
|
90 |
+
name=split,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
gen_kwargs={
|
92 |
+
"data_zip": os.path.join(data_dir, f"{split}.zip"),
|
93 |
+
"dialog_path": f"{split}/dialogues_{split}.txt",
|
94 |
+
"act_path": f"{split}/dialogues_act_{split}.txt",
|
95 |
+
"emotion_path": f"{split}/dialogues_emotion_{split}.txt",
|
96 |
},
|
97 |
+
)
|
98 |
+
for split in splits
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
]
|
100 |
|
101 |
+
def _generate_examples(self, data_zip, dialog_path, act_path, emotion_path):
|
102 |
+
with open(data_zip, "rb") as data_file:
|
103 |
+
with ZipFile(data_file) as zip_file:
|
104 |
+
with zip_file.open(dialog_path) as dialog_file, zip_file.open(act_path) as act_file, zip_file.open(
|
105 |
+
emotion_path
|
106 |
+
) as emotion_file:
|
107 |
+
for idx, (dialog_line, act_line, emotion_line) in enumerate(
|
108 |
+
zip(dialog_file, act_file, emotion_file)
|
109 |
+
):
|
110 |
+
if not dialog_line.strip():
|
111 |
+
break
|
112 |
+
dialog = dialog_line.decode().split(self.__EOU__)[:-1]
|
113 |
+
act = act_line.decode().split(" ")[:-1]
|
114 |
+
emotion = emotion_line.decode().split(" ")[:-1]
|
115 |
+
assert (
|
116 |
+
len(dialog) == len(act) == len(emotion)
|
117 |
+
), "Different turns btw dialogue & emotion & action"
|
118 |
+
yield idx, {
|
119 |
+
"dialog": dialog,
|
120 |
+
"act": [act_label[x] for x in act],
|
121 |
+
"emotion": [emotion_label[x] for x in emotion],
|
122 |
+
}
|