patrickvonplaten
commited on
Commit
•
30d835f
1
Parent(s):
d617661
update
Browse files- convert_file.sh +11 -0
- de_head_0000_2015-48.txt.gz +2 -2
- german_common_crawl.py +151 -166
- german_common_crawl.py.lock +0 -0
- write_to_filtered_file.py +25 -0
convert_file.sh
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env bash
|
2 |
+
file_name=${1}
|
3 |
+
|
4 |
+
local_file_name=$(echo "${file_name}" | cut -f8 -d/)
|
5 |
+
bare_local_file_name=$(echo "${local_file_name}" | cut -f1 -d.)
|
6 |
+
|
7 |
+
wget ${file_name}
|
8 |
+
|
9 |
+
./write_to_filtered_file.py ${local_file_name}
|
10 |
+
|
11 |
+
gzip -c "${bare_local_file_name}.txt" > "${bare_local_file_name}.txt.gz"
|
de_head_0000_2015-48.txt.gz
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f81d28cbb4c1bfaa26699540c498edaf56ca642cb74d3cd5aaad44b71ce53650
|
3 |
+
size 1066575032
|
german_common_crawl.py
CHANGED
@@ -15,10 +15,10 @@
|
|
15 |
"""German Common Crawl"""
|
16 |
|
17 |
from __future__ import absolute_import, division, print_function
|
18 |
-
|
19 |
-
import os
|
20 |
-
|
21 |
import datasets
|
|
|
|
|
|
|
22 |
|
23 |
|
24 |
# Find for instance the citation on arxiv or on the dataset repo/website
|
@@ -38,114 +38,116 @@ German Only Extract from Common Crawl
|
|
38 |
This Dataset is for pretraining a German Language Model (Unsupervised) or tune a Multilingual Model specifically to German
|
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 |
class GermanCommonCrawl(datasets.GeneratorBasedBuilder):
|
151 |
"""TODO: Short description of my dataset."""
|
@@ -161,33 +163,25 @@ class GermanCommonCrawl(datasets.GeneratorBasedBuilder):
|
|
161 |
]
|
162 |
|
163 |
def _info(self):
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
"original_nlines": datasets.Value("int32"),
|
184 |
-
"original_length": datasets.Value("int32"),
|
185 |
-
"language": datasets.Value("string"),
|
186 |
-
"perplexity": datasets.Value("int32"),
|
187 |
-
"bucket": datasets.Value("int32"),
|
188 |
-
|
189 |
-
}
|
190 |
-
)
|
191 |
return datasets.DatasetInfo(
|
192 |
# This is the description that will appear on the datasets page.
|
193 |
description=_DESCRIPTION,
|
@@ -203,41 +197,32 @@ class GermanCommonCrawl(datasets.GeneratorBasedBuilder):
|
|
203 |
|
204 |
def _split_generators(self, dl_manager):
|
205 |
"""Returns SplitGenerators."""
|
206 |
-
if self.config.name == "
|
207 |
-
|
208 |
else:
|
209 |
-
raise NotImplementedError("just `
|
210 |
|
211 |
-
import ipdb; ipdb.set_trace()
|
212 |
return [
|
213 |
datasets.SplitGenerator(
|
214 |
name=datasets.Split.TRAIN,
|
215 |
-
# These kwargs will be passed to _generate_examples
|
216 |
gen_kwargs={
|
217 |
-
"
|
218 |
-
"split": "train",
|
219 |
},
|
220 |
),
|
221 |
]
|
222 |
|
223 |
-
def _generate_examples(self,
|
224 |
-
"""
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
if self.config.name == "data_only":
|
239 |
-
yield id_, {
|
240 |
-
"raw_content": data["raw_content"],
|
241 |
-
}
|
242 |
-
else:
|
243 |
-
yield id_, data
|
|
|
15 |
"""German Common Crawl"""
|
16 |
|
17 |
from __future__ import absolute_import, division, print_function
|
|
|
|
|
|
|
18 |
import datasets
|
19 |
+
import itertools
|
20 |
+
import gzip
|
21 |
+
from ast import literal_eval
|
22 |
|
23 |
|
24 |
# Find for instance the citation on arxiv or on the dataset repo/website
|
|
|
38 |
This Dataset is for pretraining a German Language Model (Unsupervised) or tune a Multilingual Model specifically to German
|
39 |
"""
|
40 |
|
41 |
+
REPO_URL = "https://huggingface.co/datasets/flax-community/german_common_crawl/resolve/main/"
|
42 |
+
|
43 |
+
_URL_FIRST = [REPO_URL + file_name for file_name in [
|
44 |
+
"de_head_0000_2015-48.txt.gz",
|
45 |
+
]]
|
46 |
+
|
47 |
+
_URL_HEAD = [REPO_URL + file_name for file_name in [
|
48 |
+
"de_head_0000_2015-48.txt.gz",
|
49 |
+
# "de_head_0000_2016-18.txt.gz",
|
50 |
+
# "de_head_0000_2016-44.txt.gz",
|
51 |
+
# "de_head_0000_2017-13.txt.gz",
|
52 |
+
# "de_head_0000_2017-30.txt.gz",
|
53 |
+
# "de_head_0000_2017-39.txt.gz",
|
54 |
+
# "de_head_0000_2017-51.txt.gz",
|
55 |
+
# "de_head_0000_2018-09.txt.gz",
|
56 |
+
# "de_head_0000_2018-17.txt.gz",
|
57 |
+
# "de_head_0000_2018-30.txt.gz",
|
58 |
+
# "de_head_0000_2018-39.txt.gz",
|
59 |
+
# "de_head_0000_2018-51.txt.gz",
|
60 |
+
# "de_head_0000_2019-18.txt.gz",
|
61 |
+
# "de_head_0000_2019-30.txt.gz",
|
62 |
+
# "de_head_0000_2019-47.txt.gz",
|
63 |
+
# "de_head_0000_2020-10.txt.gz",
|
64 |
+
# "de_head_0001_2016-44.txt.gz",
|
65 |
+
# "de_head_0001_2017-13.txt.gz",
|
66 |
+
# "de_head_0001_2017-30.txt.gz",
|
67 |
+
# "de_head_0001_2017-39.txt.gz",
|
68 |
+
# "de_head_0001_2017-51.txt.gz",
|
69 |
+
# "de_head_0001_2018-09.txt.gz",
|
70 |
+
# "de_head_0001_2018-17.txt.gz",
|
71 |
+
# "de_head_0001_2018-30.txt.gz",
|
72 |
+
# "de_head_0001_2018-39.txt.gz",
|
73 |
+
# "de_head_0001_2018-51.txt.gz",
|
74 |
+
# "de_head_0001_2019-09.txt.gz",
|
75 |
+
# "de_head_0001_2019-18.txt.gz",
|
76 |
+
# "de_head_0001_2019-30.txt.gz",
|
77 |
+
# "de_head_0001_2019-47.txt.gz",
|
78 |
+
# "de_head_0001_2020-10.txt.gz",
|
79 |
+
# "de_head_0002_2016-44.txt.gz",
|
80 |
+
# "de_head_0002_2017-13.txt.gz",
|
81 |
+
# "de_head_0002_2017-30.txt.gz",
|
82 |
+
# "de_head_0002_2017-39.txt.gz",
|
83 |
+
# "de_head_0002_2017-51.txt.gz",
|
84 |
+
# "de_head_0002_2018-09.txt.gz",
|
85 |
+
# "de_head_0002_2018-17.txt.gz",
|
86 |
+
# "de_head_0002_2018-30.txt.gz",
|
87 |
+
# "de_head_0002_2018-39.txt.gz",
|
88 |
+
# "de_head_0002_2018-51.txt.gz",
|
89 |
+
# "de_head_0002_2019-09.txt.gz",
|
90 |
+
# "de_head_0002_2019-18.txt.gz",
|
91 |
+
# "de_head_0002_2019-30.txt.gz",
|
92 |
+
# "de_head_0002_2019-47.txt.gz",
|
93 |
+
# "de_head_0002_2020-10.txt.gz",
|
94 |
+
# "de_head_0003_2016-44.txt.gz",
|
95 |
+
# "de_head_0003_2017-13.txt.gz",
|
96 |
+
# "de_head_0003_2017-30.txt.gz",
|
97 |
+
# "de_head_0003_2017-39.txt.gz",
|
98 |
+
# "de_head_0003_2017-51.txt.gz",
|
99 |
+
# "de_head_0003_2018-09.txt.gz",
|
100 |
+
# "de_head_0003_2018-17.txt.gz",
|
101 |
+
# "de_head_0003_2018-30.txt.gz",
|
102 |
+
# "de_head_0003_2018-39.txt.gz",
|
103 |
+
# "de_head_0003_2018-51.txt.gz",
|
104 |
+
# "de_head_0003_2019-09.txt.gz",
|
105 |
+
# "de_head_0003_2019-18.txt.gz",
|
106 |
+
# "de_head_0003_2019-30.txt.gz",
|
107 |
+
# "de_head_0003_2019-47.txt.gz",
|
108 |
+
# "de_head_0003_2020-10.txt.gz",
|
109 |
+
# "de_head_0004_2016-44.txt.gz",
|
110 |
+
# "de_head_0004_2017-30.txt.gz",
|
111 |
+
# "de_head_0004_2017-39.txt.gz",
|
112 |
+
# "de_head_0004_2017-51.txt.gz",
|
113 |
+
# "de_head_0004_2018-09.txt.gz",
|
114 |
+
# "de_head_0004_2018-17.txt.gz",
|
115 |
+
# "de_head_0004_2018-30.txt.gz",
|
116 |
+
# "de_head_0004_2018-39.txt.gz",
|
117 |
+
# "de_head_0004_2018-51.txt.gz",
|
118 |
+
# "de_head_0004_2019-09.txt.gz",
|
119 |
+
# "de_head_0004_2019-18.txt.gz",
|
120 |
+
# "de_head_0004_2019-30.txt.gz",
|
121 |
+
# "de_head_0004_2019-47.txt.gz",
|
122 |
+
# "de_head_0004_2020-10.txt.gz",
|
123 |
+
# "de_head_0005_2017-51.txt.gz",
|
124 |
+
# "de_head_0005_2018-09.txt.gz",
|
125 |
+
# "de_head_0005_2018-17.txt.gz",
|
126 |
+
# "de_head_0005_2018-30.txt.gz",
|
127 |
+
# "de_head_0005_2018-39.txt.gz",
|
128 |
+
# "de_head_0005_2018-51.txt.gz",
|
129 |
+
# "de_head_0005_2019-09.txt.gz",
|
130 |
+
# "de_head_0005_2019-18.txt.gz",
|
131 |
+
# "de_head_0005_2019-30.txt.gz",
|
132 |
+
# "de_head_0005_2019-47.txt.gz",
|
133 |
+
# "de_head_0005_2020-10.txt.gz",
|
134 |
+
# "de_head_0006_2018-09.txt.gz",
|
135 |
+
# "de_head_0006_2018-17.txt.gz",
|
136 |
+
# "de_head_0006_2018-30.txt.gz",
|
137 |
+
# "de_head_0006_2018-39.txt.gz",
|
138 |
+
# "de_head_0006_2018-51.txt.gz",
|
139 |
+
# "de_head_0006_2019-09.txt.gz",
|
140 |
+
# "de_head_0006_2019-18.txt.gz",
|
141 |
+
# "de_head_0006_2019-30.txt.gz",
|
142 |
+
# "de_head_0006_2019-47.txt.gz",
|
143 |
+
# "de_head_0006_2020-10.txt.gz",
|
144 |
+
# "de_head_0007_2018-30.txt.gz",
|
145 |
+
# "de_head_0007_2018-51.txt.gz",
|
146 |
+
# "de_head_0007_2019-09.txt.gz",
|
147 |
+
# "de_head_0007_2019-18.txt.gz",
|
148 |
+
# "de_head_0007_2019-47.txt.gz",
|
149 |
+
# "de_head_0007_2020-10.txt.gz",
|
150 |
+
]]
|
151 |
|
152 |
class GermanCommonCrawl(datasets.GeneratorBasedBuilder):
|
153 |
"""TODO: Short description of my dataset."""
|
|
|
163 |
]
|
164 |
|
165 |
def _info(self):
|
166 |
+
features = datasets.Features(
|
167 |
+
{
|
168 |
+
"url": datasets.Value("string"),
|
169 |
+
"date_download": datasets.Value("string"),
|
170 |
+
"digest": datasets.Value("string"),
|
171 |
+
"length": datasets.Value("int32"),
|
172 |
+
"nlines": datasets.Value("int32"),
|
173 |
+
"source_domain": datasets.Value("string"),
|
174 |
+
"title": datasets.Value("string"),
|
175 |
+
"raw_content": datasets.Value("string"),
|
176 |
+
"cc_segment": datasets.Value("string"),
|
177 |
+
"original_nlines": datasets.Value("int32"),
|
178 |
+
"original_length": datasets.Value("int32"),
|
179 |
+
"language": datasets.Value("string"),
|
180 |
+
"language_score": datasets.Value("int32"),
|
181 |
+
"perplexity": datasets.Value("int32"),
|
182 |
+
"bucket": datasets.Value("string"),
|
183 |
+
}
|
184 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
185 |
return datasets.DatasetInfo(
|
186 |
# This is the description that will appear on the datasets page.
|
187 |
description=_DESCRIPTION,
|
|
|
197 |
|
198 |
def _split_generators(self, dl_manager):
|
199 |
"""Returns SplitGenerators."""
|
200 |
+
if self.config.name == "first":
|
201 |
+
data_files = dl_manager.download(_URL_FIRST)
|
202 |
else:
|
203 |
+
raise NotImplementedError("just `first` works for now")
|
204 |
|
|
|
205 |
return [
|
206 |
datasets.SplitGenerator(
|
207 |
name=datasets.Split.TRAIN,
|
|
|
208 |
gen_kwargs={
|
209 |
+
"data_files": data_files,
|
|
|
210 |
},
|
211 |
),
|
212 |
]
|
213 |
|
214 |
+
def _generate_examples(self, data_files):
|
215 |
+
"""This function returns the examples in the raw (text) form by iterating on all the files."""
|
216 |
+
for filepath in data_files:
|
217 |
+
with gzip.open(filepath, "rt", encoding="utf-8") as f:
|
218 |
+
for id_, line in enumerate(f):
|
219 |
+
item = literal_eval(line)
|
220 |
+
import ipdb; ipdb.set_trace()
|
221 |
+
yield id_, {
|
222 |
+
|
223 |
+
|
224 |
+
|
225 |
+
|
226 |
+
|
227 |
+
|
228 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
german_common_crawl.py.lock
ADDED
File without changes
|
write_to_filtered_file.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
import gzip
|
3 |
+
from ast import literal_eval
|
4 |
+
from tqdm import tqdm
|
5 |
+
import sys
|
6 |
+
|
7 |
+
if __name__ == '__main__':
|
8 |
+
file_name = sys.argv[1]
|
9 |
+
new_file_name = ".".join(file_name.split(".")[:1] + ["txt"])
|
10 |
+
with gzip.open(file_name, 'rt') as f:
|
11 |
+
a = f.readline()
|
12 |
+
a = a.split("{'url'")
|
13 |
+
a = [("{'url'" + item) for item in a]
|
14 |
+
|
15 |
+
b = []
|
16 |
+
for item in tqdm(a):
|
17 |
+
try:
|
18 |
+
if literal_eval(item)['language_score'] > 0.98:
|
19 |
+
b.append(item)
|
20 |
+
except:
|
21 |
+
None
|
22 |
+
|
23 |
+
with open(new_file_name, 'wt') as file_new:
|
24 |
+
for part in b:
|
25 |
+
file_new.write(part + '\n')
|