Datasets:
File size: 2,772 Bytes
5bb7e76 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
"""NLUCat dataset."""
import json
import datasets
_HOMEPAGE = ""
_CITATION = """\
"""
_DESCRIPTION = """\
NLUCat - Natural Language Understanding in Catalan
"""
_TRAIN_FILE = "train.json"
_DEV_FILE = "dev.json"
_TEST_FILE = "test.json"
class Nlucat(datasets.GeneratorBasedBuilder):
VERSION = datasets.Version("1.0.0")
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"example": datasets.Value("string"),
"intent": datasets.Value("string"),
"slot_text": datasets.Sequence(datasets.Value("string")),
"slot_tag": datasets.Sequence(datasets.Value("string")),
"start_char": datasets.Sequence(datasets.Value("string")),
"end_char": datasets.Sequence(datasets.Value("string"))
}
),
homepage=_HOMEPAGE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
urls_to_download = {
"train": f"{_TRAIN_FILE}",
"dev": f"{_DEV_FILE}",
"test": f"{_TEST_FILE}",
}
downloaded_files = dl_manager.download_and_extract(urls_to_download)
return [
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"], "split": "train"}),
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"], "split": "validation"}),
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"], "split": "test"}),
]
def _generate_examples(self, filepath, split):
"""Yields examples."""
with open(filepath, encoding="utf-8") as f:
dataset = json.load(f)
for row in dataset["data"]:
example = row["example"]
intent = row["annotation"]["intent"]
slot_text = [slot["Text"] for slot in row["annotation"]["slots"]]
slot_tag = [slot["Tag"] for slot in row["annotation"]["slots"]]
start_char = [answer["Start_char"] for answer in row["annotation"]["slots"]]
end_char = [answer["End_char"] for answer in row["annotation"]["slots"]]
yield row["id"], {
"example": example,
"intent": intent,
"slot_text": slot_text,
"slot_tag": slot_tag,
"start_char": start_char,
"end_char": end_char
}
|