Datasets:
Tasks:
Text Classification
Modalities:
Text
Formats:
parquet
Sub-tasks:
sentiment-classification
Languages:
English
Size:
100K - 1M
ArXiv:
License:
Commit
·
ac93e45
1
Parent(s):
bfd4401
Delete loading script
Browse files- yelp_review_full.py +0 -124
yelp_review_full.py
DELETED
|
@@ -1,124 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
"""The Yelp Review Full dataset for text classification."""
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
import csv
|
| 19 |
-
|
| 20 |
-
import datasets
|
| 21 |
-
from datasets.tasks import TextClassification
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
_CITATION = """\
|
| 25 |
-
@inproceedings{zhang2015character,
|
| 26 |
-
title={Character-level convolutional networks for text classification},
|
| 27 |
-
author={Zhang, Xiang and Zhao, Junbo and LeCun, Yann},
|
| 28 |
-
booktitle={Advances in neural information processing systems},
|
| 29 |
-
pages={649--657},
|
| 30 |
-
year={2015}
|
| 31 |
-
}
|
| 32 |
-
"""
|
| 33 |
-
|
| 34 |
-
_DESCRIPTION = """\
|
| 35 |
-
The Yelp reviews dataset consists of reviews from Yelp. It is extracted from the Yelp Dataset Challenge 2015 data.
|
| 36 |
-
The Yelp reviews full star dataset is constructed by Xiang Zhang ([email protected]) from the above dataset.
|
| 37 |
-
It is first used as a text classification benchmark in the following paper: Xiang Zhang, Junbo Zhao, Yann LeCun.
|
| 38 |
-
Character-level Convolutional Networks for Text Classification. Advances in Neural Information Processing Systems 28 (NIPS 2015).
|
| 39 |
-
"""
|
| 40 |
-
|
| 41 |
-
_HOMEPAGE = "https://www.yelp.com/dataset"
|
| 42 |
-
|
| 43 |
-
_LICENSE = "https://s3-media3.fl.yelpcdn.com/assets/srv0/engineering_pages/bea5c1e92bf3/assets/vendor/yelp-dataset-agreement.pdf"
|
| 44 |
-
|
| 45 |
-
_URLs = {
|
| 46 |
-
"yelp_review_full": "https://s3.amazonaws.com/fast-ai-nlp/yelp_review_full_csv.tgz",
|
| 47 |
-
}
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
class YelpReviewFullConfig(datasets.BuilderConfig):
|
| 51 |
-
"""BuilderConfig for YelpReviewFull."""
|
| 52 |
-
|
| 53 |
-
def __init__(self, **kwargs):
|
| 54 |
-
"""BuilderConfig for YelpReviewFull.
|
| 55 |
-
|
| 56 |
-
Args:
|
| 57 |
-
**kwargs: keyword arguments forwarded to super.
|
| 58 |
-
"""
|
| 59 |
-
super(YelpReviewFullConfig, self).__init__(**kwargs)
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
class YelpReviewFull(datasets.GeneratorBasedBuilder):
|
| 63 |
-
"""Yelp Review Full Star Dataset 2015."""
|
| 64 |
-
|
| 65 |
-
VERSION = datasets.Version("1.0.0")
|
| 66 |
-
|
| 67 |
-
BUILDER_CONFIGS = [
|
| 68 |
-
YelpReviewFullConfig(
|
| 69 |
-
name="yelp_review_full", version=VERSION, description="Yelp Review Full Star Dataset 2015"
|
| 70 |
-
),
|
| 71 |
-
]
|
| 72 |
-
|
| 73 |
-
def _info(self):
|
| 74 |
-
features = datasets.Features(
|
| 75 |
-
{
|
| 76 |
-
"label": datasets.features.ClassLabel(
|
| 77 |
-
names=[
|
| 78 |
-
"1 star",
|
| 79 |
-
"2 star",
|
| 80 |
-
"3 stars",
|
| 81 |
-
"4 stars",
|
| 82 |
-
"5 stars",
|
| 83 |
-
]
|
| 84 |
-
),
|
| 85 |
-
"text": datasets.Value("string"),
|
| 86 |
-
}
|
| 87 |
-
)
|
| 88 |
-
return datasets.DatasetInfo(
|
| 89 |
-
description=_DESCRIPTION,
|
| 90 |
-
features=features,
|
| 91 |
-
supervised_keys=None,
|
| 92 |
-
homepage=_HOMEPAGE,
|
| 93 |
-
license=_LICENSE,
|
| 94 |
-
citation=_CITATION,
|
| 95 |
-
task_templates=[TextClassification(text_column="text", label_column="label")],
|
| 96 |
-
)
|
| 97 |
-
|
| 98 |
-
def _split_generators(self, dl_manager):
|
| 99 |
-
"""Returns SplitGenerators."""
|
| 100 |
-
my_urls = _URLs[self.config.name]
|
| 101 |
-
archive = dl_manager.download(my_urls)
|
| 102 |
-
return [
|
| 103 |
-
datasets.SplitGenerator(
|
| 104 |
-
name=datasets.Split.TRAIN,
|
| 105 |
-
gen_kwargs={"filepath": "yelp_review_full_csv/train.csv", "files": dl_manager.iter_archive(archive)},
|
| 106 |
-
),
|
| 107 |
-
datasets.SplitGenerator(
|
| 108 |
-
name=datasets.Split.TEST,
|
| 109 |
-
gen_kwargs={"filepath": "yelp_review_full_csv/test.csv", "files": dl_manager.iter_archive(archive)},
|
| 110 |
-
),
|
| 111 |
-
]
|
| 112 |
-
|
| 113 |
-
def _generate_examples(self, filepath, files):
|
| 114 |
-
"""Yields examples."""
|
| 115 |
-
for path, f in files:
|
| 116 |
-
if path == filepath:
|
| 117 |
-
csvfile = (line.decode("utf-8") for line in f)
|
| 118 |
-
data = csv.reader(csvfile, delimiter=",", quoting=csv.QUOTE_NONNUMERIC)
|
| 119 |
-
for id_, row in enumerate(data):
|
| 120 |
-
yield id_, {
|
| 121 |
-
"text": row[1],
|
| 122 |
-
"label": int(row[0]) - 1,
|
| 123 |
-
}
|
| 124 |
-
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|