File size: 1,853 Bytes
251d8f8 |
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 |
import datasets
import json
class RestaurantsReviewsConfig(datasets.BuilderConfig):
def __init__(self, features, **kwargs):
super(RestaurantsReviewsConfig, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs)
self.features = features
class RestaurantsReviews(datasets.GeneratorBasedBuilder):
BUILDER_CONFIGS = [
RestaurantsReviewsConfig(
name="simple",
description="Simple config",
features=["review_id", "general", "food", "interior", "service", "text"],
)
]
def _info(self):
return datasets.DatasetInfo(
description='Healthcare facilities reviews dataset.',
features=datasets.Features(
{
"review_id": datasets.Value("string"),
"general": datasets.Value("string"),
"food": datasets.Value("string"),
"interior": datasets.Value("string"),
"service": datasets.Value("string"),
"text": datasets.Value("string"),
"Idx": datasets.Value("int32"),
}
),
)
def _split_generators(self, dl_manager: datasets.DownloadManager):
urls_to_download = {
"train": "restaurants_reviews.jsonl"
}
downloaded_files = dl_manager.download_and_extract(urls_to_download)
return [
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]})
]
def _generate_examples(self, filepath):
"""Yields examples."""
with open(filepath, encoding="utf-8") as f:
for uid, row in enumerate(f):
data = json.loads(row)
data["Idx"] = uid
yield uid, data
|