healthcare_facilities_reviews / healthcare_facilities_reviews.py
blinoff's picture
Update healthcare_facilities_reviews.py
17110eb
raw
history blame
2.1 kB
import datasets
import json
class HfreviewsConfig(datasets.BuilderConfig):
def __init__(self, features, **kwargs):
super(HfreviewsConfig, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs)
self.features = features
class HealthcareFacilitiesReviews(datasets.GeneratorBasedBuilder):
BUILDER_CONFIGS = [
HfreviewsConfig(
name="simple",
description="Simple config",
features=["content", "title", "sentiment", "category", "review_id", "source_url"],
)
]
def _info(self):
return datasets.DatasetInfo(
description='Healthcare facilities reviews dataset.',
features=datasets.Features(
{
"content": datasets.Value("string"),
"title": datasets.Value("string"),
"sentiment": datasets.Value("string"),
"category": datasets.Value("string"),
"review_id": datasets.Value("string"),
"source_url": datasets.Value("string"),
"Idx": datasets.Value("int32"),
}
),
supervised_keys=None,
homepage='',
)
def _split_generators(self, dl_manager: datasets.DownloadManager):
urls_to_download = {
"train": "healthcare_facilities_reviews.jsonl",
"dev": "healthcare_facilities_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"]}),
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
]
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