Datasets:
Commit
•
3756a1e
1
Parent(s):
186d185
Delete loading script
Browse files- re_dial.py +0 -160
re_dial.py
DELETED
@@ -1,160 +0,0 @@
|
|
1 |
-
# coding=utf-8
|
2 |
-
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
3 |
-
#
|
4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
-
# you may not use this file except in compliance with the License.
|
6 |
-
# You may obtain a copy of the License at
|
7 |
-
#
|
8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9 |
-
#
|
10 |
-
# Unless required by applicable law or agreed to in writing, software
|
11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
-
# See the License for the specific language governing permissions and
|
14 |
-
# limitations under the License.
|
15 |
-
"""Annotated dataset of dialogues where users recommend movies to each other."""
|
16 |
-
|
17 |
-
|
18 |
-
import json
|
19 |
-
import os
|
20 |
-
|
21 |
-
import datasets
|
22 |
-
|
23 |
-
|
24 |
-
_CITATION = """\
|
25 |
-
@inproceedings{li2018conversational,
|
26 |
-
title={Towards Deep Conversational Recommendations},
|
27 |
-
author={Li, Raymond and Kahou, Samira Ebrahimi and Schulz, Hannes and Michalski, Vincent and Charlin, Laurent and Pal, Chris},
|
28 |
-
booktitle={Advances in Neural Information Processing Systems 31 (NIPS 2018)},
|
29 |
-
year={2018}
|
30 |
-
}
|
31 |
-
"""
|
32 |
-
|
33 |
-
_DESCRIPTION = """\
|
34 |
-
ReDial (Recommendation Dialogues) is an annotated dataset of dialogues, where users
|
35 |
-
recommend movies to each other. The dataset was collected by a team of researchers working at
|
36 |
-
Polytechnique Montréal, MILA – Quebec AI Institute, Microsoft Research Montréal, HEC Montreal, and Element AI.
|
37 |
-
|
38 |
-
The dataset allows research at the intersection of goal-directed dialogue systems
|
39 |
-
(such as restaurant recommendation) and free-form (also called “chit-chat”) dialogue systems.
|
40 |
-
"""
|
41 |
-
|
42 |
-
_HOMEPAGE = "https://redialdata.github.io/website/"
|
43 |
-
|
44 |
-
_LICENSE = "CC BY 4.0 License."
|
45 |
-
|
46 |
-
_DATA_URL = "https://github.com/ReDialData/website/raw/data/redial_dataset.zip"
|
47 |
-
|
48 |
-
|
49 |
-
class ReDial(datasets.GeneratorBasedBuilder):
|
50 |
-
"""Annotated dataset of dialogues where users recommend movies to each other."""
|
51 |
-
|
52 |
-
VERSION = datasets.Version("1.1.0")
|
53 |
-
|
54 |
-
def _info(self):
|
55 |
-
question_features = {
|
56 |
-
"movieId": datasets.Value("string"),
|
57 |
-
"suggested": datasets.Value("int32"),
|
58 |
-
"seen": datasets.Value("int32"),
|
59 |
-
"liked": datasets.Value("int32"),
|
60 |
-
}
|
61 |
-
features = datasets.Features(
|
62 |
-
{
|
63 |
-
"movieMentions": [
|
64 |
-
{
|
65 |
-
"movieId": datasets.Value("string"),
|
66 |
-
"movieName": datasets.Value("string"),
|
67 |
-
},
|
68 |
-
],
|
69 |
-
"respondentQuestions": [question_features],
|
70 |
-
"messages": [
|
71 |
-
{
|
72 |
-
"timeOffset": datasets.Value("int32"),
|
73 |
-
"text": datasets.Value("string"),
|
74 |
-
"senderWorkerId": datasets.Value("int32"),
|
75 |
-
"messageId": datasets.Value("int32"),
|
76 |
-
},
|
77 |
-
],
|
78 |
-
"conversationId": datasets.Value("int32"),
|
79 |
-
"respondentWorkerId": datasets.Value("int32"),
|
80 |
-
"initiatorWorkerId": datasets.Value("int32"),
|
81 |
-
"initiatorQuestions": [question_features],
|
82 |
-
}
|
83 |
-
)
|
84 |
-
return datasets.DatasetInfo(
|
85 |
-
# This is the description that will appear on the datasets page.
|
86 |
-
description=_DESCRIPTION,
|
87 |
-
# This defines the different columns of the dataset and their types
|
88 |
-
features=features, # Here we define them above because they are different between the two configurations
|
89 |
-
# If there's a common (input, target) tuple from the features,
|
90 |
-
# specify them here. They'll be used if as_supervised=True in
|
91 |
-
# builder.as_dataset.
|
92 |
-
supervised_keys=None,
|
93 |
-
# Homepage of the dataset for documentation
|
94 |
-
homepage=_HOMEPAGE,
|
95 |
-
# License for the dataset if available
|
96 |
-
license=_LICENSE,
|
97 |
-
# Citation for the dataset
|
98 |
-
citation=_CITATION,
|
99 |
-
)
|
100 |
-
|
101 |
-
def _split_generators(self, dl_manager):
|
102 |
-
"""Returns SplitGenerators."""
|
103 |
-
data_dir = dl_manager.download_and_extract(_DATA_URL)
|
104 |
-
|
105 |
-
return [
|
106 |
-
datasets.SplitGenerator(
|
107 |
-
name=datasets.Split.TRAIN,
|
108 |
-
# These kwargs will be passed to _generate_examples
|
109 |
-
gen_kwargs={
|
110 |
-
"filepath": os.path.join(data_dir, "train_data.jsonl"),
|
111 |
-
"split": "train",
|
112 |
-
},
|
113 |
-
),
|
114 |
-
datasets.SplitGenerator(
|
115 |
-
name=datasets.Split.TEST,
|
116 |
-
# These kwargs will be passed to _generate_examples
|
117 |
-
gen_kwargs={"filepath": os.path.join(data_dir, "test_data.jsonl"), "split": "test"},
|
118 |
-
),
|
119 |
-
]
|
120 |
-
|
121 |
-
def _generate_examples(self, filepath, split):
|
122 |
-
"""Yields examples."""
|
123 |
-
|
124 |
-
with open(filepath, encoding="utf-8") as f:
|
125 |
-
examples = f.readlines()
|
126 |
-
for id_, row in enumerate(examples):
|
127 |
-
data = json.loads(row.strip())
|
128 |
-
d = {}
|
129 |
-
movieMentions_list = []
|
130 |
-
for i in data["movieMentions"]:
|
131 |
-
d["movieId"] = i
|
132 |
-
d["movieName"] = data["movieMentions"][i]
|
133 |
-
movieMentions_list.append(d)
|
134 |
-
d = {}
|
135 |
-
|
136 |
-
respondentQuestions_list = []
|
137 |
-
for i in data["respondentQuestions"]:
|
138 |
-
d["movieId"] = i
|
139 |
-
alpha = data["respondentQuestions"][i]
|
140 |
-
z = {**d, **alpha} # merging 2 dictionaries
|
141 |
-
respondentQuestions_list.append(z)
|
142 |
-
d = {}
|
143 |
-
|
144 |
-
initiatorQuestions_list = []
|
145 |
-
for i in data["initiatorQuestions"]:
|
146 |
-
d["movieId"] = i
|
147 |
-
alpha = data["initiatorQuestions"][i]
|
148 |
-
z = {**d, **alpha} # merging 2 dictionaries
|
149 |
-
initiatorQuestions_list.append(z)
|
150 |
-
d = {}
|
151 |
-
|
152 |
-
yield id_, {
|
153 |
-
"movieMentions": movieMentions_list,
|
154 |
-
"respondentQuestions": respondentQuestions_list,
|
155 |
-
"messages": data["messages"],
|
156 |
-
"conversationId": data["conversationId"],
|
157 |
-
"respondentWorkerId": data["respondentWorkerId"],
|
158 |
-
"initiatorWorkerId": data["initiatorWorkerId"],
|
159 |
-
"initiatorQuestions": initiatorQuestions_list,
|
160 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|