Datasets:
yelp
/

Modalities:
Text
Formats:
parquet
Languages:
English
ArXiv:
Libraries:
Datasets
pandas
License:
File size: 4,412 Bytes
27da5b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1581050
27da5b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7b5d95c
27da5b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1581050
27da5b3
 
 
 
 
7b5d95c
27da5b3
 
 
7b5d95c
27da5b3
 
 
7b5d95c
27da5b3
 
 
7b5d95c
704ae0d
7b5d95c
 
 
 
 
 
 
 
 
 
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# coding=utf-8
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""The Yelp Review Full dataset for text classification."""


import csv

import datasets
from datasets.tasks import TextClassification


_CITATION = """\
@inproceedings{zhang2015character,
  title={Character-level convolutional networks for text classification},
  author={Zhang, Xiang and Zhao, Junbo and LeCun, Yann},
  booktitle={Advances in neural information processing systems},
  pages={649--657},
  year={2015}
}
"""

_DESCRIPTION = """\
The Yelp reviews dataset consists of reviews from Yelp. It is extracted from the Yelp Dataset Challenge 2015 data.
The Yelp reviews full star dataset is constructed by Xiang Zhang ([email protected]) from the above dataset.
It is first used as a text classification benchmark in the following paper: Xiang Zhang, Junbo Zhao, Yann LeCun.
Character-level Convolutional Networks for Text Classification. Advances in Neural Information Processing Systems 28 (NIPS 2015).
"""

_HOMEPAGE = "https://www.yelp.com/dataset"

_LICENSE = "https://s3-media3.fl.yelpcdn.com/assets/srv0/engineering_pages/bea5c1e92bf3/assets/vendor/yelp-dataset-agreement.pdf"

_URLs = {
    "yelp_review_full": "https://s3.amazonaws.com/fast-ai-nlp/yelp_review_full_csv.tgz",
}


class YelpReviewFullConfig(datasets.BuilderConfig):
    """BuilderConfig for YelpReviewFull."""

    def __init__(self, **kwargs):
        """BuilderConfig for YelpReviewFull.

        Args:
          **kwargs: keyword arguments forwarded to super.
        """
        super(YelpReviewFullConfig, self).__init__(**kwargs)


class YelpReviewFull(datasets.GeneratorBasedBuilder):
    """Yelp Review Full Star Dataset 2015."""

    VERSION = datasets.Version("1.0.0")

    BUILDER_CONFIGS = [
        YelpReviewFullConfig(
            name="yelp_review_full", version=VERSION, description="Yelp Review Full Star Dataset 2015"
        ),
    ]

    def _info(self):
        features = datasets.Features(
            {
                "label": datasets.features.ClassLabel(
                    names=[
                        "1 star",
                        "2 star",
                        "3 stars",
                        "4 stars",
                        "5 stars",
                    ]
                ),
                "text": datasets.Value("string"),
            }
        )
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=features,
            supervised_keys=None,
            homepage=_HOMEPAGE,
            license=_LICENSE,
            citation=_CITATION,
            task_templates=[TextClassification(text_column="text", label_column="label")],
        )

    def _split_generators(self, dl_manager):
        """Returns SplitGenerators."""
        my_urls = _URLs[self.config.name]
        archive = dl_manager.download(my_urls)
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={"filepath": "yelp_review_full_csv/train.csv", "files": dl_manager.iter_archive(archive)},
            ),
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                gen_kwargs={"filepath": "yelp_review_full_csv/test.csv", "files": dl_manager.iter_archive(archive)},
            ),
        ]

    def _generate_examples(self, filepath, files):
        """Yields examples."""
        for path, f in files:
            if path == filepath:
                csvfile = (line.decode("utf-8") for line in f)
                data = csv.reader(csvfile, delimiter=",", quoting=csv.QUOTE_NONNUMERIC)
                for id_, row in enumerate(data):
                    yield id_, {
                        "text": row[1],
                        "label": int(row[0]) - 1,
                    }
                break