omkarenator commited on
Commit
3eba508
1 Parent(s): 600ab03

add data viewer to the web parts

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