danasone commited on
Commit
7d479e6
1 Parent(s): 55bebad

Create taiga.py

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