| """A wine-ratings dataset""" |
|
|
| import csv |
|
|
| import datasets |
|
|
|
|
| _CITATION = """\ |
| @InProceedings{huggingface:dataset, |
| title = {A wine ratings dataset from regions around the world}, |
| author={Alfredo Deza |
| }, |
| year={2022} |
| } |
| """ |
|
|
| _DESCRIPTION = """\ |
| This is a dataset for wines in various regions around the world with names, regions, ratings and descriptions |
| """ |
|
|
| _HOMEPAGE = "https://github.com/paiml/wine-ratings" |
|
|
| _LICENSE = "MIT" |
|
|
| class WineRatings(datasets.GeneratorBasedBuilder): |
|
|
| VERSION = datasets.Version("0.0.1") |
|
|
| def _info(self): |
| features = datasets.Features( |
| { |
| "name": datasets.Value("string"), |
| "region": datasets.Value("string"), |
| "variety": datasets.Value("string"), |
| "rating": datasets.Value("float"), |
| "notes": datasets.Value("string"), |
| } |
| ) |
| return datasets.DatasetInfo( |
| description=_DESCRIPTION, |
| features=features, |
| homepage=_HOMEPAGE, |
| license=_LICENSE, |
| citation=_CITATION, |
| ) |
|
|
| def _split_generators(self, dl_manager): |
|
|
| return [ |
| datasets.SplitGenerator( |
| name=datasets.Split.TRAIN, |
| gen_kwargs={ |
| "filepath": "train.csv", |
| "split": "train", |
| }, |
| ), |
| datasets.SplitGenerator( |
| name=datasets.Split.VALIDATION, |
| gen_kwargs={ |
| "filepath": "validation.csv", |
| "split": "validation", |
| }, |
| ), |
| datasets.SplitGenerator( |
| name=datasets.Split.TEST, |
| gen_kwargs={ |
| "filepath": "test.csv", |
| "split": "test" |
| }, |
| ), |
| ] |
|
|
| |
| def _generate_examples(self, filepath, split): |
| with open(filepath, encoding="utf-8") as f: |
| csv_reader = csv.reader(f, delimiter=",") |
| next(csv_reader) |
| for id_, row in enumerate(csv_reader): |
| yield id_, { |
| "name": row[0], |
| "region": row[1], |
| "variety": row[2], |
| "rating": row[3], |
| "notes": row[4], |
| } |
|
|