File size: 9,644 Bytes
d617661 30d835f d617661 52783d2 d617661 30d835f ef1bc3d 3da0754 30d835f bafe1b7 30d835f bafe1b7 30d835f d617661 52783d2 d617661 bafe1b7 d617661 30d835f d617661 52783d2 bafe1b7 52783d2 bafe1b7 52783d2 d617661 52783d2 d617661 30d835f d617661 30d835f 52783d2 704128b ff8d123 30d835f bafe1b7 59692a4 bafe1b7 52783d2 30d835f |
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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# coding=utf-8
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""German Common Crawl"""
from __future__ import absolute_import, division, print_function
import datasets
import gzip
from ast import literal_eval
# Find for instance the citation on arxiv or on the dataset repo/website
_CITATION = """\
@inproceedings{wenzek2020ccnet,
title={CCNet: Extracting High Quality Monolingual Datasets from Web Crawl Data},
author={Wenzek, Guillaume and Lachaux, Marie-Anne and Conneau, Alexis and Chaudhary, Vishrav and Guzm{\'a}n, Francisco and Joulin, Armand and Grave, {\'E}douard},
booktitle={Proceedings of The 12th Language Resources and Evaluation Conference},
pages={4003--4012},
year={2020}
}
"""
_DESCRIPTION = """\
German Only Extract from Common Crawl
This Dataset is for pretraining a German Language Model (Unsupervised) or tune a Multilingual Model specifically to German
"""
REPO_URL = "https://huggingface.co/datasets/flax-community/german_common_crawl/resolve/main/"
_URL_FIRST = [REPO_URL + file_name for file_name in [
"de_head_0000_2016-44.jsonl",
# "dummy.txt.gz",
]]
#TODO convert & upload all those files correctly
_URL_HEAD = [REPO_URL + file_name for file_name in [
"de_head_0000_2015-48.txt.gz",
"de_head_0000_2016-18.txt.gz",
"de_head_0000_2016-44.txt.gz",
"de_head_0000_2017-13.txt.gz",
"de_head_0000_2017-30.txt.gz",
"de_head_0000_2017-39.txt.gz",
"de_head_0000_2017-51.txt.gz",
"de_head_0000_2018-09.txt.gz",
"de_head_0000_2018-17.txt.gz",
"de_head_0000_2018-30.txt.gz",
"de_head_0000_2018-39.txt.gz",
"de_head_0000_2018-51.txt.gz",
"de_head_0000_2019-18.txt.gz",
"de_head_0000_2019-30.txt.gz",
"de_head_0000_2019-47.txt.gz",
"de_head_0000_2020-10.txt.gz",
"de_head_0001_2016-44.txt.gz",
"de_head_0001_2017-13.txt.gz",
"de_head_0001_2017-30.txt.gz",
"de_head_0001_2017-39.txt.gz",
"de_head_0001_2017-51.txt.gz",
"de_head_0001_2018-09.txt.gz",
"de_head_0001_2018-17.txt.gz",
"de_head_0001_2018-30.txt.gz",
"de_head_0001_2018-39.txt.gz",
"de_head_0001_2018-51.txt.gz",
"de_head_0001_2019-09.txt.gz",
"de_head_0001_2019-18.txt.gz",
"de_head_0001_2019-30.txt.gz",
"de_head_0001_2019-47.txt.gz",
"de_head_0001_2020-10.txt.gz",
"de_head_0002_2016-44.txt.gz",
"de_head_0002_2017-13.txt.gz",
"de_head_0002_2017-30.txt.gz",
"de_head_0002_2017-39.txt.gz",
"de_head_0002_2017-51.txt.gz",
"de_head_0002_2018-09.txt.gz",
"de_head_0002_2018-17.txt.gz",
"de_head_0002_2018-30.txt.gz",
"de_head_0002_2018-39.txt.gz",
"de_head_0002_2018-51.txt.gz",
"de_head_0002_2019-09.txt.gz",
"de_head_0002_2019-18.txt.gz",
"de_head_0002_2019-30.txt.gz",
"de_head_0002_2019-47.txt.gz",
"de_head_0002_2020-10.txt.gz",
"de_head_0003_2016-44.txt.gz",
"de_head_0003_2017-13.txt.gz",
"de_head_0003_2017-30.txt.gz",
"de_head_0003_2017-39.txt.gz",
"de_head_0003_2017-51.txt.gz",
"de_head_0003_2018-09.txt.gz",
"de_head_0003_2018-17.txt.gz",
"de_head_0003_2018-30.txt.gz",
"de_head_0003_2018-39.txt.gz",
"de_head_0003_2018-51.txt.gz",
"de_head_0003_2019-09.txt.gz",
"de_head_0003_2019-18.txt.gz",
"de_head_0003_2019-30.txt.gz",
"de_head_0003_2019-47.txt.gz",
"de_head_0003_2020-10.txt.gz",
"de_head_0004_2016-44.txt.gz",
"de_head_0004_2017-30.txt.gz",
"de_head_0004_2017-39.txt.gz",
"de_head_0004_2017-51.txt.gz",
"de_head_0004_2018-09.txt.gz",
"de_head_0004_2018-17.txt.gz",
"de_head_0004_2018-30.txt.gz",
"de_head_0004_2018-39.txt.gz",
"de_head_0004_2018-51.txt.gz",
"de_head_0004_2019-09.txt.gz",
"de_head_0004_2019-18.txt.gz",
"de_head_0004_2019-30.txt.gz",
"de_head_0004_2019-47.txt.gz",
"de_head_0004_2020-10.txt.gz",
"de_head_0005_2017-51.txt.gz",
"de_head_0005_2018-09.txt.gz",
"de_head_0005_2018-17.txt.gz",
"de_head_0005_2018-30.txt.gz",
"de_head_0005_2018-39.txt.gz",
"de_head_0005_2018-51.txt.gz",
"de_head_0005_2019-09.txt.gz",
"de_head_0005_2019-18.txt.gz",
"de_head_0005_2019-30.txt.gz",
"de_head_0005_2019-47.txt.gz",
"de_head_0005_2020-10.txt.gz",
"de_head_0006_2018-09.txt.gz",
"de_head_0006_2018-17.txt.gz",
"de_head_0006_2018-30.txt.gz",
"de_head_0006_2018-39.txt.gz",
"de_head_0006_2018-51.txt.gz",
"de_head_0006_2019-09.txt.gz",
"de_head_0006_2019-18.txt.gz",
"de_head_0006_2019-30.txt.gz",
"de_head_0006_2019-47.txt.gz",
"de_head_0006_2020-10.txt.gz",
"de_head_0007_2018-30.txt.gz",
"de_head_0007_2018-51.txt.gz",
"de_head_0007_2019-09.txt.gz",
"de_head_0007_2019-18.txt.gz",
"de_head_0007_2019-47.txt.gz",
"de_head_0007_2020-10.txt.gz",
]]
# TOOD add file names and convert and upload all of them
_URL_MIDDLE = [REPO_URL + file_name for file_name in [
]]
class GermanCommonCrawl(datasets.GeneratorBasedBuilder):
"""TODO: Short description of my dataset."""
VERSION = datasets.Version("1.1.0")
BUILDER_CONFIGS = [
datasets.BuilderConfig(name="first", version=VERSION, description="Only the first data file"),
datasets.BuilderConfig(name="head", version=VERSION, description=""), #TODO fill description
datasets.BuilderConfig(name="middle", version=VERSION, description=""), #TODO fill description
datasets.BuilderConfig(name="all", version=VERSION, description=""), #TODO fill description
]
def _info(self):
features = datasets.Features(
{
"url": datasets.Value("string"),
"date_download": datasets.Value("string"),
"digest": datasets.Value("string"),
"length": datasets.Value("int32"),
"nlines": datasets.Value("int32"),
"source_domain": datasets.Value("string"),
"title": datasets.Value("string"),
"raw_content": datasets.Value("string"),
"cc_segment": datasets.Value("string"),
"original_nlines": datasets.Value("int32"),
"original_length": datasets.Value("int32"),
"language": datasets.Value("string"),
"language_score": datasets.Value("int32"),
"perplexity": datasets.Value("int32"),
"bucket": datasets.Value("string"),
}
)
return datasets.DatasetInfo(
# This is the description that will appear on the datasets page.
description=_DESCRIPTION,
# This defines the different columns of the dataset and their types
features=features, # Here we define them above because they are different between the two configurations
# If there's a common (input, txtget) tuple from the features,
# specify them here. They'll be used if as_supervised=True in
# builder.as_dataset.
supervised_keys=None,
# Citation for the dataset
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
if self.config.name == "first":
data_files = dl_manager.download(_URL_FIRST)
elif self.config.name == "head":
data_files = dl_manager.download(_URL_HEAD)
elif self.config.name == "middle":
data_files = dl_manager.download(_URL_MIDDLE)
else:
data_files = dl_manager.download(_URL_HEAD + _URL_MIDDLE)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"data_files": data_files,
},
),
]
def _generate_examples(self, data_files):
"""This function returns the examples in the raw (text) form by iterating on all the files."""
for filepath in data_files:
with open(filepath, "rt", encoding="utf-8") as f:
# with gzip.open(filepath, "rt", encoding="utf-8") as f:
for id_, line in enumerate(f):
item = literal_eval(line)
yield id_, {
"url": item["url"],
"date_download": item["date_download"],
"digest": item["digest"],
"length": item["length"],
"nlines": item["nlines"],
"source_domain": item["source_domain"],
"title": item["title"],
"raw_content": item["raw_content"],
"cc_segment": item["cc_segment"],
"original_nlines": item["original_nlines"],
"original_length": item["original_length"],
"language": item["language"],
"language_score": item["language_score"],
"perplexity": item["perplexity"],
"bucket": item["bucket"],
}
|