Datasets:
ReDIAL dataset with multiple configuration.
Browse files- .gitattributes +5 -0
- data/train-00000-of-00001-e743925b24aaa562.parquet → movies_merged.csv +2 -2
- data/test-00000-of-00001-f21aec36c6804b6f.parquet → movies_with_mentions.csv +2 -2
- redial.py +195 -0
- data/validation-00000-of-00001-8390a3aedba185de.parquet → test_data +2 -2
- train_data +3 -0
- valid_data +3 -0
.gitattributes
CHANGED
@@ -52,3 +52,8 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
52 |
*.jpg filter=lfs diff=lfs merge=lfs -text
|
53 |
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
54 |
*.webp filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
52 |
*.jpg filter=lfs diff=lfs merge=lfs -text
|
53 |
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
54 |
*.webp filter=lfs diff=lfs merge=lfs -text
|
55 |
+
movies_merged.csv filter=lfs diff=lfs merge=lfs -text
|
56 |
+
movies_with_mentions.csv filter=lfs diff=lfs merge=lfs -text
|
57 |
+
valid_data filter=lfs diff=lfs merge=lfs -text
|
58 |
+
test_data filter=lfs diff=lfs merge=lfs -text
|
59 |
+
train_data filter=lfs diff=lfs merge=lfs -text
|
data/train-00000-of-00001-e743925b24aaa562.parquet → movies_merged.csv
RENAMED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:af2aa1ce27b1aba74758e0da9e645650e4df8d24bf72b5460ea9d4d064f0b629
|
3 |
+
size 2613693
|
data/test-00000-of-00001-f21aec36c6804b6f.parquet → movies_with_mentions.csv
RENAMED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0d408daa474ac95b959a739a261dddd997dd800f5ea585da15a434a26187dbb0
|
3 |
+
size 226703
|
redial.py
ADDED
@@ -0,0 +1,195 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import re
|
3 |
+
from typing import List
|
4 |
+
|
5 |
+
import datasets
|
6 |
+
|
7 |
+
logger = datasets.logging.get_logger(__name__)
|
8 |
+
|
9 |
+
class RedialConfig(datasets.BuilderConfig):
|
10 |
+
"""BuilderConfig for ReDIAL."""
|
11 |
+
|
12 |
+
def __init__(self, features, **kwargs):
|
13 |
+
"""BuilderConfig for ReDIAL.
|
14 |
+
|
15 |
+
Args:
|
16 |
+
features: *list[string]*, list of the features that will appear in the
|
17 |
+
feature dict. Should not include "label".
|
18 |
+
**kwargs: keyword arguments forwarded to super.
|
19 |
+
"""
|
20 |
+
super().__init__(version=datasets.Version("0.0.1"), **kwargs)
|
21 |
+
self.features = features
|
22 |
+
|
23 |
+
_URL = "./"
|
24 |
+
_URLS = {
|
25 |
+
"train": _URL + "train_data",
|
26 |
+
"valid": _URL + "valid_data",
|
27 |
+
"test": _URL + "test_data",
|
28 |
+
}
|
29 |
+
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
class ReDIAL(datasets.GeneratorBasedBuilder):
|
34 |
+
DEFAULT_CONFIG_NAME = "rec"
|
35 |
+
BUILDER_CONFIGS = [
|
36 |
+
RedialConfig(
|
37 |
+
name="SA",
|
38 |
+
description="For using the ReDIAL dataset to train sentiment analysis on movies in sentences",
|
39 |
+
features={
|
40 |
+
"id": datasets.Value("int32"),
|
41 |
+
"movieName": datasets.Value("string"),
|
42 |
+
"messages": datasets.features.Sequence(datasets.Value("string")),
|
43 |
+
"senders": datasets.features.Sequence(datasets.Value("int32")),
|
44 |
+
"form": datasets.features.Sequence(
|
45 |
+
datasets.Value("int32"), length=6
|
46 |
+
)
|
47 |
+
},
|
48 |
+
# certain information(e.g. movie_occurrences) is model-specific, and we leave it for Dataset.map
|
49 |
+
),
|
50 |
+
RedialConfig(
|
51 |
+
name="SA_debug",
|
52 |
+
description="For using the ReDIAL dataset to train sentiment analysis on movies in sentences",
|
53 |
+
features={
|
54 |
+
"id": datasets.Value("int32"),
|
55 |
+
"movieName": datasets.Value("string"),
|
56 |
+
"messages": datasets.features.Sequence(datasets.Value("string")),
|
57 |
+
"senders": datasets.features.Sequence(datasets.Value("int32")),
|
58 |
+
"form": datasets.features.Sequence(
|
59 |
+
datasets.Value("int32"), length=6
|
60 |
+
)
|
61 |
+
},
|
62 |
+
),
|
63 |
+
RedialConfig(
|
64 |
+
name="autorec",
|
65 |
+
description="For training autorec model on ReDIAL data",
|
66 |
+
features=datasets.Features({
|
67 |
+
"movieIds": datasets.Sequence(datasets.Value("int32")),
|
68 |
+
"ratings": datasets.Sequence(datasets.Value("float"))
|
69 |
+
}),
|
70 |
+
),
|
71 |
+
RedialConfig(
|
72 |
+
name="rec",
|
73 |
+
description="For using the ReDIAL dataset to train recommender",
|
74 |
+
features={
|
75 |
+
"movieIds": datasets.Sequence(datasets.Value("int32")),
|
76 |
+
"messages": datasets.features.Sequence(datasets.Value("string")),
|
77 |
+
"senders": datasets.features.Sequence(datasets.Value("int32")),
|
78 |
+
},
|
79 |
+
),
|
80 |
+
|
81 |
+
]
|
82 |
+
|
83 |
+
def __init__(self, **kwargs):
|
84 |
+
super().__init__(**kwargs)
|
85 |
+
self.last_sender = None
|
86 |
+
|
87 |
+
|
88 |
+
def _processMessage(self, msg, initialId):
|
89 |
+
"""
|
90 |
+
msg example: {
|
91 |
+
"timeOffset": 0,
|
92 |
+
"text": "Hi I am looking for a movie like @111776",
|
93 |
+
"senderWorkerId": 956,
|
94 |
+
"messageId": 204171
|
95 |
+
},
|
96 |
+
"""
|
97 |
+
res = {
|
98 |
+
"text": msg["text"],
|
99 |
+
"sender": 1 if msg["senderWorkerId"] == initialId else -1
|
100 |
+
}
|
101 |
+
return res
|
102 |
+
|
103 |
+
def _flattenMessages(self, conversation):
|
104 |
+
messages = []
|
105 |
+
senders = []
|
106 |
+
for message in conversation["messages"]:
|
107 |
+
role = 1 if message["senderWorkerId"] == conversation["initiatorWorkerId"] else -1
|
108 |
+
text = message["text"]
|
109 |
+
if len(senders) > 0 and senders[-1] == role:
|
110 |
+
messages[-1] += "\n" + text
|
111 |
+
else:
|
112 |
+
senders.append(role)
|
113 |
+
messages.append(text)
|
114 |
+
return messages, senders
|
115 |
+
|
116 |
+
def _info(self):
|
117 |
+
return datasets.DatasetInfo(
|
118 |
+
description= self.config.description,
|
119 |
+
features=datasets.Features(self.config.features),
|
120 |
+
)
|
121 |
+
|
122 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
123 |
+
urls_to_download = _URLS
|
124 |
+
downloaded_files = dl_manager.download_and_extract(urls_to_download)
|
125 |
+
return [
|
126 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
|
127 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["valid"]}),
|
128 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
|
129 |
+
]
|
130 |
+
|
131 |
+
def _generate_examples(self, filepath):
|
132 |
+
"""This function returns the examples in the raw (text) form."""
|
133 |
+
logger.info("generating examples from = %s", filepath)
|
134 |
+
|
135 |
+
if self.config.name == "autorec":
|
136 |
+
with open(filepath, encoding="utf-8") as f:
|
137 |
+
idx = 0
|
138 |
+
for line in f:
|
139 |
+
conversation = json.loads(line)
|
140 |
+
movieIds = []
|
141 |
+
ratings = []
|
142 |
+
if len(conversation["initiatorQuestions"]) == 0:
|
143 |
+
continue
|
144 |
+
for id, form in conversation["initiatorQuestions"].items():
|
145 |
+
rating = int(form["liked"])
|
146 |
+
if rating < 2:
|
147 |
+
movieIds.append(id)
|
148 |
+
ratings.append(rating)
|
149 |
+
if len(movieIds) > 0:
|
150 |
+
yield idx, {
|
151 |
+
"movieIds": movieIds,
|
152 |
+
"ratings": ratings
|
153 |
+
}
|
154 |
+
idx += 1
|
155 |
+
|
156 |
+
elif "SA" in self.config.name:
|
157 |
+
Idx = 0
|
158 |
+
date_pattern = re.compile(r'\(\d{4}\)') # To match e.g. "(2009)"
|
159 |
+
with open(filepath, encoding="utf-8") as f:
|
160 |
+
for line in f:
|
161 |
+
conversation = json.loads(line)
|
162 |
+
init_q = conversation["initiatorQuestions"]
|
163 |
+
resp_q = conversation["respondentQuestions"]
|
164 |
+
msgs, senders = self._flattenMessages(conversation)
|
165 |
+
# get movies that are in both forms.
|
166 |
+
gen = [key for key in init_q if key in resp_q]
|
167 |
+
for id in gen:
|
168 |
+
# remove date from movie name
|
169 |
+
movieName = date_pattern.sub('', conversation["movieMentions"][id]).strip(" ")
|
170 |
+
if len(movieName) == 0:
|
171 |
+
continue
|
172 |
+
yield Idx, {
|
173 |
+
"id": int(id),
|
174 |
+
"movieName": movieName,
|
175 |
+
"messages": msgs,
|
176 |
+
"senders": senders,
|
177 |
+
"form": [init_q[id]["suggested"], init_q[id]["seen"], init_q[id]["liked"],
|
178 |
+
resp_q[id]["suggested"], resp_q[id]["seen"], resp_q[id]["liked"],]
|
179 |
+
}
|
180 |
+
Idx += 1
|
181 |
+
if Idx > 100 and "debug" in self.config.name:
|
182 |
+
break
|
183 |
+
elif "rec" in self.config.name:
|
184 |
+
Idx = 0
|
185 |
+
with open(filepath, encoding="utf-8") as f:
|
186 |
+
for line in f:
|
187 |
+
conversation = json.loads(line)
|
188 |
+
msgs, senders = self._flattenMessages(conversation)
|
189 |
+
|
190 |
+
yield Idx, {
|
191 |
+
"messages": msgs,
|
192 |
+
"senders": senders,
|
193 |
+
"movieIds": [int(movieId) for movieId in conversation["movieMentions"]]
|
194 |
+
}
|
195 |
+
Idx += 1
|
data/validation-00000-of-00001-8390a3aedba185de.parquet → test_data
RENAMED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:cb720e51ace7b7b1c72e2ebb88645a48c8203cacd073c56900fc2e3b9bfffdcc
|
3 |
+
size 3790112
|
train_data
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:43333bf53b064e32a96f156411f07059c7d8dd32f19e70ed3349acd82560242a
|
3 |
+
size 23014814
|
valid_data
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7adfb9e9cc33440267c3a54ac934ed720dc67c871c39f1f548015f2522cf7741
|
3 |
+
size 5747829
|