Datasets:
add dataset script
Browse files
README.md
CHANGED
@@ -227,7 +227,27 @@ More stastics are listed here:
|
|
227 |
|
228 |
### Licensing Information
|
229 |
|
230 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
231 |
|
232 |
### Citation Information
|
233 |
|
|
|
227 |
|
228 |
### Licensing Information
|
229 |
|
230 |
+
MIT License
|
231 |
+
|
232 |
+
Copyright (c) 2020 silver
|
233 |
+
|
234 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
235 |
+
of this software and associated documentation files (the "Software"), to deal
|
236 |
+
in the Software without restriction, including without limitation the rights
|
237 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
238 |
+
copies of the Software, and to permit persons to whom the Software is
|
239 |
+
furnished to do so, subject to the following conditions:
|
240 |
+
|
241 |
+
The above copyright notice and this permission notice shall be included in all
|
242 |
+
copies or substantial portions of the Software.
|
243 |
+
|
244 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
245 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
246 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
247 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
248 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
249 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
250 |
+
SOFTWARE.
|
251 |
|
252 |
### Citation Information
|
253 |
|
mmchat.py
CHANGED
@@ -18,8 +18,6 @@ We design various strategies to ensure the quality of the dialogues in MMChat.
|
|
18 |
"""
|
19 |
|
20 |
import json
|
21 |
-
import os
|
22 |
-
|
23 |
import datasets
|
24 |
|
25 |
|
@@ -52,29 +50,38 @@ _HOMEPAGE = "https://github.com/silverriver/MMChat"
|
|
52 |
_LICENSE = "MIT"
|
53 |
|
54 |
_URLS = {
|
55 |
-
"mmchat":
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
"mmchat_raw": [
|
58 |
-
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat_raw/
|
59 |
-
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat_raw/
|
60 |
-
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat_raw/
|
61 |
-
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat_raw/MMChat_split3.tgz",
|
62 |
-
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat_raw/MMChat_split4.tgz",
|
63 |
-
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat_raw/MMChat_split5.tgz",
|
64 |
-
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat_raw/MMChat_split6.tgz",
|
65 |
-
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat_raw/MMChat_split7.tgz",
|
66 |
-
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat_raw/MMChat_split8.tgz",
|
67 |
],
|
68 |
"mmchat_lccc_filtered": [
|
69 |
-
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat_lccc_filtered/
|
70 |
-
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat_lccc_filtered/
|
71 |
-
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat_lccc_filtered/
|
72 |
-
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat_lccc_filtered/MMChat_lccc_flt_split3.tgz",
|
73 |
-
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat_lccc_filtered/MMChat_lccc_flt_split4.tgz",
|
74 |
-
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat_lccc_filtered/MMChat_lccc_flt_split5.tgz",
|
75 |
-
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat_lccc_filtered/MMChat_lccc_flt_split6.tgz",
|
76 |
-
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat_lccc_filtered/MMChat_lccc_flt_split7.tgz",
|
77 |
-
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat_lccc_filtered/MMChat_lccc_flt_split8.tgz",
|
78 |
],
|
79 |
}
|
80 |
|
@@ -138,116 +145,87 @@ class MMChat(datasets.GeneratorBasedBuilder):
|
|
138 |
datasets.SplitGenerator(
|
139 |
name=datasets.Split.TRAIN,
|
140 |
gen_kwargs={
|
141 |
-
"
|
142 |
-
"
|
143 |
-
"
|
144 |
-
"
|
145 |
},
|
146 |
),
|
147 |
datasets.SplitGenerator(
|
148 |
name=datasets.Split.TEST,
|
149 |
gen_kwargs={
|
150 |
-
"
|
151 |
-
"
|
152 |
-
"
|
153 |
-
"
|
154 |
},
|
155 |
),
|
156 |
datasets.SplitGenerator(
|
157 |
name=datasets.Split.VALIDATION,
|
158 |
gen_kwargs={
|
159 |
-
"
|
160 |
-
"
|
161 |
-
"
|
162 |
-
"
|
163 |
-
},
|
164 |
-
),
|
165 |
-
]
|
166 |
-
elif self.config.name == "mmchat_hf":
|
167 |
-
return [
|
168 |
-
datasets.SplitGenerator(
|
169 |
-
name=datasets.Split.TRAIN,
|
170 |
-
gen_kwargs={
|
171 |
-
"dialog_files": [os.path.join(i, "dialog.jsonl") for i in data_dir],
|
172 |
-
"weibo_files": [os.path.join(i, "weibo.jsonl") for i in data_dir],
|
173 |
-
"img_files": [os.path.join(i, "weibo_img_expanded_url.jsonl") for i in data_dir],
|
174 |
-
"label_files": [os.path.join(i, "human_annotation.jsonl") for i in data_dir],
|
175 |
},
|
176 |
),
|
177 |
]
|
178 |
-
|
179 |
-
return [
|
180 |
-
datasets.SplitGenerator(
|
181 |
-
name=datasets.Split.TRAIN,
|
182 |
-
gen_kwargs={
|
183 |
-
"dialog_files": [os.path.join(i, "dialog_lccc_flt.jsonl") for i in data_dir],
|
184 |
-
"weibo_files": [os.path.join(i, "weibo_lccc_flt.jsonl") for i in data_dir],
|
185 |
-
"img_files": [os.path.join(i, "weibo_img_expanded_url_lccc_flt.jsonl") for i in data_dir],
|
186 |
-
"label_files": [],
|
187 |
-
},
|
188 |
-
),
|
189 |
-
]
|
190 |
-
elif self.config.name == "mmchat_raw":
|
191 |
return [
|
192 |
datasets.SplitGenerator(
|
193 |
name=datasets.Split.TRAIN,
|
194 |
gen_kwargs={
|
195 |
-
"
|
196 |
-
"
|
197 |
-
"
|
198 |
-
"
|
199 |
},
|
200 |
),
|
201 |
]
|
202 |
|
203 |
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
204 |
-
def _generate_examples(self,
|
205 |
id = 0
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
) as img_f:
|
216 |
-
while True:
|
217 |
-
try:
|
218 |
-
dialog_line = dialog_f.readline().strip()
|
219 |
-
if len(dialog_line) == 0:
|
220 |
-
break
|
221 |
-
dialog = json.loads(dialog_line) # dialog_f.readline())
|
222 |
-
weibo = json.loads(weibo_f.readline())
|
223 |
-
if self.config.name == "mmchat":
|
224 |
-
imgs = img_f.readline().strip().split(";")
|
225 |
-
else:
|
226 |
-
imgs = json.loads(img_f.readline())["weibo_img"].split(";")
|
227 |
-
|
228 |
-
if self.config.name == "mmchat_hf":
|
229 |
-
label = json.loads(label_f.readline())
|
230 |
-
# Yields examples as (key, example) tuples
|
231 |
-
yield id, {
|
232 |
-
"dialog": dialog,
|
233 |
-
"weibo_content": weibo,
|
234 |
-
"imgs": imgs,
|
235 |
-
"labels": {
|
236 |
-
"image_qualified": True if label["image_quality"] == "1" else False,
|
237 |
-
"dialog_qualified": True if label["dialog_quality"] == "1" else False,
|
238 |
-
"dialog_image_related": True
|
239 |
-
if label["dialog_image_relativeness"] == "1"
|
240 |
-
else False,
|
241 |
-
},
|
242 |
-
}
|
243 |
-
else:
|
244 |
-
yield id, {
|
245 |
-
"dialog": dialog,
|
246 |
-
"weibo_content": weibo,
|
247 |
-
"imgs": imgs,
|
248 |
-
}
|
249 |
-
id += 1
|
250 |
-
except EOFError:
|
251 |
break
|
252 |
-
|
253 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
"""
|
19 |
|
20 |
import json
|
|
|
|
|
21 |
import datasets
|
22 |
|
23 |
|
|
|
50 |
_LICENSE = "MIT"
|
51 |
|
52 |
_URLS = {
|
53 |
+
"mmchat": {
|
54 |
+
"train": [
|
55 |
+
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat/dialog_train.jsonl.gz",
|
56 |
+
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat/img_url_train.jsonl.gz",
|
57 |
+
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat/weibo_train.jsonl.gz",
|
58 |
+
],
|
59 |
+
"dev": [
|
60 |
+
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat/dialog_dev.jsonl.gz",
|
61 |
+
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat/img_url_dev.jsonl.gz",
|
62 |
+
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat/weibo_dev.jsonl.gz",
|
63 |
+
],
|
64 |
+
"test": [
|
65 |
+
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat/dialog_test.jsonl.gz",
|
66 |
+
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat/img_url_test.jsonl.gz",
|
67 |
+
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat/weibo_test.jsonl.gz",
|
68 |
+
]
|
69 |
+
},
|
70 |
+
"mmchat_hf": [
|
71 |
+
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat_hf/dialog.jsonl.gz",
|
72 |
+
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat_hf/weibo_img_expanded_url.jsonl.gz",
|
73 |
+
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat_hf/weibo.jsonl.gz",
|
74 |
+
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat_hf/human_annotation.jsonl.gz",
|
75 |
+
],
|
76 |
"mmchat_raw": [
|
77 |
+
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat_raw/dialog_raw.jsonl.gz",
|
78 |
+
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat_raw/weibo_img_expanded_url_raw.jsonl.gz",
|
79 |
+
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat_raw/weibo_raw.jsonl.gz",
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
],
|
81 |
"mmchat_lccc_filtered": [
|
82 |
+
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat_lccc_filtered/dialog_lccc_flt.jsonl.gz",
|
83 |
+
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat_lccc_filtered/weibo_img_expanded_url_lccc_flt.jsonl.gz",
|
84 |
+
"https://huggingface.co/datasets/silver/mmchat/resolve/main/mmchat_lccc_filtered/weibo_lccc_flt.jsonl.gz",
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
],
|
86 |
}
|
87 |
|
|
|
145 |
datasets.SplitGenerator(
|
146 |
name=datasets.Split.TRAIN,
|
147 |
gen_kwargs={
|
148 |
+
"dialog_file": data_dir["train"][0],
|
149 |
+
"weibo_file": data_dir["train"][2],
|
150 |
+
"img_file": data_dir["train"][1],
|
151 |
+
"label_file": None,
|
152 |
},
|
153 |
),
|
154 |
datasets.SplitGenerator(
|
155 |
name=datasets.Split.TEST,
|
156 |
gen_kwargs={
|
157 |
+
"dialog_file": data_dir["test"][0],
|
158 |
+
"weibo_file": data_dir["test"][2],
|
159 |
+
"img_file": data_dir["test"][1],
|
160 |
+
"label_file": None,
|
161 |
},
|
162 |
),
|
163 |
datasets.SplitGenerator(
|
164 |
name=datasets.Split.VALIDATION,
|
165 |
gen_kwargs={
|
166 |
+
"dialog_file": data_dir["dev"][0],
|
167 |
+
"weibo_file": data_dir["dev"][2],
|
168 |
+
"img_file": data_dir["dev"][1],
|
169 |
+
"label_file": None,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
},
|
171 |
),
|
172 |
]
|
173 |
+
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
return [
|
175 |
datasets.SplitGenerator(
|
176 |
name=datasets.Split.TRAIN,
|
177 |
gen_kwargs={
|
178 |
+
"dialog_file": data_dir[0],
|
179 |
+
"weibo_file": data_dir[2],
|
180 |
+
"img_file": data_dir[1],
|
181 |
+
"label_file": data_dir[3] if len(data_dir) == 4 else None,
|
182 |
},
|
183 |
),
|
184 |
]
|
185 |
|
186 |
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
187 |
+
def _generate_examples(self, dialog_file, weibo_file, img_file, label_file):
|
188 |
id = 0
|
189 |
+
if label_file is not None:
|
190 |
+
label_f = open(label_file, encoding="utf-8")
|
191 |
+
|
192 |
+
with open(dialog_file, encoding="utf-8") as dialog_f, open(weibo_file, encoding="utf-8") as weibo_f, open(
|
193 |
+
img_file, encoding="utf-8") as img_f:
|
194 |
+
while True:
|
195 |
+
try:
|
196 |
+
dialog_line = dialog_f.readline().strip()
|
197 |
+
if len(dialog_line) == 0:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
break
|
199 |
+
dialog = json.loads(dialog_line) # dialog_f.readline())
|
200 |
+
weibo = json.loads(weibo_f.readline())
|
201 |
+
if self.config.name == "mmchat":
|
202 |
+
imgs = img_f.readline().strip().split(";")
|
203 |
+
else:
|
204 |
+
imgs = json.loads(img_f.readline())["weibo_img"].split(";")
|
205 |
+
|
206 |
+
if self.config.name == "mmchat_hf":
|
207 |
+
label = json.loads(label_f.readline())
|
208 |
+
# Yields examples as (key, example) tuples
|
209 |
+
yield id, {
|
210 |
+
"dialog": dialog,
|
211 |
+
"weibo_content": weibo,
|
212 |
+
"imgs": imgs,
|
213 |
+
"labels": {
|
214 |
+
"image_qualified": True if label["image_quality"] == "1" else False,
|
215 |
+
"dialog_qualified": True if label["dialog_quality"] == "1" else False,
|
216 |
+
"dialog_image_related": True
|
217 |
+
if label["dialog_image_relativeness"] == "1"
|
218 |
+
else False,
|
219 |
+
},
|
220 |
+
}
|
221 |
+
else:
|
222 |
+
yield id, {
|
223 |
+
"dialog": dialog,
|
224 |
+
"weibo_content": weibo,
|
225 |
+
"imgs": imgs,
|
226 |
+
}
|
227 |
+
id += 1
|
228 |
+
except EOFError:
|
229 |
+
break
|
230 |
+
if label_file is not None:
|
231 |
+
label_f.close()
|