|
import json |
|
import datasets |
|
|
|
_DESCRIPTION = "Catalan chatbot conversations from 10 different domains" |
|
_HOMEPAGE = "https://zenodo.org/records/7276036" |
|
_LICENSE = "CC BY 4.0" |
|
_VERSION = "1.0.0" |
|
|
|
_DATAPATH = "KitKat.json" |
|
|
|
_CATEGORIES = [ |
|
"allotjament", |
|
"banca", |
|
"menjar_domicili", |
|
"comerc", |
|
"lloguer_vehicles", |
|
"transports", |
|
"assegurances", |
|
"ajuntament", |
|
"clinica", |
|
"telefonia", |
|
] |
|
|
|
class KitKat(datasets.GeneratorBasedBuilder): |
|
""" KitKat: Conversacional dataset for Catalan. """ |
|
|
|
VERSION = datasets.Version(_VERSION) |
|
|
|
DEFAULT_CONFIG_NAME = "all" |
|
BUILDER_CONFIGS = [datasets.BuilderConfig(name="all", version=VERSION, description="All categories.")] |
|
for _CAT in _CATEGORIES: |
|
BUILDER_CONFIGS.append( |
|
datasets.BuilderConfig(name=_CAT, version=VERSION, description=f"Articles from category \"{_CAT}\"") |
|
) |
|
|
|
@staticmethod |
|
def _info(): |
|
features = datasets.Features( |
|
{ |
|
"id": datasets.Value("string"), |
|
"category": datasets.Value("string"), |
|
"conversation": [ |
|
{ |
|
|
|
"role": datasets.Value("string"), |
|
"text": datasets.Value("string"), |
|
"intent": datasets.Value("string"), |
|
"slots": [ |
|
{ |
|
"tag": datasets.Value("string"), |
|
"text": datasets.Value("string"), |
|
"Start_char": datasets.Value("int32"), |
|
"End_char": datasets.Value("int32"), |
|
} |
|
] |
|
} |
|
] |
|
} |
|
) |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=features, |
|
homepage=_HOMEPAGE, |
|
license=_LICENSE, |
|
) |
|
|
|
@staticmethod |
|
def _split_generators(dl_manager): |
|
data_dir = dl_manager.download_and_extract(_DATAPATH) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"filepath": data_dir, |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, filepath): |
|
with open(filepath, encoding="utf-8") as f: |
|
data = json.load(f) |
|
|
|
_key = 0 |
|
for category,conversations in data["xats"].items(): |
|
if self.config.name in ["all", category]: |
|
for conversation in conversations: |
|
yield _key, { |
|
"id": conversation["id"], |
|
"category": category, |
|
|
|
"conversation": [{"role":x["actor"], "text":x["text"], "slots":x["slots"], "intent":x["intent"]} for x in conversation["frases"]] |
|
} |
|
_key+=1 |