Maurice Weber
commited on
Commit
·
357d568
1
Parent(s):
d929e00
add sample code
Browse files- RedPajama-Data-V2.py +86 -32
- sample/sample_listings.txt +100 -0
RedPajama-Data-V2.py
CHANGED
@@ -36,7 +36,7 @@ with open("_QUALITY_SIGNAL_TAGS", "r") as f:
|
|
36 |
|
37 |
_URL_BASE = 'https://data.together.xyz/redpajama-data-v2/v1.0.0'
|
38 |
_LANGUAGES = ("en", "de", "fr", "es", "it")
|
39 |
-
|
40 |
|
41 |
_LISTINGS_PATTERN = "urls/{language}-{snapshot}-{partition}.txt"
|
42 |
|
@@ -55,7 +55,25 @@ class RedPajamaDataV2Config(datasets.BuilderConfig):
|
|
55 |
self.language = language
|
56 |
|
57 |
|
58 |
-
_BUILDER_CONFIGS = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
for lang in _LANGUAGES:
|
61 |
_BUILDER_CONFIGS.extend(
|
@@ -141,7 +159,41 @@ class RedPajamaV2(datasets.GeneratorBasedBuilder):
|
|
141 |
supervised_keys=None,
|
142 |
)
|
143 |
|
144 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
url_lists = dl_manager.download_and_extract({
|
146 |
snapshot_id: _LISTINGS_PATTERN.format(
|
147 |
language=self.config.language,
|
@@ -157,40 +209,35 @@ class RedPajamaV2(datasets.GeneratorBasedBuilder):
|
|
157 |
with open(listings_file, encoding="utf-8") as f:
|
158 |
listings_ids[snapshot_id] = [line.strip() for line in f]
|
159 |
|
160 |
-
#
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
snapshot_id: [
|
168 |
-
os.path.join(
|
|
|
|
|
|
|
169 |
for lst_id in listings_ids[snapshot_id]
|
170 |
]
|
171 |
for snapshot_id in self.config.snapshots
|
172 |
}
|
173 |
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
snapshot_id: [
|
180 |
-
os.path.join(
|
181 |
-
_URL_BASE,
|
182 |
-
f"quality_signals/{lst_id}.signals.json.gz"
|
183 |
-
)
|
184 |
-
for lst_id in listings_ids[snapshot_id]
|
185 |
-
]
|
186 |
-
for snapshot_id in self.config.snapshots
|
187 |
-
}
|
188 |
-
|
189 |
-
quality_signals_files = dl_manager.download(
|
190 |
-
quality_signals_urls
|
191 |
-
)
|
192 |
-
else:
|
193 |
-
quality_signals_files = {}
|
194 |
|
195 |
return [
|
196 |
datasets.SplitGenerator(
|
@@ -208,6 +255,12 @@ class RedPajamaV2(datasets.GeneratorBasedBuilder):
|
|
208 |
)
|
209 |
]
|
210 |
|
|
|
|
|
|
|
|
|
|
|
|
|
211 |
def _generate_examples(self, documents_files, quality_signals_files):
|
212 |
""" This function returns examples """
|
213 |
snapshots = list(documents_files.keys())
|
@@ -215,7 +268,7 @@ class RedPajamaV2(datasets.GeneratorBasedBuilder):
|
|
215 |
key = 0
|
216 |
for snapshot in snapshots:
|
217 |
docs_files = documents_files[snapshot]
|
218 |
-
if self.config.partition
|
219 |
qs_files = quality_signals_files[snapshot]
|
220 |
else:
|
221 |
qs_files = None
|
@@ -234,6 +287,7 @@ class RedPajamaV2(datasets.GeneratorBasedBuilder):
|
|
234 |
|
235 |
meta = {
|
236 |
"url": doc["url"],
|
|
|
237 |
"source_domain": doc["source_domain"],
|
238 |
"date_download": doc["date_download"],
|
239 |
"digest": doc["digest"],
|
|
|
36 |
|
37 |
_URL_BASE = 'https://data.together.xyz/redpajama-data-v2/v1.0.0'
|
38 |
_LANGUAGES = ("en", "de", "fr", "es", "it")
|
39 |
+
_SAMPLE_SNAPSHOT_ID = "2023-06"
|
40 |
|
41 |
_LISTINGS_PATTERN = "urls/{language}-{snapshot}-{partition}.txt"
|
42 |
|
|
|
55 |
self.language = language
|
56 |
|
57 |
|
58 |
+
_BUILDER_CONFIGS = [
|
59 |
+
RedPajamaDataV2Config(
|
60 |
+
name=f'_sample',
|
61 |
+
partition='sample',
|
62 |
+
snapshots=None,
|
63 |
+
language=None,
|
64 |
+
version=datasets.Version("1.0.0", ""),
|
65 |
+
description=f"RedPajamaV2 Sample",
|
66 |
+
),
|
67 |
+
# this one is just an alias for the sample
|
68 |
+
RedPajamaDataV2Config(
|
69 |
+
name=f'sample',
|
70 |
+
partition='sample',
|
71 |
+
snapshots=None,
|
72 |
+
language=None,
|
73 |
+
version=datasets.Version("1.0.0", ""),
|
74 |
+
description=f"RedPajamaV2 Sample",
|
75 |
+
)
|
76 |
+
]
|
77 |
|
78 |
for lang in _LANGUAGES:
|
79 |
_BUILDER_CONFIGS.extend(
|
|
|
159 |
supervised_keys=None,
|
160 |
)
|
161 |
|
162 |
+
def _split_generators_sample(self, dl_manager):
|
163 |
+
# fetch documents
|
164 |
+
with open("sample/sample_listings.txt", "r") as fd:
|
165 |
+
listings = [line.strip() for line in fd]
|
166 |
+
|
167 |
+
# fetch documents
|
168 |
+
docs_files = dl_manager.download({
|
169 |
+
_SAMPLE_SNAPSHOT_ID: [
|
170 |
+
f"sample/documents/{lst}.json.gz" for lst in listings
|
171 |
+
]
|
172 |
+
})
|
173 |
+
|
174 |
+
# fetch quality signals
|
175 |
+
signals_files = dl_manager.download({
|
176 |
+
_SAMPLE_SNAPSHOT_ID: [
|
177 |
+
f"sample/quality_signals/{lst}.signals.json.gz"
|
178 |
+
for lst in listings
|
179 |
+
]
|
180 |
+
})
|
181 |
+
|
182 |
+
return [
|
183 |
+
datasets.SplitGenerator(
|
184 |
+
name=datasets.Split.TRAIN,
|
185 |
+
gen_kwargs={
|
186 |
+
"documents_files": {
|
187 |
+
_SAMPLE_SNAPSHOT_ID: docs_files[_SAMPLE_SNAPSHOT_ID]
|
188 |
+
},
|
189 |
+
"quality_signals_files": {
|
190 |
+
_SAMPLE_SNAPSHOT_ID: signals_files[_SAMPLE_SNAPSHOT_ID]
|
191 |
+
}
|
192 |
+
}
|
193 |
+
)
|
194 |
+
]
|
195 |
+
|
196 |
+
def _split_generators_full(self, dl_manager):
|
197 |
url_lists = dl_manager.download_and_extract({
|
198 |
snapshot_id: _LISTINGS_PATTERN.format(
|
199 |
language=self.config.language,
|
|
|
209 |
with open(listings_file, encoding="utf-8") as f:
|
210 |
listings_ids[snapshot_id] = [line.strip() for line in f]
|
211 |
|
212 |
+
# build urls pointing to documents
|
213 |
+
document_urls = {
|
214 |
+
snapshot_id: [
|
215 |
+
os.path.join(_URL_BASE, f"documents/{lst_id}.json.gz")
|
216 |
+
for lst_id in listings_ids[snapshot_id]
|
217 |
+
]
|
218 |
+
for snapshot_id in self.config.snapshots
|
219 |
+
}
|
220 |
+
|
221 |
+
documents_files = dl_manager.download(document_urls)
|
222 |
+
|
223 |
+
# build urls pointing to quality signals
|
224 |
+
if self.config.partition == "head_middle":
|
225 |
+
quality_signals_urls = {
|
226 |
snapshot_id: [
|
227 |
+
os.path.join(
|
228 |
+
_URL_BASE,
|
229 |
+
f"quality_signals/{lst_id}.signals.json.gz"
|
230 |
+
)
|
231 |
for lst_id in listings_ids[snapshot_id]
|
232 |
]
|
233 |
for snapshot_id in self.config.snapshots
|
234 |
}
|
235 |
|
236 |
+
quality_signals_files = dl_manager.download(
|
237 |
+
quality_signals_urls
|
238 |
+
)
|
239 |
+
else:
|
240 |
+
quality_signals_files = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
241 |
|
242 |
return [
|
243 |
datasets.SplitGenerator(
|
|
|
255 |
)
|
256 |
]
|
257 |
|
258 |
+
def _split_generators(self, dl_manager):
|
259 |
+
if self.config.name == "sample":
|
260 |
+
return self._split_generators_sample(dl_manager)
|
261 |
+
|
262 |
+
return self._split_generators_full(dl_manager)
|
263 |
+
|
264 |
def _generate_examples(self, documents_files, quality_signals_files):
|
265 |
""" This function returns examples """
|
266 |
snapshots = list(documents_files.keys())
|
|
|
268 |
key = 0
|
269 |
for snapshot in snapshots:
|
270 |
docs_files = documents_files[snapshot]
|
271 |
+
if self.config.partition in ("head_middle", "sample"):
|
272 |
qs_files = quality_signals_files[snapshot]
|
273 |
else:
|
274 |
qs_files = None
|
|
|
287 |
|
288 |
meta = {
|
289 |
"url": doc["url"],
|
290 |
+
"language": doc["language"],
|
291 |
"source_domain": doc["source_domain"],
|
292 |
"date_download": doc["date_download"],
|
293 |
"digest": doc["digest"],
|
sample/sample_listings.txt
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
documents/2023-06/0003/es_middle
|
2 |
+
documents/2023-06/0003/de_head
|
3 |
+
documents/2023-06/0003/fr_head
|
4 |
+
documents/2023-06/0003/es_head
|
5 |
+
documents/2023-06/0003/fr_middle
|
6 |
+
documents/2023-06/0003/en_head
|
7 |
+
documents/2023-06/0003/it_middle
|
8 |
+
documents/2023-06/0003/en_middle
|
9 |
+
documents/2023-06/0003/it_head
|
10 |
+
documents/2023-06/0003/de_middle
|
11 |
+
documents/2023-06/0004/es_middle
|
12 |
+
documents/2023-06/0004/de_head
|
13 |
+
documents/2023-06/0004/fr_head
|
14 |
+
documents/2023-06/0004/es_head
|
15 |
+
documents/2023-06/0004/fr_middle
|
16 |
+
documents/2023-06/0004/en_head
|
17 |
+
documents/2023-06/0004/it_middle
|
18 |
+
documents/2023-06/0004/en_middle
|
19 |
+
documents/2023-06/0004/it_head
|
20 |
+
documents/2023-06/0004/de_middle
|
21 |
+
documents/2023-06/0005/es_middle
|
22 |
+
documents/2023-06/0005/de_head
|
23 |
+
documents/2023-06/0005/fr_head
|
24 |
+
documents/2023-06/0005/es_head
|
25 |
+
documents/2023-06/0005/fr_middle
|
26 |
+
documents/2023-06/0005/en_head
|
27 |
+
documents/2023-06/0005/it_middle
|
28 |
+
documents/2023-06/0005/en_middle
|
29 |
+
documents/2023-06/0005/it_head
|
30 |
+
documents/2023-06/0005/de_middle
|
31 |
+
documents/2023-06/0002/es_middle
|
32 |
+
documents/2023-06/0002/de_head
|
33 |
+
documents/2023-06/0002/fr_head
|
34 |
+
documents/2023-06/0002/es_head
|
35 |
+
documents/2023-06/0002/fr_middle
|
36 |
+
documents/2023-06/0002/en_head
|
37 |
+
documents/2023-06/0002/it_middle
|
38 |
+
documents/2023-06/0002/en_middle
|
39 |
+
documents/2023-06/0002/it_head
|
40 |
+
documents/2023-06/0002/de_middle
|
41 |
+
documents/2023-06/0007/es_middle
|
42 |
+
documents/2023-06/0007/de_head
|
43 |
+
documents/2023-06/0007/fr_head
|
44 |
+
documents/2023-06/0007/es_head
|
45 |
+
documents/2023-06/0007/fr_middle
|
46 |
+
documents/2023-06/0007/en_head
|
47 |
+
documents/2023-06/0007/it_middle
|
48 |
+
documents/2023-06/0007/en_middle
|
49 |
+
documents/2023-06/0007/it_head
|
50 |
+
documents/2023-06/0007/de_middle
|
51 |
+
documents/2023-06/0000/es_middle
|
52 |
+
documents/2023-06/0000/de_head
|
53 |
+
documents/2023-06/0000/fr_head
|
54 |
+
documents/2023-06/0000/es_head
|
55 |
+
documents/2023-06/0000/fr_middle
|
56 |
+
documents/2023-06/0000/en_head
|
57 |
+
documents/2023-06/0000/it_middle
|
58 |
+
documents/2023-06/0000/en_middle
|
59 |
+
documents/2023-06/0000/it_head
|
60 |
+
documents/2023-06/0000/de_middle
|
61 |
+
documents/2023-06/0009/es_middle
|
62 |
+
documents/2023-06/0009/de_head
|
63 |
+
documents/2023-06/0009/fr_head
|
64 |
+
documents/2023-06/0009/es_head
|
65 |
+
documents/2023-06/0009/fr_middle
|
66 |
+
documents/2023-06/0009/en_head
|
67 |
+
documents/2023-06/0009/it_middle
|
68 |
+
documents/2023-06/0009/en_middle
|
69 |
+
documents/2023-06/0009/it_head
|
70 |
+
documents/2023-06/0009/de_middle
|
71 |
+
documents/2023-06/0008/es_middle
|
72 |
+
documents/2023-06/0008/de_head
|
73 |
+
documents/2023-06/0008/fr_head
|
74 |
+
documents/2023-06/0008/es_head
|
75 |
+
documents/2023-06/0008/fr_middle
|
76 |
+
documents/2023-06/0008/en_head
|
77 |
+
documents/2023-06/0008/it_middle
|
78 |
+
documents/2023-06/0008/en_middle
|
79 |
+
documents/2023-06/0008/it_head
|
80 |
+
documents/2023-06/0008/de_middle
|
81 |
+
documents/2023-06/0001/es_middle
|
82 |
+
documents/2023-06/0001/de_head
|
83 |
+
documents/2023-06/0001/fr_head
|
84 |
+
documents/2023-06/0001/es_head
|
85 |
+
documents/2023-06/0001/fr_middle
|
86 |
+
documents/2023-06/0001/en_head
|
87 |
+
documents/2023-06/0001/it_middle
|
88 |
+
documents/2023-06/0001/en_middle
|
89 |
+
documents/2023-06/0001/it_head
|
90 |
+
documents/2023-06/0001/de_middle
|
91 |
+
documents/2023-06/0006/es_middle
|
92 |
+
documents/2023-06/0006/de_head
|
93 |
+
documents/2023-06/0006/fr_head
|
94 |
+
documents/2023-06/0006/es_head
|
95 |
+
documents/2023-06/0006/fr_middle
|
96 |
+
documents/2023-06/0006/en_head
|
97 |
+
documents/2023-06/0006/it_middle
|
98 |
+
documents/2023-06/0006/en_middle
|
99 |
+
documents/2023-06/0006/it_head
|
100 |
+
documents/2023-06/0006/de_middle
|