Datasets:
Tasks:
Text Classification
Modalities:
Text
Formats:
parquet
Sub-tasks:
sentiment-classification
Languages:
French
Size:
100K - 1M
License:
Commit
·
02dcf22
1
Parent(s):
e0c900e
Support streaming allocine dataset (#4563)
Browse files* Support streaming allocine dataset
* Fix style
Commit from https://github.com/huggingface/datasets/commit/514756651448c03e0a8f08141148552f4b223e29
- allocine.py +25 -13
allocine.py
CHANGED
|
@@ -2,7 +2,6 @@
|
|
| 2 |
|
| 3 |
|
| 4 |
import json
|
| 5 |
-
import os
|
| 6 |
|
| 7 |
import datasets
|
| 8 |
from datasets.tasks import TextClassification
|
|
@@ -70,25 +69,38 @@ class AllocineDataset(datasets.GeneratorBasedBuilder):
|
|
| 70 |
)
|
| 71 |
|
| 72 |
def _split_generators(self, dl_manager):
|
| 73 |
-
|
| 74 |
-
data_dir =
|
| 75 |
return [
|
| 76 |
datasets.SplitGenerator(
|
| 77 |
-
name=datasets.Split.TRAIN,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
),
|
| 79 |
datasets.SplitGenerator(
|
| 80 |
-
name=datasets.Split.VALIDATION,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
),
|
| 82 |
datasets.SplitGenerator(
|
| 83 |
-
name=datasets.Split.TEST,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
),
|
| 85 |
]
|
| 86 |
|
| 87 |
-
def _generate_examples(self, filepath):
|
| 88 |
"""Generate Allocine examples."""
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
|
|
|
|
|
| 2 |
|
| 3 |
|
| 4 |
import json
|
|
|
|
| 5 |
|
| 6 |
import datasets
|
| 7 |
from datasets.tasks import TextClassification
|
|
|
|
| 69 |
)
|
| 70 |
|
| 71 |
def _split_generators(self, dl_manager):
|
| 72 |
+
archive_path = dl_manager.download(self._DOWNLOAD_URL)
|
| 73 |
+
data_dir = "data"
|
| 74 |
return [
|
| 75 |
datasets.SplitGenerator(
|
| 76 |
+
name=datasets.Split.TRAIN,
|
| 77 |
+
gen_kwargs={
|
| 78 |
+
"filepath": f"{data_dir}/{self._TRAIN_FILE}",
|
| 79 |
+
"files": dl_manager.iter_archive(archive_path),
|
| 80 |
+
},
|
| 81 |
),
|
| 82 |
datasets.SplitGenerator(
|
| 83 |
+
name=datasets.Split.VALIDATION,
|
| 84 |
+
gen_kwargs={
|
| 85 |
+
"filepath": f"{data_dir}/{self._VAL_FILE}",
|
| 86 |
+
"files": dl_manager.iter_archive(archive_path),
|
| 87 |
+
},
|
| 88 |
),
|
| 89 |
datasets.SplitGenerator(
|
| 90 |
+
name=datasets.Split.TEST,
|
| 91 |
+
gen_kwargs={
|
| 92 |
+
"filepath": f"{data_dir}/{self._TEST_FILE}",
|
| 93 |
+
"files": dl_manager.iter_archive(archive_path),
|
| 94 |
+
},
|
| 95 |
),
|
| 96 |
]
|
| 97 |
|
| 98 |
+
def _generate_examples(self, filepath, files):
|
| 99 |
"""Generate Allocine examples."""
|
| 100 |
+
for path, file in files:
|
| 101 |
+
if path == filepath:
|
| 102 |
+
for id_, row in enumerate(file):
|
| 103 |
+
data = json.loads(row.decode("utf-8"))
|
| 104 |
+
review = data["review"]
|
| 105 |
+
label = "neg" if data["polarity"] == 0 else "pos"
|
| 106 |
+
yield id_, {"review": review, "label": label}
|