Initial commit
Browse files
wikipedia_snippets_streamed.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Wikipedia snippets in parquet format"""
|
2 |
+
import os
|
3 |
+
import pyarrow.parquet as pq
|
4 |
+
import datasets
|
5 |
+
|
6 |
+
logger = datasets.logging.get_logger(__name__)
|
7 |
+
_CITATION = """\
|
8 |
+
@ONLINE {wikidump,
|
9 |
+
author = {Wikimedia Foundation},
|
10 |
+
title = {Wikimedia Downloads},
|
11 |
+
url = {https://dumps.wikimedia.org}
|
12 |
+
}
|
13 |
+
"""
|
14 |
+
_DESCRIPTION = """\
|
15 |
+
The dataset was built from the Wikipedia dump (https://dumps.wikimedia.org/).
|
16 |
+
Each example contains the content of one full Wikipedia article with cleaning to strip
|
17 |
+
markdown and unwanted sections (references, etc.).
|
18 |
+
"""
|
19 |
+
_LICENSE = (
|
20 |
+
"This work is licensed under the Creative Commons Attribution-ShareAlike "
|
21 |
+
"3.0 Unported License. To view a copy of this license, visit "
|
22 |
+
"http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to "
|
23 |
+
"Creative Commons, PO Box 1866, Mountain View, CA 94042, USA."
|
24 |
+
)
|
25 |
+
|
26 |
+
|
27 |
+
class WikipediaSnippetsStreamed(datasets.ArrowBasedBuilder):
|
28 |
+
"""Bengali wikipedia from 03/20/2021"""
|
29 |
+
|
30 |
+
def _info(self):
|
31 |
+
return datasets.DatasetInfo(
|
32 |
+
description=_DESCRIPTION,
|
33 |
+
features=datasets.Features(
|
34 |
+
{
|
35 |
+
"title": datasets.Value("string"),
|
36 |
+
"text": datasets.Value("string"),
|
37 |
+
}
|
38 |
+
),
|
39 |
+
supervised_keys=None,
|
40 |
+
homepage="https://dumps.wikimedia.org",
|
41 |
+
citation=_CITATION,
|
42 |
+
)
|
43 |
+
|
44 |
+
def _split_generators(self, dl_manager):
|
45 |
+
url = "https://storage.googleapis.com/huggingface-nlp/cache/datasets/wiki40b/en/1.1.0/wiki40b-train.parquet"
|
46 |
+
downloaded_files = dl_manager.download(url)
|
47 |
+
return [
|
48 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepaths": downloaded_files["train"]}),
|
49 |
+
]
|
50 |
+
|
51 |
+
def _generate_tables(self, filepaths):
|
52 |
+
"""This function returns the examples in the raw (text) form."""
|
53 |
+
for filepath in filepaths:
|
54 |
+
logger.info("generating examples from = %s", filepath)
|
55 |
+
filepath_id = os.path.basename(filepath)
|
56 |
+
with open(filepath, "rb") as f:
|
57 |
+
pf = pq.ParquetFile(f)
|
58 |
+
for i in range(pf.num_row_groups):
|
59 |
+
id_ = f"{filepath_id}_{i}"
|
60 |
+
yield id_, pf.read_row_group(i)
|