Create house_rating.py
Browse files- house_rating.py +85 -0
house_rating.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""A wine-ratings dataset"""
|
| 2 |
+
|
| 3 |
+
import csv
|
| 4 |
+
|
| 5 |
+
import datasets
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
_CITATION = """\
|
| 9 |
+
@InProceedings{huggingface:dataset,
|
| 10 |
+
title = {A wine ratings dataset from regions around the world},
|
| 11 |
+
author={Alfredo Deza
|
| 12 |
+
},
|
| 13 |
+
year={2022}
|
| 14 |
+
}
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
_DESCRIPTION = """\
|
| 18 |
+
This is a dataset for wines in various regions around the world with names, regions, ratings and descriptions
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
_HOMEPAGE = "https://github.com/paiml/wine-ratings"
|
| 22 |
+
|
| 23 |
+
_LICENSE = "MIT"
|
| 24 |
+
|
| 25 |
+
class WineRatings(datasets.GeneratorBasedBuilder):
|
| 26 |
+
|
| 27 |
+
VERSION = datasets.Version("0.0.1")
|
| 28 |
+
|
| 29 |
+
def _info(self):
|
| 30 |
+
features = datasets.Features(
|
| 31 |
+
{
|
| 32 |
+
"name": datasets.Value("string"),
|
| 33 |
+
"region": datasets.Value("string"),
|
| 34 |
+
"variety": datasets.Value("string"),
|
| 35 |
+
"rating": datasets.Value("float"),
|
| 36 |
+
"notes": datasets.Value("string"),
|
| 37 |
+
}
|
| 38 |
+
)
|
| 39 |
+
return datasets.DatasetInfo(
|
| 40 |
+
description=_DESCRIPTION,
|
| 41 |
+
features=features,
|
| 42 |
+
homepage=_HOMEPAGE,
|
| 43 |
+
license=_LICENSE,
|
| 44 |
+
citation=_CITATION,
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
def _split_generators(self, dl_manager):
|
| 48 |
+
|
| 49 |
+
return [
|
| 50 |
+
datasets.SplitGenerator(
|
| 51 |
+
name=datasets.Split.TRAIN,
|
| 52 |
+
gen_kwargs={
|
| 53 |
+
"filepath": "train.csv",
|
| 54 |
+
"split": "train",
|
| 55 |
+
},
|
| 56 |
+
),
|
| 57 |
+
datasets.SplitGenerator(
|
| 58 |
+
name=datasets.Split.VALIDATION,
|
| 59 |
+
gen_kwargs={
|
| 60 |
+
"filepath": "validation.csv",
|
| 61 |
+
"split": "validation",
|
| 62 |
+
},
|
| 63 |
+
),
|
| 64 |
+
datasets.SplitGenerator(
|
| 65 |
+
name=datasets.Split.TEST,
|
| 66 |
+
gen_kwargs={
|
| 67 |
+
"filepath": "test.csv",
|
| 68 |
+
"split": "test"
|
| 69 |
+
},
|
| 70 |
+
),
|
| 71 |
+
]
|
| 72 |
+
|
| 73 |
+
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
| 74 |
+
def _generate_examples(self, filepath, split):
|
| 75 |
+
with open(filepath, encoding="utf-8") as f:
|
| 76 |
+
csv_reader = csv.reader(f, delimiter=",")
|
| 77 |
+
next(csv_reader)
|
| 78 |
+
for id_, row in enumerate(csv_reader):
|
| 79 |
+
yield id_, {
|
| 80 |
+
"name": row[0],
|
| 81 |
+
"region": row[1],
|
| 82 |
+
"variety": row[2],
|
| 83 |
+
"rating": row[3],
|
| 84 |
+
"notes": row[4],
|
| 85 |
+
}
|