Create gg.py
Browse files
gg.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import datasets
|
2 |
+
|
3 |
+
text_file = 'dateee.txt'
|
4 |
+
|
5 |
+
class DailyDialog(datasets.GeneratorBasedBuilder):
|
6 |
+
"""DailyDialog: A Manually Labelled Multi-turn Dialogue Dataset"""
|
7 |
+
|
8 |
+
VERSION = datasets.Version("1.0.0")
|
9 |
+
|
10 |
+
__EOU__ = "__eou__"
|
11 |
+
|
12 |
+
|
13 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager):
|
14 |
+
# You should implement the logic here to split the text_file into TRAIN, VALIDATION, and TEST
|
15 |
+
# Example logic is provided below
|
16 |
+
with open(text_file, 'r', encoding='utf-8') as f:
|
17 |
+
lines = f.readlines()
|
18 |
+
|
19 |
+
train_size = int(0.8 * len(lines))
|
20 |
+
val_size = int(0.1 * len(lines))
|
21 |
+
test_size = len(lines) - train_size - val_size
|
22 |
+
|
23 |
+
train_data = lines[:train_size]
|
24 |
+
val_data = lines[train_size:train_size + val_size]
|
25 |
+
test_data = lines[train_size + val_size:]
|
26 |
+
|
27 |
+
return [
|
28 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"data": train_data}),
|
29 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"data": val_data}),
|
30 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"data": test_data}),
|
31 |
+
]
|
32 |
+
|
33 |
+
def _generate_examples(self, data):
|
34 |
+
for idx, line in enumerate(data):
|
35 |
+
yield idx, {
|
36 |
+
"dialog": line.strip().split(self.__EOU__)[:-1]
|
37 |
+
}
|