system HF staff commited on
Commit
9a403d6
1 Parent(s): 0c5d631

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. imdb.py +16 -28
README.md CHANGED
@@ -1,4 +1,5 @@
1
  ---
 
2
  languages:
3
  - en
4
  paperswithcode_id: imdb-movie-reviews
 
1
  ---
2
+ pretty_name: IMDB
3
  languages:
4
  - en
5
  paperswithcode_id: imdb-movie-reviews
imdb.py CHANGED
@@ -16,9 +16,6 @@
16
  # Lint as: python3
17
  """IMDB movie reviews dataset."""
18
 
19
-
20
- import os
21
-
22
  import datasets
23
  from datasets.tasks import TextClassification
24
 
@@ -82,42 +79,33 @@ class Imdb(datasets.GeneratorBasedBuilder):
82
  task_templates=[TextClassification(text_column="text", label_column="label")],
83
  )
84
 
85
- def _vocab_text_gen(self, archive):
86
- for _, ex in self._generate_examples(archive, os.path.join("aclImdb", "train")):
87
- yield ex["text"]
88
-
89
  def _split_generators(self, dl_manager):
90
- arch_path = dl_manager.download_and_extract(_DOWNLOAD_URL)
91
- data_dir = os.path.join(arch_path, "aclImdb")
92
  return [
93
  datasets.SplitGenerator(
94
- name=datasets.Split.TRAIN, gen_kwargs={"directory": os.path.join(data_dir, "train")}
95
  ),
96
  datasets.SplitGenerator(
97
- name=datasets.Split.TEST, gen_kwargs={"directory": os.path.join(data_dir, "test")}
98
  ),
99
  datasets.SplitGenerator(
100
  name=datasets.Split("unsupervised"),
101
- gen_kwargs={"directory": os.path.join(data_dir, "train"), "labeled": False},
102
  ),
103
  ]
104
 
105
- def _generate_examples(self, directory, labeled=True):
106
- """Generate IMDB examples."""
107
  # For labeled examples, extract the label from the path.
108
  if labeled:
109
- files = {
110
- "pos": sorted(os.listdir(os.path.join(directory, "pos"))),
111
- "neg": sorted(os.listdir(os.path.join(directory, "neg"))),
112
- }
113
- for key in files:
114
- for id_, file in enumerate(files[key]):
115
- filepath = os.path.join(directory, key, file)
116
- with open(filepath, encoding="UTF-8") as f:
117
- yield key + "_" + str(id_), {"text": f.read(), "label": key}
118
  else:
119
- unsup_files = sorted(os.listdir(os.path.join(directory, "unsup")))
120
- for id_, file in enumerate(unsup_files):
121
- filepath = os.path.join(directory, "unsup", file)
122
- with open(filepath, encoding="UTF-8") as f:
123
- yield id_, {"text": f.read(), "label": -1}
 
16
  # Lint as: python3
17
  """IMDB movie reviews dataset."""
18
 
 
 
 
19
  import datasets
20
  from datasets.tasks import TextClassification
21
 
 
79
  task_templates=[TextClassification(text_column="text", label_column="label")],
80
  )
81
 
 
 
 
 
82
  def _split_generators(self, dl_manager):
83
+ archive = dl_manager.download(_DOWNLOAD_URL)
 
84
  return [
85
  datasets.SplitGenerator(
86
+ name=datasets.Split.TRAIN, gen_kwargs={"files": dl_manager.iter_archive(archive), "split": "train"}
87
  ),
88
  datasets.SplitGenerator(
89
+ name=datasets.Split.TEST, gen_kwargs={"files": dl_manager.iter_archive(archive), "split": "test"}
90
  ),
91
  datasets.SplitGenerator(
92
  name=datasets.Split("unsupervised"),
93
+ gen_kwargs={"files": dl_manager.iter_archive(archive), "split": "train", "labeled": False},
94
  ),
95
  ]
96
 
97
+ def _generate_examples(self, files, split, labeled=True):
98
+ """Generate aclImdb examples."""
99
  # For labeled examples, extract the label from the path.
100
  if labeled:
101
+ label_mapping = {"pos": 1, "neg": 0}
102
+ for path, f in files:
103
+ if path.startswith(f"aclImdb/{split}"):
104
+ label = label_mapping.get(path.split("/")[2])
105
+ if label is not None:
106
+ yield path, {"text": f.read().decode("utf-8"), "label": label}
 
 
 
107
  else:
108
+ for path, f in files:
109
+ if path.startswith(f"aclImdb/{split}"):
110
+ if path.split("/")[2] == "unsup":
111
+ yield path, {"text": f.read().decode("utf-8"), "label": -1}