|
|
|
|
|
"""TODO(empathetic_dialogues): Add a description here.""" |
|
|
|
|
|
import csv |
|
import json |
|
|
|
import datasets |
|
from datasets.tasks import QuestionAnsweringExtractive |
|
|
|
|
|
|
|
logger = datasets.logging.get_logger(__name__) |
|
|
|
_DESCRIPTION = """\ |
|
persian-conversational-dataset |
|
""" |
|
|
|
_URL = "https://huggingface.co/datasets/Kamtera/Persian-conversational-dataset/blob/main/" |
|
_URLS = [ |
|
"dadrah_dataset.json", |
|
"dadrah_dataset1-1000_10000.json", |
|
"dadrah_dataset1-10000_100000.json", |
|
"dadrah_dataset1-100000_276342.json", |
|
] |
|
|
|
class persianConversation(datasets.GeneratorBasedBuilder): |
|
|
|
|
|
|
|
def _info(self): |
|
|
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=datasets.Features( |
|
{ |
|
"title": datasets.Value("string"), |
|
"question": datasets.Value("string"), |
|
"answers": datasets.Sequence(datasets.Value("string")), |
|
"keywords": datasets.Sequence(datasets.Value("string")), |
|
|
|
} |
|
), |
|
|
|
|
|
|
|
supervised_keys=None, |
|
|
|
|
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
"""Returns SplitGenerators.""" |
|
|
|
|
|
|
|
downloaded_files = dl_manager.download(_URLS) |
|
logger.info("| > downloaded files") |
|
logger.info(downloaded_files) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={ |
|
"files": downloaded_files[1:], |
|
"split_file": "train", |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
|
|
gen_kwargs={ |
|
"files": downloaded_files[0:1], |
|
"split_file": "test" |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, files, split_file): |
|
"""Yields examples.""" |
|
import json |
|
logger.info("| > generate examples for "+split_file) |
|
logger.info(files) |
|
for path in files: |
|
with open(path, 'r', encoding='utf-8') as fmm: |
|
data=json.load(fmm) |
|
for id_, row in enumerate(data): |
|
title=row[0] |
|
question=row[1] |
|
answers=row[2] |
|
keywords=row[3] |
|
yield id_, { |
|
"title": title, |
|
"question": question, |
|
"answers": answers, |
|
"keywords": keywords, |
|
} |