Commit
·
eb28e6e
1
Parent(s):
cdab174
Support streaming id_clickbait dataset (#4014)
Browse files* Support streaming id_clickbait dataset
* Fix paths on Windows
* Simplify code
Commit from https://github.com/huggingface/datasets/commit/f56672b7adb8733cd9c914675f96736c196a9c0f
- id_clickbait.py +13 -15
id_clickbait.py
CHANGED
@@ -47,7 +47,7 @@ _HOMEPAGE = "https://github.com/feryandi/Dataset-Artikel"
|
|
47 |
|
48 |
_LICENSE = "Creative Commons Attribution 4.0 International license"
|
49 |
|
50 |
-
|
51 |
|
52 |
|
53 |
class IdClickbaitConfig(datasets.BuilderConfig):
|
@@ -72,9 +72,9 @@ class IdClickbait(datasets.GeneratorBasedBuilder):
|
|
72 |
version=VERSION,
|
73 |
description="Annotated clickbait dataset",
|
74 |
label_classes=["non-clickbait", "clickbait"],
|
75 |
-
path="annotated
|
76 |
),
|
77 |
-
IdClickbaitConfig(name="raw", version=VERSION, description="Raw dataset", path="raw
|
78 |
]
|
79 |
|
80 |
BUILDER_CONFIG_CLASS = IdClickbaitConfig
|
@@ -111,34 +111,32 @@ class IdClickbait(datasets.GeneratorBasedBuilder):
|
|
111 |
)
|
112 |
|
113 |
def _split_generators(self, dl_manager):
|
114 |
-
|
115 |
-
data_dir = dl_manager.download_and_extract(my_urls)
|
116 |
return [
|
117 |
datasets.SplitGenerator(
|
118 |
name=datasets.Split.TRAIN,
|
119 |
gen_kwargs={
|
120 |
"article_dir": os.path.join(data_dir, self.config.path),
|
121 |
-
"split": "train",
|
122 |
},
|
123 |
)
|
124 |
]
|
125 |
|
126 |
-
def _generate_examples(self, article_dir
|
127 |
-
logger.info("⏳ Generating
|
128 |
-
|
129 |
-
for path in sorted(glob.glob(os.path.join(article_dir, "
|
130 |
with open(path, encoding="utf-8-sig", newline="") as f:
|
131 |
reader = csv.DictReader(f)
|
132 |
for row in reader:
|
133 |
if self.config.name == "annotated":
|
134 |
-
yield
|
135 |
-
"id": str(
|
136 |
"title": row["title"],
|
137 |
"label": row["label"],
|
138 |
}
|
139 |
else:
|
140 |
-
yield
|
141 |
-
"id": str(
|
142 |
"title": row["title"],
|
143 |
"source": row["source"],
|
144 |
"date": row["date"],
|
@@ -147,4 +145,4 @@ class IdClickbait(datasets.GeneratorBasedBuilder):
|
|
147 |
"content": row["content"],
|
148 |
"url": row["url"],
|
149 |
}
|
150 |
-
|
|
|
47 |
|
48 |
_LICENSE = "Creative Commons Attribution 4.0 International license"
|
49 |
|
50 |
+
_URL = "https://md-datasets-cache-zipfiles-prod.s3.eu-west-1.amazonaws.com/k42j7x2kpn-1.zip"
|
51 |
|
52 |
|
53 |
class IdClickbaitConfig(datasets.BuilderConfig):
|
|
|
72 |
version=VERSION,
|
73 |
description="Annotated clickbait dataset",
|
74 |
label_classes=["non-clickbait", "clickbait"],
|
75 |
+
path=os.path.join("annotated", "csv"),
|
76 |
),
|
77 |
+
IdClickbaitConfig(name="raw", version=VERSION, description="Raw dataset", path=os.path.join("raw", "csv")),
|
78 |
]
|
79 |
|
80 |
BUILDER_CONFIG_CLASS = IdClickbaitConfig
|
|
|
111 |
)
|
112 |
|
113 |
def _split_generators(self, dl_manager):
|
114 |
+
data_dir = dl_manager.download_and_extract(_URL)
|
|
|
115 |
return [
|
116 |
datasets.SplitGenerator(
|
117 |
name=datasets.Split.TRAIN,
|
118 |
gen_kwargs={
|
119 |
"article_dir": os.path.join(data_dir, self.config.path),
|
|
|
120 |
},
|
121 |
)
|
122 |
]
|
123 |
|
124 |
+
def _generate_examples(self, article_dir):
|
125 |
+
logger.info(f"⏳ Generating examples from = {article_dir}")
|
126 |
+
idx = 0
|
127 |
+
for path in sorted(glob.glob(os.path.join(article_dir, "*.csv"))):
|
128 |
with open(path, encoding="utf-8-sig", newline="") as f:
|
129 |
reader = csv.DictReader(f)
|
130 |
for row in reader:
|
131 |
if self.config.name == "annotated":
|
132 |
+
yield idx, {
|
133 |
+
"id": str(idx),
|
134 |
"title": row["title"],
|
135 |
"label": row["label"],
|
136 |
}
|
137 |
else:
|
138 |
+
yield idx, {
|
139 |
+
"id": str(idx),
|
140 |
"title": row["title"],
|
141 |
"source": row["source"],
|
142 |
"date": row["date"],
|
|
|
145 |
"content": row["content"],
|
146 |
"url": row["url"],
|
147 |
}
|
148 |
+
idx += 1
|