Create new file
Browse files- escorpius.py +147 -0
escorpius.py
ADDED
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2022 esCorpius authors
|
3 |
+
# The code required to produce and load this dataset is licensed under MIT License.
|
4 |
+
# The code samples included in this dataset keep their own licenses, which can be retrieved via their metadata.
|
5 |
+
# Unless required by applicable law or agreed to in writing, software
|
6 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
7 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
8 |
+
# See the License for the specific language governing permissions and
|
9 |
+
# limitations under the License.
|
10 |
+
|
11 |
+
# Please note that the dataset release is still work in progress.
|
12 |
+
|
13 |
+
"""The esCorpius dataset."""
|
14 |
+
|
15 |
+
import json
|
16 |
+
|
17 |
+
import datasets
|
18 |
+
|
19 |
+
from pathlib import Path
|
20 |
+
|
21 |
+
|
22 |
+
_CITATION = """\
|
23 |
+
@misc{TODO
|
24 |
+
}
|
25 |
+
"""
|
26 |
+
|
27 |
+
_DESCRIPTION = """\
|
28 |
+
Spanish dataset
|
29 |
+
""" # TODO: expand
|
30 |
+
|
31 |
+
_HOMEPAGE = "https://huggingface.co/datasets/LHF/escorpius"
|
32 |
+
|
33 |
+
_LICENSE = "CC BY-NC-ND 4.0"
|
34 |
+
|
35 |
+
_URL = ""
|
36 |
+
|
37 |
+
|
38 |
+
_FEATURES = datasets.Features(
|
39 |
+
{
|
40 |
+
"id": datasets.Value("string"),
|
41 |
+
"text": datasets.Value("string"),
|
42 |
+
"url_warc": datasets.Value("string"),
|
43 |
+
"url": datasets.Value("string")
|
44 |
+
|
45 |
+
}
|
46 |
+
)
|
47 |
+
|
48 |
+
|
49 |
+
class EsCorpiusConfig(datasets.BuilderConfig):
|
50 |
+
"""BuilderConfig for esCorpius."""
|
51 |
+
|
52 |
+
def __init__(self, *args, **kwargs):
|
53 |
+
"""BuilderConfig for The Pile.
|
54 |
+
Args:
|
55 |
+
**kwargs: keyword arguments forwarded to super.
|
56 |
+
"""
|
57 |
+
super().__init__(
|
58 |
+
*args,
|
59 |
+
**kwargs,
|
60 |
+
)
|
61 |
+
|
62 |
+
|
63 |
+
class EsCorpius(datasets.GeneratorBasedBuilder):
|
64 |
+
"""The esCorpius dataset."""
|
65 |
+
|
66 |
+
BUILDER_CONFIGS = [
|
67 |
+
EsCorpiusConfig(
|
68 |
+
name="esCorpius",
|
69 |
+
version=datasets.Version("1.0.1"),
|
70 |
+
description="Spanish dataset"
|
71 |
+
),
|
72 |
+
]
|
73 |
+
|
74 |
+
def _info(self):
|
75 |
+
"""Give information and typings for the dataset."""
|
76 |
+
return datasets.DatasetInfo(
|
77 |
+
# This is the description that will appear on the datasets page.
|
78 |
+
description=_DESCRIPTION,
|
79 |
+
# This defines the different columns of the dataset and their types
|
80 |
+
features=_FEATURES,
|
81 |
+
# If there's a common (input, target) tuple from the features,
|
82 |
+
# specify them here. They'll be used if as_supervised=True in
|
83 |
+
# builder.as_dataset.
|
84 |
+
supervised_keys=None,
|
85 |
+
# Homepage of the dataset for documentation
|
86 |
+
homepage=_HOMEPAGE,
|
87 |
+
# License for the dataset if available
|
88 |
+
license=_LICENSE,
|
89 |
+
# Citation for the dataset
|
90 |
+
citation=_CITATION,
|
91 |
+
)
|
92 |
+
|
93 |
+
def _split_generators(self, dl_manager):
|
94 |
+
"""Returns SplitGenerators."""
|
95 |
+
urls_to_download = [
|
96 |
+
'es_corpus.jsonl.aa',
|
97 |
+
'es_corpus.jsonl.ab',
|
98 |
+
'es_corpus.jsonl.ac',
|
99 |
+
'es_corpus.jsonl.ad',
|
100 |
+
'es_corpus.jsonl.ae',
|
101 |
+
'es_corpus.jsonl.af',
|
102 |
+
'es_corpus.jsonl.ag',
|
103 |
+
'es_corpus.jsonl.ah',
|
104 |
+
'es_corpus.jsonl.ai',
|
105 |
+
'es_corpus.jsonl.aj',
|
106 |
+
'es_corpus.jsonl.ak',
|
107 |
+
'es_corpus.jsonl.al',
|
108 |
+
'es_corpus.jsonl.am',
|
109 |
+
'es_corpus.jsonl.an',
|
110 |
+
'es_corpus.jsonl.ao',
|
111 |
+
'es_corpus.jsonl.ap',
|
112 |
+
'es_corpus.jsonl.aq',
|
113 |
+
'es_corpus.jsonl.ar',
|
114 |
+
'es_corpus.jsonl.as',
|
115 |
+
'es_corpus.jsonl.at',
|
116 |
+
'es_corpus.jsonl.au',
|
117 |
+
'es_corpus.jsonl.av',
|
118 |
+
'es_corpus.jsonl.aw',
|
119 |
+
'es_corpus.jsonl.ax',
|
120 |
+
'es_corpus.jsonl.ay',
|
121 |
+
'es_corpus.jsonl.az',
|
122 |
+
'es_corpus.jsonl.ba',
|
123 |
+
'es_corpus.jsonl.bb',
|
124 |
+
'es_corpus.jsonl.bc',
|
125 |
+
'es_corpus.jsonl.bd',
|
126 |
+
'es_corpus.jsonl.be',
|
127 |
+
'es_corpus.jsonl.bf',
|
128 |
+
'es_corpus.jsonl.bg'
|
129 |
+
]
|
130 |
+
downloaded_files = dl_manager.download_and_extract(urls_to_download)
|
131 |
+
|
132 |
+
return [
|
133 |
+
|
134 |
+
datasets.SplitGenerator(name='train',
|
135 |
+
gen_kwargs={"files": downloaded_files}),
|
136 |
+
]
|
137 |
+
|
138 |
+
def _generate_examples(self, files):
|
139 |
+
"""Yield examples as (key, example) tuples."""
|
140 |
+
key = 0
|
141 |
+
|
142 |
+
for path in sorted(Path(files).rglob('*.jsonl*')):
|
143 |
+
with open(open(path, "r"), encoding="utf-8") as f:
|
144 |
+
for row in f:
|
145 |
+
data = json.loads(row)
|
146 |
+
yield key, data
|
147 |
+
key += 1
|