Create kitkat.py
Browse files
kitkat.py
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import datasets
|
3 |
+
|
4 |
+
_DESCRIPTION = "Catalan chatbot conversations from 10 different domains"
|
5 |
+
_HOMEPAGE = "https://zenodo.org/records/7276036"
|
6 |
+
_LICENSE = "CC BY 4.0"
|
7 |
+
_VERSION = "1.0.0"
|
8 |
+
|
9 |
+
_DATAPATH = "KitKat.json"
|
10 |
+
|
11 |
+
_CATEGORIES = [
|
12 |
+
"allotjament",
|
13 |
+
"banca",
|
14 |
+
"menjar_domicili",
|
15 |
+
"comerc",
|
16 |
+
"lloguer_vehicles",
|
17 |
+
"transports",
|
18 |
+
"assegurances",
|
19 |
+
"ajuntament",
|
20 |
+
"clinica",
|
21 |
+
"telefonia",
|
22 |
+
]
|
23 |
+
|
24 |
+
class KitKat(datasets.GeneratorBasedBuilder):
|
25 |
+
""" KitKat: Conversacional dataset for Catalan. """
|
26 |
+
|
27 |
+
VERSION = datasets.Version(_VERSION)
|
28 |
+
|
29 |
+
DEFAULT_CONFIG_NAME = "all"
|
30 |
+
BUILDER_CONFIGS = [datasets.BuilderConfig(name="all", version=VERSION, description="All categories.")]
|
31 |
+
for _CAT in _CATEGORIES:
|
32 |
+
BUILDER_CONFIGS.append(
|
33 |
+
datasets.BuilderConfig(name=_CAT, version=VERSION, description=f"Articles from category \"{_CAT}\"")
|
34 |
+
)
|
35 |
+
|
36 |
+
@staticmethod
|
37 |
+
def _info():
|
38 |
+
features = datasets.Features(
|
39 |
+
{
|
40 |
+
"id": datasets.Value("string"),
|
41 |
+
"category": datasets.Value("string"),
|
42 |
+
"conversation": [
|
43 |
+
{
|
44 |
+
# "id": datasets.Value("string"),
|
45 |
+
"role": datasets.Value("string"),
|
46 |
+
"text": datasets.Value("string"),
|
47 |
+
"intent": datasets.Value("string"),
|
48 |
+
"slots": [
|
49 |
+
{
|
50 |
+
"tag": datasets.Value("string"),
|
51 |
+
"text": datasets.Value("string"),
|
52 |
+
"Start_char": datasets.Value("int32"),
|
53 |
+
"End_char": datasets.Value("int32"),
|
54 |
+
}
|
55 |
+
]
|
56 |
+
}
|
57 |
+
]
|
58 |
+
}
|
59 |
+
)
|
60 |
+
return datasets.DatasetInfo(
|
61 |
+
description=_DESCRIPTION,
|
62 |
+
features=features,
|
63 |
+
homepage=_HOMEPAGE,
|
64 |
+
license=_LICENSE,
|
65 |
+
)
|
66 |
+
|
67 |
+
@staticmethod
|
68 |
+
def _split_generators(dl_manager):
|
69 |
+
data_dir = dl_manager.download_and_extract(_DATAPATH)
|
70 |
+
return [
|
71 |
+
datasets.SplitGenerator(
|
72 |
+
name=datasets.Split.TRAIN,
|
73 |
+
gen_kwargs={
|
74 |
+
"filepath": data_dir,
|
75 |
+
},
|
76 |
+
),
|
77 |
+
]
|
78 |
+
|
79 |
+
def _generate_examples(self, filepath):
|
80 |
+
with open(filepath, encoding="utf-8") as f:
|
81 |
+
data = json.load(f)
|
82 |
+
|
83 |
+
_key = 0
|
84 |
+
for category,conversations in data["xats"].items():
|
85 |
+
if self.config.name in ["all", category]:
|
86 |
+
for conversation in conversations:
|
87 |
+
yield _key, {
|
88 |
+
"id": conversation["id"], # conversation["número"],
|
89 |
+
"category": category,
|
90 |
+
# "conversation": [{"id": x["id"], "role":x["actor"], "text":x["text"], "slots":x["slots"], "intent":x["intent"]} for x in conversation["frases"]]
|
91 |
+
"conversation": [{"role":x["actor"], "text":x["text"], "slots":x["slots"], "intent":x["intent"]} for x in conversation["frases"]]
|
92 |
+
}
|
93 |
+
_key+=1
|