blinoff commited on
Commit
251d8f8
1 Parent(s): 20348cf

Upload restaurants_reviews.py

Browse files
Files changed (1) hide show
  1. restaurants_reviews.py +50 -0
restaurants_reviews.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datasets
2
+ import json
3
+
4
+ class RestaurantsReviewsConfig(datasets.BuilderConfig):
5
+ def __init__(self, features, **kwargs):
6
+ super(RestaurantsReviewsConfig, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs)
7
+ self.features = features
8
+
9
+ class RestaurantsReviews(datasets.GeneratorBasedBuilder):
10
+ BUILDER_CONFIGS = [
11
+ RestaurantsReviewsConfig(
12
+ name="simple",
13
+ description="Simple config",
14
+ features=["review_id", "general", "food", "interior", "service", "text"],
15
+ )
16
+ ]
17
+
18
+ def _info(self):
19
+ return datasets.DatasetInfo(
20
+ description='Healthcare facilities reviews dataset.',
21
+ features=datasets.Features(
22
+ {
23
+ "review_id": datasets.Value("string"),
24
+ "general": datasets.Value("string"),
25
+ "food": datasets.Value("string"),
26
+ "interior": datasets.Value("string"),
27
+ "service": datasets.Value("string"),
28
+ "text": datasets.Value("string"),
29
+ "Idx": datasets.Value("int32"),
30
+ }
31
+ ),
32
+ )
33
+
34
+ def _split_generators(self, dl_manager: datasets.DownloadManager):
35
+ urls_to_download = {
36
+ "train": "restaurants_reviews.jsonl"
37
+ }
38
+ downloaded_files = dl_manager.download_and_extract(urls_to_download)
39
+
40
+ return [
41
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]})
42
+ ]
43
+
44
+ def _generate_examples(self, filepath):
45
+ """Yields examples."""
46
+ with open(filepath, encoding="utf-8") as f:
47
+ for uid, row in enumerate(f):
48
+ data = json.loads(row)
49
+ data["Idx"] = uid
50
+ yield uid, data