import csv import os import datasets _CITATION = """ @misc{RecipeNLGLite, author = {Mehrdad Farahani}, title = {RecipeNLG: A Cooking Recipes Dataset for Semi-Structured Text Generation (Lite)}, year = 2021, publisher = {GitHub}, journal = {GitHub repository}, howpublished = {url{https://github.com/m3hrdadfi/recipe-nlg-lite}}, } """ _DESCRIPTION = """ RecipeNLG: A Cooking Recipes Dataset for Semi-Structured Text Generation - Lite version The dataset we publish contains 7,198 cooking recipes (>7K). It's processed in more careful way and provides more samples than any other dataset in the area.""" _HOMEPAGE = "https://github.com/m3hrdadfi/recipe-nlg-lite" _LICENSE = "MIT License" _URLs = { "1.0.0": { "data": "https://drive.google.com/uc?id=1PGH5H_oW7wUvMw_5xaXvbEN7DFll-wDX", "features": [ {"name": "uid", "type": datasets.Value("string")}, {"name": "name", "type": datasets.Value("string")}, {"name": "description", "type": datasets.Value("string")}, {"name": "link", "type": datasets.Value("string")}, {"name": "ner", "type": datasets.Value("string")}, {"name": "ingredients", "type": datasets.Value("string")}, {"name": "steps", "type": datasets.Value("string")}, ], } } class RecipeNLGLiteConfig(datasets.BuilderConfig): """BuilderConfig for RecipeNLGLite.""" def __init__(self, **kwargs): """BuilderConfig for RecipeNLGLite. Args: **kwargs: keyword arguments forwarded to super. """ super(RecipeNLGLiteConfig, self).__init__(**kwargs) class RecipeNLGLite(datasets.GeneratorBasedBuilder): BUILDER_CONFIGS = [ RecipeNLGLiteConfig( name="1.0.0", version=datasets.Version("1.0.0"), description="The first version of recipe_nlg_lite" ), ] def _info(self): feature_names_types = _URLs[self.config.name]["features"] features = datasets.Features({f["name"]: f["type"] for f in feature_names_types}) return datasets.DatasetInfo( description=_DESCRIPTION, features=features, homepage=_HOMEPAGE, citation=_CITATION ) def _split_generators(self, dl_manager): my_urls = _URLs[self.config.name] data_dir = dl_manager.download_and_extract(my_urls["data"]) return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={ "filepath": os.path.join(data_dir, "recipe_nlg_lite", "train.csv"), "split": "train", }, ), datasets.SplitGenerator( name=datasets.Split.TEST, gen_kwargs={ "filepath": os.path.join(data_dir, "recipe_nlg_lite", "test.csv"), "split": "test", }, ), ] def _generate_examples(self, filepath, split): feature_names_types = _URLs[self.config.name]["features"] features = [f["name"] for f in feature_names_types] with open(filepath, encoding="utf-8") as csv_file: reader = csv.DictReader(csv_file, quotechar='"', delimiter="\t", quoting=csv.QUOTE_MINIMAL) for _id, row in enumerate(reader): if len(row) == len(features): yield _id, {f: row[f] for f in features}