Datasets:
Tasks:
Text Classification
Modalities:
Text
Formats:
parquet
Sub-tasks:
sentiment-classification
Languages:
English
Size:
100K - 1M
License:
Update files from the datasets library (from 1.16.0)
Browse filesRelease notes: https://github.com/huggingface/datasets/releases/tag/1.16.0
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 |
-
|
| 91 |
-
data_dir = os.path.join(arch_path, "aclImdb")
|
| 92 |
return [
|
| 93 |
datasets.SplitGenerator(
|
| 94 |
-
name=datasets.Split.TRAIN, gen_kwargs={"
|
| 95 |
),
|
| 96 |
datasets.SplitGenerator(
|
| 97 |
-
name=datasets.Split.TEST, gen_kwargs={"
|
| 98 |
),
|
| 99 |
datasets.SplitGenerator(
|
| 100 |
name=datasets.Split("unsupervised"),
|
| 101 |
-
gen_kwargs={"
|
| 102 |
),
|
| 103 |
]
|
| 104 |
|
| 105 |
-
def _generate_examples(self,
|
| 106 |
-
"""Generate
|
| 107 |
# For labeled examples, extract the label from the path.
|
| 108 |
if labeled:
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 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 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 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}
|
|
|