File size: 2,705 Bytes
7d479e6 8403b88 7d479e6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
import datasets
import zipfile
import urllib.request
import os
logger = datasets.logging.get_logger(__name__)
_DESCRIPTION = """\
A colossal, cleaned version of Common Crawl's web crawl corpus.
Based on Common Crawl dataset: "https://commoncrawl.org".
This is the processed version of Google's mC4 dataset by AllenAI.
"""
_CITATION = """
@article{2019t5,
author = {Colin Raffel and Noam Shazeer and Adam Roberts and Katherine Lee and Sharan Narang and Michael Matena and Yanqi Zhou and Wei Li and Peter J. Liu},
title = {Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer},
journal = {arXiv e-prints},
year = {2019},
archivePrefix = {arXiv},
eprint = {1910.10683},
}
"""
_URL = "https://linghub.ru/static/Taiga/news.zip"
_DATA_URL = "https://linghub.ru/static/Taiga/news.zip"
class TaigaConfig(datasets.BuilderConfig):
"""BuilderConfig for mC4."""
def __init__(self, *args, **kwargs):
"""BuilderConfig for mC4.
Args:
languages (:obj:`List[str]`): list of languages to load
**kwargs: keyword arguments forwarded to super.
"""
super().__init__(
*args,
name="taiga",
**kwargs,
)
class Taiga(datasets.GeneratorBasedBuilder):
"""mC4, a colossal, cleaned version of Common Crawl's web crawl corpus."""
BUILDER_CONFIGS = [TaigaConfig()]
BUILDER_CONFIG_CLASS = TaigaConfig
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"text": datasets.Value("string"),
}
),
)
def _split_generators(self, dl_manager):
downloaded_file = dl_manager.download(['proza_ru2.zip', 'stihi_ru.zip', 'proza_ru1.zip'])
return [
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepaths": downloaded_file}),
]
def _generate_examples(self, filepaths):
"""This function returns the examples in the raw (text) form by iterating on all the files."""
id_ = 0
for filepath in filepaths:
logger.info("generating examples from = %s", filepath)
with zipfile.ZipFile(filepath) as z:
for filename in z.namelist():
if not os.path.isdir(filename) and '.txt' in filename.split('/') and len(filename.split('/')) > 2:
# read the file
with z.open(filename) as f:
txt = f.read().decode('utf-8')
yield id_, {'text': txt}
id_ += 1
|