system HF staff commited on
Commit
26f40d3
1 Parent(s): 4463af2

Update files from the datasets library (from 1.16.0)

Browse files

Release notes: https://github.com/huggingface/datasets/releases/tag/1.16.0

Files changed (2) hide show
  1. README.md +1 -0
  2. rotten_tomatoes.py +16 -21
README.md CHANGED
@@ -1,4 +1,5 @@
1
  ---
 
2
  languages:
3
  - en
4
  paperswithcode_id: null
 
1
  ---
2
+ pretty_name: RottenTomatoes - Movie Review Data
3
  languages:
4
  - en
5
  paperswithcode_id: null
rotten_tomatoes.py CHANGED
@@ -16,9 +16,6 @@
16
  # Lint as: python3
17
  """Rotten tomatoes movie reviews dataset."""
18
 
19
-
20
- import os
21
-
22
  import datasets
23
  from datasets.tasks import TextClassification
24
 
@@ -62,41 +59,39 @@ class RottenTomatoesMovieReview(datasets.GeneratorBasedBuilder):
62
  task_templates=[TextClassification(text_column="text", label_column="label")],
63
  )
64
 
65
- def _vocab_text_gen(self, train_file):
66
- for _, ex in self._generate_examples(train_file):
67
- yield ex["text"]
68
-
69
  def _split_generators(self, dl_manager):
70
  """Downloads Rotten Tomatoes sentences."""
71
- extracted_folder_path = dl_manager.download_and_extract(_DOWNLOAD_URL)
72
  return [
73
  datasets.SplitGenerator(
74
  name=datasets.Split.TRAIN,
75
- gen_kwargs={"split_key": "train", "data_dir": extracted_folder_path},
76
  ),
77
  datasets.SplitGenerator(
78
  name=datasets.Split.VALIDATION,
79
- gen_kwargs={"split_key": "validation", "data_dir": extracted_folder_path},
80
  ),
81
  datasets.SplitGenerator(
82
  name=datasets.Split.TEST,
83
- gen_kwargs={"split_key": "test", "data_dir": extracted_folder_path},
84
  ),
85
  ]
86
 
87
- def _get_examples_from_split(self, split_key, data_dir):
88
  """Reads Rotten Tomatoes sentences and splits into 80% train,
89
  10% validation, and 10% test, as is the practice set out in Jinfeng
90
  Li, ``TEXTBUGGER: Generating Adversarial Text Against Real-world
91
  Applications.''
92
  """
93
- data_dir = os.path.join(data_dir, "rt-polaritydata")
94
-
95
- pos_samples = open(os.path.join(data_dir, "rt-polarity.pos"), encoding="latin-1").readlines()
96
- pos_samples = list(map(lambda t: t.strip(), pos_samples))
97
-
98
- neg_samples = open(os.path.join(data_dir, "rt-polarity.neg"), encoding="latin-1").readlines()
99
- neg_samples = list(map(lambda t: t.strip(), neg_samples))
 
 
100
 
101
  # 80/10/10 split
102
  i1 = int(len(pos_samples) * 0.8 + 0.5)
@@ -117,9 +112,9 @@ class RottenTomatoesMovieReview(datasets.GeneratorBasedBuilder):
117
  else:
118
  raise ValueError(f"Invalid split key {split_key}")
119
 
120
- def _generate_examples(self, split_key, data_dir):
121
  """Yields examples for a given split of MR."""
122
- split_text, split_labels = self._get_examples_from_split(split_key, data_dir)
123
  for text, label in zip(split_text, split_labels):
124
  data_key = split_key + "_" + text
125
  feature_dict = {"text": text, "label": label}
 
16
  # Lint as: python3
17
  """Rotten tomatoes movie reviews dataset."""
18
 
 
 
 
19
  import datasets
20
  from datasets.tasks import TextClassification
21
 
 
59
  task_templates=[TextClassification(text_column="text", label_column="label")],
60
  )
61
 
 
 
 
 
62
  def _split_generators(self, dl_manager):
63
  """Downloads Rotten Tomatoes sentences."""
64
+ archive = dl_manager.download(_DOWNLOAD_URL)
65
  return [
66
  datasets.SplitGenerator(
67
  name=datasets.Split.TRAIN,
68
+ gen_kwargs={"split_key": "train", "files": dl_manager.iter_archive(archive)},
69
  ),
70
  datasets.SplitGenerator(
71
  name=datasets.Split.VALIDATION,
72
+ gen_kwargs={"split_key": "validation", "files": dl_manager.iter_archive(archive)},
73
  ),
74
  datasets.SplitGenerator(
75
  name=datasets.Split.TEST,
76
+ gen_kwargs={"split_key": "test", "files": dl_manager.iter_archive(archive)},
77
  ),
78
  ]
79
 
80
+ def _get_examples_from_split(self, split_key, files):
81
  """Reads Rotten Tomatoes sentences and splits into 80% train,
82
  10% validation, and 10% test, as is the practice set out in Jinfeng
83
  Li, ``TEXTBUGGER: Generating Adversarial Text Against Real-world
84
  Applications.''
85
  """
86
+ data_dir = "rt-polaritydata/"
87
+ pos_samples, neg_samples = None, None
88
+ for path, f in files:
89
+ if path == data_dir + "rt-polarity.pos":
90
+ pos_samples = [line.decode("latin-1").strip() for line in f]
91
+ elif path == data_dir + "rt-polarity.neg":
92
+ neg_samples = [line.decode("latin-1").strip() for line in f]
93
+ if pos_samples is not None and neg_samples is not None:
94
+ break
95
 
96
  # 80/10/10 split
97
  i1 = int(len(pos_samples) * 0.8 + 0.5)
 
112
  else:
113
  raise ValueError(f"Invalid split key {split_key}")
114
 
115
+ def _generate_examples(self, split_key, files):
116
  """Yields examples for a given split of MR."""
117
+ split_text, split_labels = self._get_examples_from_split(split_key, files)
118
  for text, label in zip(split_text, split_labels):
119
  data_key = split_key + "_" + text
120
  feature_dict = {"text": text, "label": label}