Spaces:
Sleeping
Sleeping
victormiller
commited on
Commit
•
8813482
1
Parent(s):
6f3b8c9
Update web.py
Browse files
web.py
CHANGED
@@ -1,5 +1,168 @@
|
|
1 |
from fasthtml.common import *
|
2 |
from fasthtml.components import *
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
|
5 |
def web_data():
|
@@ -21,10 +184,9 @@ def web_data():
|
|
21 |
),
|
22 |
style="""
|
23 |
background-color: #d4edda; /* Light green background */
|
24 |
-
padding: 15px;
|
25 |
border: 1px solid #c3e6cb; /* Green border */
|
26 |
border-radius: 5px;
|
27 |
-
|
28 |
""",
|
29 |
),
|
30 |
Div(
|
@@ -35,4 +197,405 @@ def web_data():
|
|
35 |
),
|
36 |
style="margin-top: 20px;",
|
37 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
)
|
|
|
|
1 |
from fasthtml.common import *
|
2 |
from fasthtml.components import *
|
3 |
+
import json
|
4 |
+
import random
|
5 |
+
import string
|
6 |
+
from rich import print
|
7 |
+
import jsonlines
|
8 |
+
from data.url_blocklist import urls_high_matches, urls_false_positives
|
9 |
+
from data.non_web_urls import non_web_urls
|
10 |
+
|
11 |
+
|
12 |
+
def DVS(
|
13 |
+
left,
|
14 |
+
header,
|
15 |
+
):
|
16 |
+
col1 = Div(
|
17 |
+
Pre(
|
18 |
+
json.dumps(left, indent=4, ensure_ascii=False),
|
19 |
+
style="white-space: pre-wrap; word-break: break-all;",
|
20 |
+
),
|
21 |
+
style="float: left; overflow-x: auto;",
|
22 |
+
)
|
23 |
+
|
24 |
+
data_display = Div(
|
25 |
+
col1,
|
26 |
+
style="overflow: auto; clear: both; height: 200px; border: 1px solid #ccc; padding: 20px;",
|
27 |
+
)
|
28 |
+
return Div(H3(header), data_display, style="margin-top: 10px;")
|
29 |
+
|
30 |
+
|
31 |
+
def DV(
|
32 |
+
left_file,
|
33 |
+
doc_id,
|
34 |
+
header,
|
35 |
+
target: str = None,
|
36 |
+
):
|
37 |
+
if target is None:
|
38 |
+
target = "".join(random.choices(string.ascii_lowercase, k=8))
|
39 |
+
|
40 |
+
if left_file.endswith("jsonl"):
|
41 |
+
left = [x for x in jsonlines.open(left_file)]
|
42 |
+
else:
|
43 |
+
left = json.load(open(left_file, encoding="utf-8"))
|
44 |
+
max_doc_id = len(left) - 1
|
45 |
+
slider = Input(
|
46 |
+
type="range",
|
47 |
+
name=f"doc_id_{target}",
|
48 |
+
min="0",
|
49 |
+
max=str(max_doc_id),
|
50 |
+
value=str(doc_id),
|
51 |
+
hx_get=f"/webdata/{target}",
|
52 |
+
hx_target=f"#{target}",
|
53 |
+
hx_trigger="change",
|
54 |
+
hx_swap="innerHTML",
|
55 |
+
hx_vals=json.dumps({"left_file": f"{left_file}", "header": f"{header}"}),
|
56 |
+
)
|
57 |
+
|
58 |
+
form = Div(
|
59 |
+
H3(header),
|
60 |
+
Label(
|
61 |
+
"Data sample: ", slider, f"{doc_id} of {max_doc_id}", cls="plotly_slider"
|
62 |
+
),
|
63 |
+
cls="plotly_input_container",
|
64 |
+
style="padding: 20px;",
|
65 |
+
)
|
66 |
+
|
67 |
+
col1 = Div(
|
68 |
+
Pre(
|
69 |
+
json.dumps(left[doc_id], indent=4, ensure_ascii=False),
|
70 |
+
style="white-space: pre-wrap; word-break: break-all;",
|
71 |
+
),
|
72 |
+
style="float: left; overflow-x: auto;",
|
73 |
+
)
|
74 |
+
|
75 |
+
data_display = Div(
|
76 |
+
col1,
|
77 |
+
style="overflow: auto; clear: both; height: 600px; border: 1px solid #ccc; padding: 20px;",
|
78 |
+
)
|
79 |
+
return Div(form, data_display, style="margin-top: 10px;", id=target)
|
80 |
+
|
81 |
+
|
82 |
+
def DV2(
|
83 |
+
left_file,
|
84 |
+
right_file,
|
85 |
+
doc_id,
|
86 |
+
target: str = None,
|
87 |
+
):
|
88 |
+
if target is None:
|
89 |
+
target = "".join(random.choices(string.ascii_lowercase, k=8))
|
90 |
+
|
91 |
+
left = json.load(open(left_file, encoding="utf-8"))
|
92 |
+
right = json.load(open(right_file, encoding="utf-8"))
|
93 |
+
max_doc_id = len(left) - 1
|
94 |
+
|
95 |
+
slider = Input(
|
96 |
+
type="range",
|
97 |
+
name=f"doc_id_{target}",
|
98 |
+
min="0",
|
99 |
+
max=str(max_doc_id),
|
100 |
+
value=str(doc_id),
|
101 |
+
hx_get=f"/webdata/{target}",
|
102 |
+
hx_target=f"#{target}",
|
103 |
+
hx_trigger="change",
|
104 |
+
hx_swap="innerHTML",
|
105 |
+
hx_vals=json.dumps(
|
106 |
+
{"left_file": f"{left_file}", "right_file": f"{right_file}"}
|
107 |
+
),
|
108 |
+
)
|
109 |
+
|
110 |
+
form = Div(
|
111 |
+
Label(
|
112 |
+
"Data sample: ", slider, f"{doc_id} of {max_doc_id}", cls="plotly_slider"
|
113 |
+
),
|
114 |
+
cls="plotly_input_container",
|
115 |
+
style="padding: 20px;",
|
116 |
+
)
|
117 |
+
|
118 |
+
col1 = Div(
|
119 |
+
H3("Raw format", style="margin-top: 0px;"),
|
120 |
+
Pre(
|
121 |
+
json.dumps(left[doc_id], indent=4, ensure_ascii=False),
|
122 |
+
style="white-space: pre-wrap; word-break: break-all;",
|
123 |
+
),
|
124 |
+
style="width: 48%; float: left; overflow-x: auto;",
|
125 |
+
)
|
126 |
+
|
127 |
+
col2 = Div(
|
128 |
+
H3("Extracted format", style="margin-top: 0px;"),
|
129 |
+
Pre(
|
130 |
+
json.dumps(right[doc_id], indent=4, ensure_ascii=False),
|
131 |
+
style="white-space: pre-wrap; word-break: break-all;",
|
132 |
+
),
|
133 |
+
style="width: 48%; float: right; overflow-x: auto;",
|
134 |
+
)
|
135 |
+
|
136 |
+
data_display = Div(
|
137 |
+
col1,
|
138 |
+
col2,
|
139 |
+
style="overflow: auto; clear: both; height: 600px; border: 1px solid #ccc; padding: 20px;",
|
140 |
+
)
|
141 |
+
return Div(form, data_display, style="margin-top: 10px;", id=target)
|
142 |
+
|
143 |
+
|
144 |
+
def update(target: str, request):
|
145 |
+
params = request.query_params
|
146 |
+
print(params)
|
147 |
+
doc_id = int(params.get(f"doc_id_{target}", 3))
|
148 |
+
left_file = params.get("left_file")
|
149 |
+
right_file = params.get("right_file")
|
150 |
+
if left_file and right_file:
|
151 |
+
return (
|
152 |
+
DV2(
|
153 |
+
left_file,
|
154 |
+
right_file,
|
155 |
+
doc_id,
|
156 |
+
target,
|
157 |
+
),
|
158 |
+
)
|
159 |
+
else:
|
160 |
+
return DV(
|
161 |
+
left_file,
|
162 |
+
doc_id,
|
163 |
+
params.get("header"),
|
164 |
+
target,
|
165 |
+
)
|
166 |
|
167 |
|
168 |
def web_data():
|
|
|
184 |
),
|
185 |
style="""
|
186 |
background-color: #d4edda; /* Light green background */
|
|
|
187 |
border: 1px solid #c3e6cb; /* Green border */
|
188 |
border-radius: 5px;
|
189 |
+
padding: 15px 15px 0px 15px;
|
190 |
""",
|
191 |
),
|
192 |
Div(
|
|
|
197 |
),
|
198 |
style="margin-top: 20px;",
|
199 |
),
|
200 |
+
H3("1. Document Preparation"),
|
201 |
+
H4("1.1 Text Extraction"),
|
202 |
+
P("""
|
203 |
+
Common Crawl provides webpage texts via two formats: WARC (Web ARChive format) and WET (WARC Encapsulated Text).
|
204 |
+
WARC files contain the raw data from the crawl, which store the full HTTP response and request metadata.
|
205 |
+
WET files contain plaintexts extracted by Common Crawl. In line with previous works ([1], [2], [3], [4]),
|
206 |
+
we found WET files to include boilerplate content like navigation menus, ads, and other irrelevant texts.
|
207 |
+
Accordingly, our pipeline starts from raw WARC files, reads with the warcio library, and extracts texts using trafilatura.
|
208 |
+
"""),
|
209 |
+
DV2("data/sample_wet.json", "data/sample_warc.json", 3),
|
210 |
+
H4("1.2 Language Identification"),
|
211 |
+
P("""
|
212 |
+
After text extraction, the non-English texts are then filtered out by fastText language identifier with a threshold of 0.65.
|
213 |
+
This step removes over 60% of the whole data.
|
214 |
+
"""),
|
215 |
+
DV(
|
216 |
+
"data/sample_non_en.json",
|
217 |
+
3,
|
218 |
+
"Sample documents that are classified as non-English",
|
219 |
+
),
|
220 |
+
DV(
|
221 |
+
"data/sample_en_low.json",
|
222 |
+
3,
|
223 |
+
"Sample documents that are classified as English but with score less than 0.65",
|
224 |
+
),
|
225 |
+
H4("1.3 URL Filtering"),
|
226 |
+
P("""
|
227 |
+
Following RefinedWeb [3], we use a manually inspected URL blocklist to filter fraudulent and/or adult websites.
|
228 |
+
We also exclude our high-quality curated data from it to avoid duplication.
|
229 |
+
"""),
|
230 |
+
H5("1.3.1 URL Blocklist"),
|
231 |
+
P("""
|
232 |
+
Following RefinedWeb [3], we applied manual inspection on the UT1 blocklist to reduce false positives like news
|
233 |
+
articles, sex education, technical blogs, etc. Specifically, we randomly took 903M URLs and matched them with
|
234 |
+
4.6M domain names in the UT1 blocklist. 24 URL domains were detected with more than 4k matches, which are shown below.
|
235 |
+
"""),
|
236 |
+
DVS(urls_high_matches, "24 URL domains with more than 4k matches"),
|
237 |
+
P("""
|
238 |
+
We manually removed the following 6 domains from the UT1 blocklist so that they will not be removed from our dataset.
|
239 |
+
"""),
|
240 |
+
DVS(urls_false_positives, "6 url domains that are removed from the blocklist"),
|
241 |
+
DV(
|
242 |
+
"data/bad_url_doc.jsonl",
|
243 |
+
3,
|
244 |
+
"Sample documents whose urls are blocked by the refined url blocklist",
|
245 |
+
),
|
246 |
+
H5("1.3.2 Excluded High Quality Sources"),
|
247 |
+
P("""
|
248 |
+
To avoid duplication with our high-quality curated datasets, we exclude the following domains from our dataset.
|
249 |
+
"""),
|
250 |
+
DVS(
|
251 |
+
non_web_urls,
|
252 |
+
"curated url domains that are excluded from our dataset",
|
253 |
+
),
|
254 |
+
DV(
|
255 |
+
"data/sample_url_exclusion.json",
|
256 |
+
0,
|
257 |
+
"Sample documents whose urls are in our curated url domain list",
|
258 |
+
),
|
259 |
+
H3("2. Line-Level Removal"),
|
260 |
+
P("""
|
261 |
+
Before computing the quality signals that can be used for filtering low-quality documents, we perform the line-level
|
262 |
+
removal to remove low-quality lines so that the final quality signals align with our final kept texts.
|
263 |
+
"""),
|
264 |
+
H4("Terminal Punctuation"),
|
265 |
+
P("""
|
266 |
+
The terminal punctuation has been used in C4 [5] and Dolma [6] to remove lines that do not end with a terminal
|
267 |
+
punctuation mark (i.e., “.”, “?”, “!”, or “"”). However, we found it could be too aggressive to remove these
|
268 |
+
lines, especially when using a better text extraction tool “trafilatura”. For instance, in the file
|
269 |
+
CC-MAIN-20230126210844-20230127000844-00000.warc.jsonl, the terminal punctuation rule led to the removal
|
270 |
+
of 56,292 additional lines, resulting in the complete exclusion of 2,203 documents from a total of 13,560
|
271 |
+
documents (16.25%). Accordingly, we choose to not use terminal punctuation as a signal to remove lines.
|
272 |
+
"""),
|
273 |
+
DV(
|
274 |
+
"data/sample_terminal_punc.json",
|
275 |
+
0,
|
276 |
+
"Sample documents with lines that are removed by the rule of terminal punctuation",
|
277 |
+
),
|
278 |
+
H4('2.1 Word "Javascript"'),
|
279 |
+
P("""
|
280 |
+
In C4 [5], the authors remove any line with the word "Javascript" since they found that many of the scraped
|
281 |
+
pages contained warnings stating that Javascript should be enabled. However, this filtering strategy is too
|
282 |
+
strict, which will filter out many lines that are really talking about “Javascript”. In our pipeline, we
|
283 |
+
propose to refine the strategy by adding one more keyword to the word "javascript" to avoid false positives.
|
284 |
+
The additional keyword could be any one of “enable” / “disable” / “require” / “activate” / “browser”.
|
285 |
+
"""),
|
286 |
+
DV(
|
287 |
+
"data/sample_java.jsonl",
|
288 |
+
0,
|
289 |
+
"Sample documents that are removed by original C4 javascript rule but are kept after our refinement",
|
290 |
+
),
|
291 |
+
H4("2.2 Other Rules from RefinedWeb"),
|
292 |
+
P("""
|
293 |
+
We also adopt rules from RefinedWeb [3] to remove lines if they satisfy any of the following criteria:
|
294 |
+
- The line is only composed of uppercase characters,
|
295 |
+
- The line is only composed of numerical characters,
|
296 |
+
- The line matches the pattern “r'^\\d+\\s+likes$'”,
|
297 |
+
- The line contains only one word.
|
298 |
+
"""),
|
299 |
+
DV(
|
300 |
+
"data/sample_refinedweb_line.json",
|
301 |
+
0,
|
302 |
+
"Sample documents with lines that are removed by the RefinedWeb rules",
|
303 |
+
),
|
304 |
+
H4("2.3 Toxic Lines"),
|
305 |
+
P("""
|
306 |
+
When doing manual inspection on the data, we found that there are some adult ads in the beginning or end of the
|
307 |
+
document (with a sample shown below), which are hard to remove via document-level filtering strategies. Inspired
|
308 |
+
by this, we develop line-level detoxification using a bad word list from LDNOOBW (+ rule: word length < 10 + the
|
309 |
+
line is in the first 3 lines or in the last 3 lines) to remove toxic lines. Specifically, we do not only consider
|
310 |
+
the bad words from English but also consider the bad words from other languages.
|
311 |
+
"""),
|
312 |
+
DVS(
|
313 |
+
json.load(open("data/toxic_lines.json")),
|
314 |
+
"Sample documents with toxic lines",
|
315 |
+
),
|
316 |
+
H3("3. Document-Level Filtering"),
|
317 |
+
P("""
|
318 |
+
In this section, we introduce all the quality signals that we have used to filter out low-quality documents.
|
319 |
+
Overview of all the quality signals that are used for filtering."""),
|
320 |
+
DVS(
|
321 |
+
json.load(open("data/all_signals.json")),
|
322 |
+
"Overview of all the quality signals that are used for filtering",
|
323 |
+
),
|
324 |
+
P("""Similar to previous sections, we will present sample documents filtered out by the given quality signals.
|
325 |
+
Most of these quality signals were initially introduced by Gopher [2] and subsequently adopted by later
|
326 |
+
studies ([3], [6], [4]). However, we observed that, despite following the same descriptions, the implementation
|
327 |
+
of each quality signal can vary significantly among different dataset pipelines, resulting in disparate
|
328 |
+
outcomes for the same quality signals.
|
329 |
+
In our pipeline, we referenced earlier implementations that were publicly available such as Dolma [6], DataTrove [4],
|
330 |
+
and RedPajama V2 [7], selecting the most suitable method based on manual inspections.
|
331 |
+
"""),
|
332 |
+
H4("3.1 Repetition-based Heuristics"),
|
333 |
+
P("""
|
334 |
+
Due to crawling errors or low-quality sources, many documents contain repeated sequences. In line with previous
|
335 |
+
work ([2], [3], [6]), we choose to remove any document with excessive line, paragraph, or n-gram repetitions.
|
336 |
+
"""),
|
337 |
+
H5("3.1.1 Fraction of (Characters in) Repeated Lines"),
|
338 |
+
P("""
|
339 |
+
Following Gopher [2], we remove documents containing many short duplicate passages, as well as those with few,
|
340 |
+
but longer duplicate passages. To achieve this goal, we calculate over the document both the fraction of passages
|
341 |
+
that are duplicates, and the fraction of characters contained within those duplicated passages.
|
342 |
+
"""),
|
343 |
+
H6("Implementations from Dolma"),
|
344 |
+
P("..."), # Add specific implementation details if available
|
345 |
+
H6("Implementations from DataTrove"),
|
346 |
+
P("..."), # Add specific implementation details if available
|
347 |
+
P("""
|
348 |
+
After evaluating the implementations of Dolma and DataTrove (note: RedPajama V2 does not implement these two quality
|
349 |
+
signals), we have made the following decisions:
|
350 |
+
"""),
|
351 |
+
H5("Passage Separation"),
|
352 |
+
P("""
|
353 |
+
Our manual review of the data revealed that documents extracted using trafilatura do not feature more than one newline
|
354 |
+
symbol separating passages. Testing the splitting pattern "\\n(2,)" on 10,000 sample documents resulted in no more than
|
355 |
+
one split. Consequently, we decided to disregard the distinction between lines and paragraphs in our implementation,
|
356 |
+
opting instead to use a single newline symbol to segment the text into passages.
|
357 |
+
"""),
|
358 |
+
H5("First Occurrence"),
|
359 |
+
P("""
|
360 |
+
In line with DataTrove's implementation, we chose to exclude the first occurrence. This more conservative strategy
|
361 |
+
helps retain a larger number of documents.
|
362 |
+
"""),
|
363 |
+
H5("Character Count"),
|
364 |
+
P("""
|
365 |
+
We adjusted the method in Dolma for counting characters within lines by excluding whitespace. This modification
|
366 |
+
ensures consistency with the overall document character count calculation.
|
367 |
+
"""),
|
368 |
+
H5("Our Implementation"),
|
369 |
+
DV(
|
370 |
+
"data/repeat_line_frac.jsonl",
|
371 |
+
0,
|
372 |
+
"Sample documents filtered by excessive line repetitions / characters in repeated lines",
|
373 |
+
),
|
374 |
+
H5("3.1.2 Fraction of Characters in the Most Common N-grams (n=2,3,4)"),
|
375 |
+
P("""
|
376 |
+
Following Gopher [2], we remove documents with a high portion of n-grams. For each n ∈ (2, 3, 4), we calculate the
|
377 |
+
fraction of characters contained within the most frequently-occurring n-gram.
|
378 |
+
"""),
|
379 |
+
H6("Implementations from Dolma"),
|
380 |
+
P("..."), # Add specific implementation details if available
|
381 |
+
H6("Implementations from RedPajama-V2"),
|
382 |
+
P("..."), # Add specific implementation details if available
|
383 |
+
H6("Implementations from DataTrove"),
|
384 |
+
P("..."), # Add specific implementation details if available
|
385 |
+
P("""
|
386 |
+
There are almost no contradictions between above implementations of fractions of characters in the most common
|
387 |
+
n-gram. The main process involves counting the occurrences of each n-gram and selecting the most common one. The
|
388 |
+
fraction is then determined by dividing the number of characters in the most common n-gram by the total number of
|
389 |
+
characters. One minor difference is that Dolma and DataTrove calculate the fraction of the most common n-gram even
|
390 |
+
if it only appears once, while RedPajama V2 skips this case.
|
391 |
+
We choose to follow Dolma and DataTrove by not skipping cases where the most common n-gram occurs only once.
|
392 |
+
In practice, documents affected by this rule — where the most common n-gram exceeds a given threshold and occurs
|
393 |
+
only once — tend to be short.
|
394 |
+
"""),
|
395 |
+
H5("Our Implementations"),
|
396 |
+
DV(
|
397 |
+
"data/sample_top_ngram.json",
|
398 |
+
0,
|
399 |
+
"Sample documents filtered by the fraction of characters in the most common n-grams (n=2,3,4)",
|
400 |
+
),
|
401 |
+
H5("3.1.3 Fraction of Characters in Duplicated N-grams (n=5,...,10)"),
|
402 |
+
P("""
|
403 |
+
Following Gopher [2], we remove documents with a high portion of n-grams. For each n ∈ (5, ..., 10), we calculate the
|
404 |
+
fraction of characters contained within all duplicate n-grams, taking care not to count characters that occur in
|
405 |
+
overlapping n-grams more than once.
|
406 |
+
"""),
|
407 |
+
H6("Implementations from Dolma"),
|
408 |
+
P("..."), # Add specific implementation details if available
|
409 |
+
H6("Implementations from RedPajama-V2"),
|
410 |
+
P("..."), # Add specific implementation details if available
|
411 |
+
H6("Implementations from DataTrove"),
|
412 |
+
P("..."), # Add specific implementation details if available
|
413 |
+
P("""
|
414 |
+
For the computation of fraction of characters in duplicate n-gram, Dolma uses the number of characters in all
|
415 |
+
n-grams (with overlapping) as the denominator, and uses the number of characters in all duplicated n-grams
|
416 |
+
(with overlapping) as the numerator. RedPajama V2 uses the number of all characters in (the words of) the document
|
417 |
+
(without overlapping) as the denominator, and uses the number of characters that are recognized as part of the
|
418 |
+
duplicate n-gram as the numerator. Datatrove uses the number of all characters in the document (including white
|
419 |
+
spaces, without overlapping) as the denominator, and uses the number of characters that are recognized as
|
420 |
+
duplicate n-gram as the numerator. However, there is a mismatch in DataTrove’s calculation, as the number of
|
421 |
+
characters in the duplicated n-grams excludes white spaces, while the total character count of the document
|
422 |
+
does not.
|
423 |
+
We decided to use the RedPajama V2 implementation but skip the 1st occurrence of the duplicate n-gram.
|
424 |
+
"""),
|
425 |
+
H5("Our Implementations"),
|
426 |
+
H5("An Example to Show the Difference Between Above Implementations"),
|
427 |
+
P("..."), # Add specific examples if available
|
428 |
+
H5(
|
429 |
+
"Sample Documents Filtered by the Fraction of Characters in Duplicated N-grams (n=5,...,10)"
|
430 |
+
),
|
431 |
+
DV(
|
432 |
+
"data/sample_dup_ngram.json",
|
433 |
+
0,
|
434 |
+
"Sample documents filtered by the fraction of characters in duplicated n-grams (n=5,...,10)",
|
435 |
+
),
|
436 |
+
H4("3.2 Line-wise Heuristics"),
|
437 |
+
P("""
|
438 |
+
Some line-wise information could also be helpful to distinguish low-quality and high-quality documents. Following
|
439 |
+
RefinedWeb [3], we remove the document if the corrected lines represent more than 5% of words. In line with previous
|
440 |
+
works ([2], [3], [6]), we remove the documents if more than 30% of the lines end with an ellipsis or more than
|
441 |
+
90% of lines start with a bullet point.
|
442 |
+
"""),
|
443 |
+
DV(
|
444 |
+
"data/line_info.json",
|
445 |
+
0,
|
446 |
+
"Sample documents that are filtered out by line-wise heuristics",
|
447 |
+
),
|
448 |
+
H4("3.3 Statistics-based Heuristics"),
|
449 |
+
P("""
|
450 |
+
We summarize other statistics-based rules originating from Gopher [2] in this section, which include:
|
451 |
+
- Word count in the document,
|
452 |
+
- Mean word length,
|
453 |
+
- Number of sentences,
|
454 |
+
- Symbol-to-word ratio,
|
455 |
+
- Fraction of alphabetic words,
|
456 |
+
- Number of stop words.
|
457 |
+
|
458 |
+
Specifically, we remove any document which meets any of the following criteria:
|
459 |
+
- Contains fewer than 50 words or more than 100,000 words
|
460 |
+
- Has a mean word length outside the range of 3 to 10 characters
|
461 |
+
- Contains fewer than 3 sentences
|
462 |
+
- Has a symbol-to-word ratio greater than 0.1
|
463 |
+
- Contains less than 80% alphabetic words
|
464 |
+
- Contains fewer than two of the following stop words: "the," "be," "to," "of," "and," "that," "have," "with"
|
465 |
+
"""),
|
466 |
+
H5("Word Count"),
|
467 |
+
P("""
|
468 |
+
Implementations from Dolma
|
469 |
+
Implementations from RedPajama-V2
|
470 |
+
Implementations from DataTrove
|
471 |
+
|
472 |
+
Both Dolma and RedPajama V2 split texts into words using white spaces and newline symbols. However,
|
473 |
+
DataTrove employs a tokenizer to split texts into words and ignore punctuations, resulting in a higher
|
474 |
+
word count compared to simple `text.split()`.
|
475 |
+
We decided to use simple `len(text.split())` to compute the word count.
|
476 |
+
"""),
|
477 |
+
H5("Mean Word Length"),
|
478 |
+
P("""
|
479 |
+
There is minimal variation among existing pipeline implementations. We simply compute the mean word length as follows:
|
480 |
+
"""),
|
481 |
+
Div(
|
482 |
+
Code("""
|
483 |
+
words = text.split()
|
484 |
+
word_count = len(words)
|
485 |
+
character_count = sum(len(word) for word in words)
|
486 |
+
mean_word_length = character_count / word_count
|
487 |
+
"""),
|
488 |
+
cls="code-block",
|
489 |
+
),
|
490 |
+
P("""
|
491 |
+
It's worth noting that Dolma used the median word length instead of the mean in their codes.
|
492 |
+
"""),
|
493 |
+
Div(
|
494 |
+
Code("""
|
495 |
+
from statistics import median
|
496 |
+
median_word_length = median(len(word) for word in words)
|
497 |
+
"""),
|
498 |
+
cls="code-block",
|
499 |
+
),
|
500 |
+
H5("Number of Sentences"),
|
501 |
+
P("""
|
502 |
+
The only publicly available implementation of this quality signal is from RedPajama V2, which uses regular expressions
|
503 |
+
to split text into sentences.
|
504 |
+
"""),
|
505 |
+
P("""
|
506 |
+
However, we found that this approach can mistakenly interpret periods in URLs as sentence endings. To address this,
|
507 |
+
we opted to use `nltk.tokenize.sent_tokenize` for more accurate sentence splitting.
|
508 |
+
"""),
|
509 |
+
H5("Symbol to Word Ratio"),
|
510 |
+
P("""
|
511 |
+
Implementations from Dolma
|
512 |
+
Implementations from RedPajama-V2
|
513 |
+
Implementations from DataTrove
|
514 |
+
|
515 |
+
Following RedPajama-V2 and DataTrove, we use the symbols of ("#", "...", "…").
|
516 |
+
We calculate the ratio as the number of symbols divided by the total number of words.
|
517 |
+
"""),
|
518 |
+
H5("Fraction of Alphabetic Words"),
|
519 |
+
P("""
|
520 |
+
Implementations from Dolma
|
521 |
+
Implementations from RedPajama-V2
|
522 |
+
Implementations from DataTrove
|
523 |
+
|
524 |
+
Both Dolma and DataTrove use `char.isalpha()` to detect whether a word contains alphabetic characters while
|
525 |
+
RedPajama-V2 employs regular expressions for this purpose. We opt to use regular expressions since `char.isalpha()`
|
526 |
+
can also match words in other languages as long as they are not punctuations.
|
527 |
+
"""),
|
528 |
+
Img(
|
529 |
+
src="path/to/sample_alphabetic_words.png",
|
530 |
+
alt="Sample documents filtered by fraction of alphabetic words",
|
531 |
+
),
|
532 |
+
H5("Number of Stop Words"),
|
533 |
+
P("""
|
534 |
+
The implementations across existing pipelines are largely identical. We adopt them and apply them to our pipeline.
|
535 |
+
"""),
|
536 |
+
Img(
|
537 |
+
src="path/to/sample_stop_words.png",
|
538 |
+
alt="Sample documents filtered by number of stop words",
|
539 |
+
),
|
540 |
+
H5("Our Implementations"),
|
541 |
+
DV(
|
542 |
+
"data/sample_doc_stat.json",
|
543 |
+
0,
|
544 |
+
"Sample documents that are filtered out by statistics-based heuristics",
|
545 |
+
),
|
546 |
+
H4("3.4 Others"),
|
547 |
+
P("""
|
548 |
+
Following C4, we remove any page where the phrase “lorem ipsum” appeared since some pages had placeholder “lorem ipsum”
|
549 |
+
text.
|
550 |
+
"""),
|
551 |
+
DV("data/lorem_ipsum.json", 0, "Sample documents containing 'lorem ipsum"),
|
552 |
+
H3("4. Deduplication"),
|
553 |
+
P("..."), # Add detailed content and images as needed
|
554 |
+
H3("5. PII Removal"),
|
555 |
+
P("..."), # Add detailed content and images as needed
|
556 |
+
H2("Reference"),
|
557 |
+
Ul(
|
558 |
+
Li(
|
559 |
+
P(
|
560 |
+
"The {P}ile: An 800{GB} dataset of diverse text for language modeling Gao, Leo and Biderman, Stella and Black, Sid and Golding, Laurence and Hoppe, Travis and Foster, Charles and Phang, Jason and He, Horace and Thite, Anish and Nabeshima, Noa and others. 2020."
|
561 |
+
)
|
562 |
+
),
|
563 |
+
Li(
|
564 |
+
P("""Scaling Language Models: Methods, Analysis & Insights from Training Gopher [link]
|
565 |
+
Jack W. Rae and Sebastian Borgeaud and Trevor Cai and Katie Millican and Jordan Hoffmann and H. Francis
|
566 |
+
Song and John Aslanides and Sarah Henderson and Roman Ring and Susannah Young and Eliza Rutherford and Tom
|
567 |
+
Hennigan and Jacob Menick and Niklas Muennighoff and Aakanksha Naik and Crystal Nam and Matthew E. Peters
|
568 |
+
and Abhilasha Ravichander and Kyle Richardson and Zejiang Shen and Emma Strubell and Nishant Subramani
|
569 |
+
and Oyvind Tafjord and Pete Walsh and Luke Zettlemoyer and Noah A. Smith and Hannaneh Hajishirzi and Iz Beltagy
|
570 |
+
and Dirk Groeneveld and Jesse Dodge and Kyle Lo. 2021.""")
|
571 |
+
),
|
572 |
+
Li(
|
573 |
+
P("""The RefinedWeb Dataset for Falcon LLM: Outperforming Curated Corpora with Web Data, and Web Data Only
|
574 |
+
Guilherme Penedo and Quentin Malartic and Daniel Hesslow and Ruxandra Cojocaru and Alessandro Cappelli and
|
575 |
+
Hamza Alobeidli and Baptiste Pannier and Ebtesam Almazrouei and Julien Launay. 2023.""")
|
576 |
+
),
|
577 |
+
Li(
|
578 |
+
P("""🍷 FineWeb: decanting the web for the finest text data at scale [link]
|
579 |
+
Guilherme Penedo, Hynek Kydlíček, Loubna Ben Allal, Anton Lozhkov, Colin Raffel, Leandro Werra and Thomas Wolf. 2024.""")
|
580 |
+
),
|
581 |
+
Li(
|
582 |
+
P("""Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer
|
583 |
+
Colin Raffel and Noam Shazeer and Adam Roberts and Katherine Lee and Sharan Narang and Michael Matena and Yanqi Zhou and
|
584 |
+
Wei Li and Peter J. Liu. 2023.""")
|
585 |
+
),
|
586 |
+
Li(
|
587 |
+
P("""Dolma: an Open Corpus of Three Trillion Tokens for Language Model Pretraining Research
|
588 |
+
Luca Soldaini and Rodney Kinney and Akshita Bhagia and Dustin Schwenk and David Atkinson and Russell Authur and
|
589 |
+
Ben Bogin and Khyathi Chandu and Jennifer Dumas and Yanai Elazar and Valentin Hofmann and Ananya Harsh Jha and
|
590 |
+
Sachin Kumar and Li Lucy and Xinxi Lyu and Nathan Lambert and Ian Magnusson and Jacob Morrison and Niklas Muennighoff and
|
591 |
+
Aakanksha Naik and Crystal Nam and Matthew E. Peters and Abhilasha Ravichander and Kyle Richardson and Zejiang Shen
|
592 |
+
and Emma Strubell and Nishant Subramani and Oyvind Tafjord and Pete Walsh and Luke Zettlemoyer and Noah A. Smith and
|
593 |
+
Hannaneh Hajishirzi and Iz Beltagy and Dirk Groeneveld and Jesse Dodge and Kyle Lo. 2024.""")
|
594 |
+
),
|
595 |
+
Li(
|
596 |
+
P("""RedPajama-Data-v2: an Open Dataset with 30 Trillion Tokens for Training Large Language Models [link]
|
597 |
+
Together Computer. 2023.""")
|
598 |
+
),
|
599 |
+
),
|
600 |
)
|
601 |
+
|