lhoestq HF staff commited on
Commit
e049714
1 Parent(s): 11c2dd5

Make yelp_polarity streamable (#4019)

Browse files

* make yelp_polarity streamable

* remove unused import

Commit from https://github.com/huggingface/datasets/commit/d78f5a5acf11096a80bb1ed198edc43f8911cff1

Files changed (2) hide show
  1. dataset_infos.json +1 -1
  2. yelp_polarity.py +26 -13
dataset_infos.json CHANGED
@@ -1 +1 @@
1
- {"plain_text": {"description": "Large Yelp Review Dataset.\nThis is a dataset for binary sentiment classification. We provide a set of 560,000 highly polar yelp reviews for training, and 38,000 for testing. \nORIGIN\nThe Yelp reviews dataset consists of reviews from Yelp. It is extracted\nfrom the Yelp Dataset Challenge 2015 data. For more information, please\nrefer to http://www.yelp.com/dataset_challenge\n\nThe Yelp reviews polarity dataset is constructed by\nXiang Zhang (xiang.zhang@nyu.edu) from the above dataset.\nIt is first used as a text classification benchmark in the following paper:\nXiang Zhang, Junbo Zhao, Yann LeCun. Character-level Convolutional Networks\nfor Text Classification. Advances in Neural Information Processing Systems 28\n(NIPS 2015).\n\n\nDESCRIPTION\n\nThe Yelp reviews polarity dataset is constructed by considering stars 1 and 2\nnegative, and 3 and 4 positive. For each polarity 280,000 training samples and\n19,000 testing samples are take randomly. In total there are 560,000 trainig\nsamples and 38,000 testing samples. Negative polarity is class 1,\nand positive class 2.\n\nThe files train.csv and test.csv contain all the training samples as\ncomma-sparated values. There are 2 columns in them, corresponding to class\nindex (1 and 2) and review text. The review texts are escaped using double\nquotes (\"), and any internal double quote is escaped by 2 double quotes (\"\").\nNew lines are escaped by a backslash followed with an \"n\" character,\nthat is \"\n\".\n", "citation": "@article{zhangCharacterlevelConvolutionalNetworks2015,\n archivePrefix = {arXiv},\n eprinttype = {arxiv},\n eprint = {1509.01626},\n primaryClass = {cs},\n title = {Character-Level {{Convolutional Networks}} for {{Text Classification}}},\n abstract = {This article offers an empirical exploration on the use of character-level convolutional networks (ConvNets) for text classification. We constructed several large-scale datasets to show that character-level convolutional networks could achieve state-of-the-art or competitive results. Comparisons are offered against traditional models such as bag of words, n-grams and their TFIDF variants, and deep learning models such as word-based ConvNets and recurrent neural networks.},\n journal = {arXiv:1509.01626 [cs]},\n author = {Zhang, Xiang and Zhao, Junbo and LeCun, Yann},\n month = sep,\n year = {2015},\n}\n\n", "homepage": "https://course.fast.ai/datasets", "license": "", "features": {"text": {"dtype": "string", "id": null, "_type": "Value"}, "label": {"num_classes": 2, "names": ["1", "2"], "names_file": null, "id": null, "_type": "ClassLabel"}}, "post_processed": null, "supervised_keys": null, "task_templates": [{"task": "text-classification", "text_column": "text", "label_column": "label", "labels": ["1", "2"]}], "builder_name": "yelp_polarity", "config_name": "plain_text", "version": {"version_str": "1.0.0", "description": "", "major": 1, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 413559061, "num_examples": 560000, "dataset_name": "yelp_polarity"}, "test": {"name": "test", "num_bytes": 27962113, "num_examples": 38000, "dataset_name": "yelp_polarity"}}, "download_checksums": {"https://s3.amazonaws.com/fast-ai-nlp/yelp_review_polarity_csv.tgz": {"num_bytes": 166373201, "checksum": "528f22e286cad085948acbc3bea7e58188416546b0e364d0ae4ca0ce666abe35"}}, "download_size": 166373201, "post_processing_size": null, "dataset_size": 441521174, "size_in_bytes": 607894375}}
1
+ {"plain_text": {"description": "Large Yelp Review Dataset.\nThis is a dataset for binary sentiment classification. We provide a set of 560,000 highly polar yelp reviews for training, and 38,000 for testing. \nORIGIN\nThe Yelp reviews dataset consists of reviews from Yelp. It is extracted\nfrom the Yelp Dataset Challenge 2015 data. For more information, please\nrefer to http://www.yelp.com/dataset_challenge\n\nThe Yelp reviews polarity dataset is constructed by\nXiang Zhang (xiang.zhang@nyu.edu) from the above dataset.\nIt is first used as a text classification benchmark in the following paper:\nXiang Zhang, Junbo Zhao, Yann LeCun. Character-level Convolutional Networks\nfor Text Classification. Advances in Neural Information Processing Systems 28\n(NIPS 2015).\n\n\nDESCRIPTION\n\nThe Yelp reviews polarity dataset is constructed by considering stars 1 and 2\nnegative, and 3 and 4 positive. For each polarity 280,000 training samples and\n19,000 testing samples are take randomly. In total there are 560,000 trainig\nsamples and 38,000 testing samples. Negative polarity is class 1,\nand positive class 2.\n\nThe files train.csv and test.csv contain all the training samples as\ncomma-sparated values. There are 2 columns in them, corresponding to class\nindex (1 and 2) and review text. The review texts are escaped using double\nquotes (\"), and any internal double quote is escaped by 2 double quotes (\"\").\nNew lines are escaped by a backslash followed with an \"n\" character,\nthat is \"\n\".\n", "citation": "@article{zhangCharacterlevelConvolutionalNetworks2015,\n archivePrefix = {arXiv},\n eprinttype = {arxiv},\n eprint = {1509.01626},\n primaryClass = {cs},\n title = {Character-Level {{Convolutional Networks}} for {{Text Classification}}},\n abstract = {This article offers an empirical exploration on the use of character-level convolutional networks (ConvNets) for text classification. We constructed several large-scale datasets to show that character-level convolutional networks could achieve state-of-the-art or competitive results. Comparisons are offered against traditional models such as bag of words, n-grams and their TFIDF variants, and deep learning models such as word-based ConvNets and recurrent neural networks.},\n journal = {arXiv:1509.01626 [cs]},\n author = {Zhang, Xiang and Zhao, Junbo and LeCun, Yann},\n month = sep,\n year = {2015},\n}\n\n", "homepage": "https://course.fast.ai/datasets", "license": "", "features": {"text": {"dtype": "string", "id": null, "_type": "Value"}, "label": {"num_classes": 2, "names": ["1", "2"], "id": null, "_type": "ClassLabel"}}, "post_processed": null, "supervised_keys": null, "task_templates": [{"task": "text-classification", "text_column": "text", "label_column": "label"}], "builder_name": "yelp_polarity", "config_name": "plain_text", "version": {"version_str": "1.0.0", "description": "", "major": 1, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 413558837, "num_examples": 560000, "dataset_name": "yelp_polarity"}, "test": {"name": "test", "num_bytes": 27962097, "num_examples": 38000, "dataset_name": "yelp_polarity"}}, "download_checksums": {"https://s3.amazonaws.com/fast-ai-nlp/yelp_review_polarity_csv.tgz": {"num_bytes": 166373201, "checksum": "528f22e286cad085948acbc3bea7e58188416546b0e364d0ae4ca0ce666abe35"}}, "download_size": 166373201, "post_processing_size": null, "dataset_size": 441520934, "size_in_bytes": 607894135}}
yelp_polarity.py CHANGED
@@ -30,8 +30,6 @@
30
  """Yelp Polarity Reviews dataset."""
31
 
32
 
33
- import os
34
-
35
  import datasets
36
  from datasets.tasks import TextClassification
37
 
@@ -132,18 +130,33 @@ class YelpPolarity(datasets.GeneratorBasedBuilder):
132
  yield ex["text"]
133
 
134
  def _split_generators(self, dl_manager):
135
- arch_path = dl_manager.download_and_extract(_DOWNLOAD_URL)
136
- train_file = os.path.join(arch_path, "yelp_review_polarity_csv", "train.csv")
137
- test_file = os.path.join(arch_path, "yelp_review_polarity_csv", "test.csv")
138
  return [
139
- datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_file}),
140
- datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": test_file}),
 
 
 
 
 
 
 
 
 
 
 
 
141
  ]
142
 
143
- def _generate_examples(self, filepath):
144
  """Generate Yelp examples."""
145
- with open(filepath, encoding="utf-8") as f:
146
- for line_id, line in enumerate(f):
147
- # The format of the line is:
148
- # "1", "The text of the review."
149
- yield line_id, {"text": line[5:-2].strip(), "label": line[1]}
 
 
 
30
  """Yelp Polarity Reviews dataset."""
31
 
32
 
 
 
33
  import datasets
34
  from datasets.tasks import TextClassification
35
 
130
  yield ex["text"]
131
 
132
  def _split_generators(self, dl_manager):
133
+ arch_path = dl_manager.download(_DOWNLOAD_URL)
134
+ train_file = "yelp_review_polarity_csv/train.csv"
135
+ test_file = "yelp_review_polarity_csv/test.csv"
136
  return [
137
+ datasets.SplitGenerator(
138
+ name=datasets.Split.TRAIN,
139
+ gen_kwargs={
140
+ "filepath": train_file,
141
+ "files": dl_manager.iter_archive(arch_path),
142
+ },
143
+ ),
144
+ datasets.SplitGenerator(
145
+ name=datasets.Split.TEST,
146
+ gen_kwargs={
147
+ "filepath": test_file,
148
+ "files": dl_manager.iter_archive(arch_path),
149
+ },
150
+ ),
151
  ]
152
 
153
+ def _generate_examples(self, filepath, files):
154
  """Generate Yelp examples."""
155
+ for path, f in files:
156
+ if path == filepath:
157
+ for line_id, line in enumerate(f):
158
+ line = line.decode("utf-8")
159
+ # The format of the line is:
160
+ # "1", "The text of the review."
161
+ yield line_id, {"text": line[5:-2].strip(), "label": line[1]}
162
+ break