view pipeline result
Browse files- app.py +379 -5
- CC-MAIN-20231128083443-20231128113443-00000.warc.gz → data/CC-MAIN-20231128083443-20231128113443-00000.warc.gz +0 -0
- images/00_1st_step_url_filtering.png +0 -0
- images/01_2nd_step_text_extraction.png +0 -0
- images/02_3rd_step_language_filtering.png +0 -0
- images/03_4th_step_gopher_filtering.png +0 -0
- images/10_8th_step_pii_removal.png +0 -0
- images/11_7th_step_custom_filters.png +0 -0
- images/12_6th_step_c4_filters.png +0 -0
- images/13_5th_step_gopher_filtering.png +0 -0
- output_all-200/base_processing/output/CC-MAIN-2023-50/00000.jsonl.gz +3 -0
- output_all-2k/base_processing/output/CC-MAIN-2023-50/00000.jsonl.gz +3 -0
- output_text_extraction-2k/base_processing/output/CC-MAIN-2023-50/00000.jsonl.gz +3 -0
- requirements.txt +1 -0
app.py
CHANGED
@@ -1,9 +1,18 @@
|
|
|
|
|
|
|
|
|
|
1 |
from itertools import islice
|
|
|
|
|
2 |
|
3 |
import gradio as gr
|
|
|
|
|
|
|
4 |
from datatrove.executor.local import LocalPipelineExecutor
|
5 |
-
from datatrove.pipeline.base import PipelineStep
|
6 |
from datatrove.pipeline.extractors import Trafilatura
|
|
|
7 |
from datatrove.pipeline.filters import (
|
8 |
C4QualityFilter,
|
9 |
FineWebQualityFilter,
|
@@ -12,13 +21,378 @@ from datatrove.pipeline.filters import (
|
|
12 |
LanguageFilter,
|
13 |
URLFilter,
|
14 |
)
|
15 |
-
from datatrove.pipeline.
|
|
|
16 |
from datatrove.pipeline.writers.jsonl import JsonlWriter
|
|
|
17 |
|
18 |
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
|
23 |
-
demo = gr.Interface(run, inputs=[gr.Textbox()], outputs=[gr.Textbox()])
|
24 |
demo.launch()
|
|
|
1 |
+
import ast
|
2 |
+
import glob
|
3 |
+
import tempfile
|
4 |
+
from dataclasses import asdict
|
5 |
from itertools import islice
|
6 |
+
from functools import partial
|
7 |
+
from typing import Optional
|
8 |
|
9 |
import gradio as gr
|
10 |
+
import nltk
|
11 |
+
import pandas as pd
|
12 |
+
from datatrove.utils.typeshelper import Languages
|
13 |
from datatrove.executor.local import LocalPipelineExecutor
|
|
|
14 |
from datatrove.pipeline.extractors import Trafilatura
|
15 |
+
from datatrove.pipeline.filters.base_filter import BaseFilter
|
16 |
from datatrove.pipeline.filters import (
|
17 |
C4QualityFilter,
|
18 |
FineWebQualityFilter,
|
|
|
21 |
LanguageFilter,
|
22 |
URLFilter,
|
23 |
)
|
24 |
+
from datatrove.pipeline.formatters import PIIFormatter
|
25 |
+
from datatrove.pipeline.readers import JsonlReader, WarcReader
|
26 |
from datatrove.pipeline.writers.jsonl import JsonlWriter
|
27 |
+
from difflib import Differ
|
28 |
|
29 |
|
30 |
+
nltk.download('punkt_tab')
|
31 |
+
DUMP_TO_PROCESS = "CC-MAIN-2023-50"
|
32 |
+
default_output_docs_2k = pd.read_json(f"output_all-2k/base_processing/output/{DUMP_TO_PROCESS}/00000.jsonl.gz", compression="gzip", lines=True).to_dict(orient="records")
|
33 |
+
default_output_docs_200 = pd.read_json(f"output_all-200/base_processing/output/{DUMP_TO_PROCESS}/00000.jsonl.gz", compression="gzip", lines=True).to_dict(orient="records")
|
34 |
+
|
35 |
+
make_gallery_image_buttons_js = """
|
36 |
+
function load() {
|
37 |
+
class ClassWatcher {
|
38 |
+
|
39 |
+
constructor(targetNode, classToWatch, classAddedCallback, arg) {
|
40 |
+
this.targetNode = targetNode
|
41 |
+
this.classToWatch = classToWatch
|
42 |
+
this.classAddedCallback = classAddedCallback
|
43 |
+
this.arg = arg
|
44 |
+
this.observer = null
|
45 |
+
this.lastClassState = targetNode.classList.contains(this.classToWatch)
|
46 |
+
|
47 |
+
this.init()
|
48 |
+
}
|
49 |
+
|
50 |
+
init() {
|
51 |
+
this.observer = new MutationObserver(this.mutationCallback)
|
52 |
+
this.observe()
|
53 |
+
}
|
54 |
+
|
55 |
+
observe() {
|
56 |
+
this.observer.observe(this.targetNode, { attributes: true })
|
57 |
+
}
|
58 |
+
|
59 |
+
disconnect() {
|
60 |
+
this.observer.disconnect()
|
61 |
+
}
|
62 |
+
|
63 |
+
mutationCallback = mutationsList => {
|
64 |
+
for (let mutation of mutationsList) {
|
65 |
+
if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
|
66 |
+
let currentClassState = mutation.target.classList.contains(this.classToWatch)
|
67 |
+
if(this.lastClassState !== currentClassState) {
|
68 |
+
this.lastClassState = currentClassState
|
69 |
+
if(currentClassState) {
|
70 |
+
this.classAddedCallback(this.arg)
|
71 |
+
}
|
72 |
+
}
|
73 |
+
}
|
74 |
+
}
|
75 |
+
}
|
76 |
+
}
|
77 |
+
let buttons = document.getElementsByClassName("block-button");
|
78 |
+
function clickButton(i) {
|
79 |
+
buttons[i].click();
|
80 |
+
}
|
81 |
+
Array.from(document.getElementById("pipeline-gallery").getElementsByClassName("thumbnail-item")).map(
|
82 |
+
(b, i) => new ClassWatcher(b, 'selected', clickButton, i)
|
83 |
+
)
|
84 |
+
}
|
85 |
+
"""
|
86 |
+
css = """
|
87 |
+
tr:has(> td div span span div.diffInsertion) {
|
88 |
+
background: darkgreen;
|
89 |
+
}
|
90 |
+
tr:has(> td div span span div.diffDeletion) {
|
91 |
+
background: darkred;
|
92 |
+
}
|
93 |
+
tr td {
|
94 |
+
border-top: 1px solid black;
|
95 |
+
}
|
96 |
+
"""
|
97 |
+
|
98 |
+
|
99 |
+
blocks = sorted(glob.glob("images/*.png"))
|
100 |
+
|
101 |
+
|
102 |
+
def prepare_as_list_or_none(text: str) -> Optional[list[str]]:
|
103 |
+
return ([x.strip() for x in text.split(",") if x.strip()] or None) if text else None
|
104 |
+
|
105 |
+
def build_code_snippet(steps, params=None):
|
106 |
+
# TODO
|
107 |
+
return (
|
108 |
+
"```python\n"
|
109 |
+
"TODO\n"
|
110 |
+
"```"
|
111 |
+
)
|
112 |
+
|
113 |
+
|
114 |
+
with gr.Blocks(css=css, js=make_gallery_image_buttons_js) as demo:
|
115 |
+
state = gr.State({"selected_block": 0})
|
116 |
+
gr.Markdown("# Common Crawl Pipeline Creator")
|
117 |
+
gallery = gr.Gallery(
|
118 |
+
blocks,
|
119 |
+
columns=4,
|
120 |
+
rows=2,
|
121 |
+
label="Select step to edit",
|
122 |
+
object_fit="scale-down",
|
123 |
+
show_share_button=False,
|
124 |
+
show_download_button=False,
|
125 |
+
show_fullscreen_button=False,
|
126 |
+
elem_id="pipeline-gallery",
|
127 |
+
height="200px",
|
128 |
+
allow_preview=False,
|
129 |
+
)
|
130 |
+
gallery_image_buttons = [gr.Button(visible=False, elem_classes="block-button") for _ in blocks] # hack to simulate each image galery as a button, see `make_gallery_image_buttons_js``
|
131 |
+
blocks_uis = []
|
132 |
+
with gr.Column(visible=False) as col:
|
133 |
+
blocks_uis.append(col)
|
134 |
+
gr.Markdown("## 1. URL Filtering \n\nPerforms filtering based on samples urls.")
|
135 |
+
with gr.Group():
|
136 |
+
url_filtering_checkbox = gr.Checkbox(True, label="Enable")
|
137 |
+
with gr.Accordion("Parameters", open=True) as acc:
|
138 |
+
use_integrated_lists_checkbox = gr.Checkbox(True, label="use_integrated_lists", info="use the datatrove integrated lists of banned urls and words")
|
139 |
+
with gr.Row():
|
140 |
+
with gr.Column():
|
141 |
+
extra_domain_textbox = gr.Textbox("", label="extra_domains", info="remove if the domain is present in `extra_domains`")
|
142 |
+
extra_domain_textbox.prepare_parameter = prepare_as_list_or_none
|
143 |
+
extra_urls_textbox = gr.Textbox("", label="extra_urls", info="remove if the full url is present on `extra_urls`")
|
144 |
+
extra_urls_textbox.prepare_parameter = prepare_as_list_or_none
|
145 |
+
with gr.Column():
|
146 |
+
banned_words_textbox = gr.Textbox("", label="banned_words", info="remove if any word from `banned_words` is in the url")
|
147 |
+
banned_words_textbox.prepare_parameter = prepare_as_list_or_none
|
148 |
+
banned_subwords_textbox = gr.Textbox("", label="banned_subwords", info="remove if any word from `banned_subwords` is a substring of the url")
|
149 |
+
banned_subwords_textbox.prepare_parameter = prepare_as_list_or_none
|
150 |
+
with gr.Column():
|
151 |
+
soft_banned_words_textbox = gr.Textbox("", label="soft_banned_words", info="remove if there are at least `soft_word_threshold` words from `soft_banned_words` in the url")
|
152 |
+
soft_banned_words_textbox.prepare_parameter = prepare_as_list_or_none
|
153 |
+
soft_word_threshold_slider = gr.Slider(0, 5, value=2, step=1, label="soft_word_threshold", info="remove if there are at least `soft_word_threshold` words from `soft_banned_words` in the url")
|
154 |
+
url_filtering_checkbox.change(lambda visible: gr.Accordion(visible=visible), inputs=url_filtering_checkbox, outputs=acc)
|
155 |
+
url_filtering_parameters_components = [use_integrated_lists_checkbox, extra_domain_textbox, extra_urls_textbox, banned_words_textbox, banned_subwords_textbox, soft_banned_words_textbox, soft_word_threshold_slider]
|
156 |
+
with gr.Column(visible=False) as col:
|
157 |
+
blocks_uis.append(col)
|
158 |
+
gr.Markdown("## 2. Text Extraction \n\nUses the [Trafilatura](https://trafilatura.readthedocs.io) extractor.")
|
159 |
+
with gr.Group():
|
160 |
+
text_extraction_checkbox = gr.Checkbox(True, label="Enable")
|
161 |
+
with gr.Accordion("Parameters", open=True) as acc:
|
162 |
+
with gr.Row():
|
163 |
+
favour_precision_checkbox = gr.Checkbox(True, label="favour_precision", info="prefer less text but correct extraction")
|
164 |
+
timeout_slider = gr.Slider(0.05, 0.5, value=0.1, step=0.05, label="timeout", info="the timeout for extraction, per document, in seconds")
|
165 |
+
deduplicate_checkbox = gr.Checkbox(True, label="deduplicate", info="trafilatura's deduplicate option")
|
166 |
+
text_extraction_checkbox.change(lambda visible: gr.Accordion(visible=visible), inputs=text_extraction_checkbox, outputs=acc)
|
167 |
+
text_extraction_parameters_components = [favour_precision_checkbox, timeout_slider, deduplicate_checkbox]
|
168 |
+
with gr.Column(visible=False) as col:
|
169 |
+
blocks_uis.append(col)
|
170 |
+
gr.Markdown("## 3. Language Filtering \n\nUses the [fastext](https://fasttext.cc/docs/en/language-identification.html) language identification models.")
|
171 |
+
with gr.Group():
|
172 |
+
language_filtering_checkbox = gr.Checkbox(True, label="Enable")
|
173 |
+
with gr.Accordion("Parameters", open=True) as acc:
|
174 |
+
with gr.Row():
|
175 |
+
languages_textbox = gr.Textbox("", label="languages", info="list of languages to keep. empty for all")
|
176 |
+
languages_textbox.prepare_parameter = prepare_as_list_or_none
|
177 |
+
language_threshold_slider = gr.Slider(0, 1, value=0.65, step=0.05, label="language_threshold", info="minimum score to accept a document")
|
178 |
+
language_filtering_checkbox.change(lambda visible: gr.Accordion(visible=visible), inputs=language_filtering_checkbox, outputs=acc)
|
179 |
+
language_filtering_parameters_components = [languages_textbox, language_threshold_slider]
|
180 |
+
with gr.Column(visible=False) as col:
|
181 |
+
blocks_uis.append(col)
|
182 |
+
gr.Markdown("## 4. Gopher Filtering (repetitions) \n\nUses the [Gopher](https://huggingface.co/papers/2112.11446) text repetition filters.")
|
183 |
+
with gr.Group():
|
184 |
+
gopher_filtering_repetitions_checkbox = gr.Checkbox(True, label="Enable")
|
185 |
+
with gr.Accordion("Parameters", open=True) as acc:
|
186 |
+
with gr.Group():
|
187 |
+
with gr.Row():
|
188 |
+
language_dropdown1 = gr.Dropdown([v for k, v in vars(Languages).items() if not k.startswith("__")], value=Languages.english, label="language", info="tokenizer language")
|
189 |
+
top_n_grams_textbox = gr.Textbox("(2, 0.2), (3, 0.18), (4, 0.16)", label="top_n_grams")
|
190 |
+
top_n_grams_textbox.prepare_parameter = ast.literal_eval
|
191 |
+
dup_n_grams_textbox = gr.Textbox("(5, 0.15), (6, 0.14), (7, 0.13), (8, 0.12), (9, 0.11), (10, 0.10)", label="dup_n_grams")
|
192 |
+
dup_n_grams_textbox.prepare_parameter = ast.literal_eval
|
193 |
+
with gr.Row():
|
194 |
+
dup_line_frac_slider = gr.Slider(0, 1, value=0.3, step=0.05, label="dup_line_frac")
|
195 |
+
dup_para_frac_slider = gr.Slider(0, 1, value=0.3, step=0.05, label="dup_para_frac")
|
196 |
+
dup_line_char_frac_slider = gr.Slider(0, 1, value=0.2, step=0.05, label="dup_line_char_frac")
|
197 |
+
dup_para_char_frac_slider = gr.Slider(0, 1, value=0.2, step=0.05, label="dup_para_char_frac")
|
198 |
+
gopher_filtering_repetitions_checkbox.change(lambda visible: gr.Accordion(visible=visible), inputs=gopher_filtering_repetitions_checkbox, outputs=acc)
|
199 |
+
gopher_filtering_repetitions_parameters_components = [language_dropdown1, top_n_grams_textbox, dup_n_grams_textbox, dup_line_frac_slider, dup_para_frac_slider, dup_line_char_frac_slider, dup_para_char_frac_slider]
|
200 |
+
with gr.Column(visible=False) as col:
|
201 |
+
blocks_uis.append(col)
|
202 |
+
gr.Markdown("## 8. PII Removal \n\nReplaces email addresses and ip addresses in the document text.")
|
203 |
+
with gr.Group():
|
204 |
+
pii_removal_checkbox = gr.Checkbox(True, label="Enable")
|
205 |
+
with gr.Accordion("Parameters", open=True) as acc:
|
206 |
+
with gr.Row():
|
207 |
+
remove_emails_checkbox = gr.Checkbox(True, label="remove_emails", info="Replace email addresses")
|
208 |
+
remove_ips_checkbox = gr.Checkbox(True, label="remove_ips", info="Replace IP addresses")
|
209 |
+
only_remove_public_ips_checkbox = gr.Checkbox(True, label="only_remove_public_ips", info="by default we only replace public (and thus PII) IPs")
|
210 |
+
with gr.Row():
|
211 |
+
email_replacement_textbox = gr.Textbox("email@example.com, firstname.lastname@example.org", label="email_replacement", info="strings to use as replacement. They will be used in a circular way")
|
212 |
+
email_replacement_textbox.prepare_parameter = prepare_as_list_or_none
|
213 |
+
ip_replacement_textbox = gr.Textbox("22.214.171.124, 126.96.36.199, 188.8.131.52, 184.108.40.206, 220.127.116.11, 18.104.22.168", label="ip_replacement", info="same as email_replacement but for IP addresses")
|
214 |
+
ip_replacement_textbox.prepare_parameter = prepare_as_list_or_none
|
215 |
+
pii_removal_checkbox.change(lambda visible: gr.Accordion(visible=visible), inputs=pii_removal_checkbox, outputs=acc)
|
216 |
+
pii_removal_parameters_components = [remove_emails_checkbox, remove_ips_checkbox, only_remove_public_ips_checkbox, email_replacement_textbox, ip_replacement_textbox]
|
217 |
+
with gr.Column(visible=False) as col:
|
218 |
+
blocks_uis.append(col)
|
219 |
+
gr.Markdown("## 7. Custom Filters \n\nUses the [FineWeb](https://huggingface.co/datasets/HuggingFaceFW/fineweb) custom text filters.")
|
220 |
+
with gr.Group():
|
221 |
+
custom_filters_checkbox = gr.Checkbox(True, label="Enable")
|
222 |
+
with gr.Accordion("Parameters", open=True) as acc:
|
223 |
+
with gr.Row():
|
224 |
+
line_punct_thr_slider = gr.Slider(0, 1, value=0.12, step=0.01, label="line_punct_thr")
|
225 |
+
line_punct_exclude_zero = gr.Checkbox(False, label="line_punct_exclude_zero")
|
226 |
+
short_line_thr_slider = gr.Slider(0, 1, value=0.67, step=0.01, label="short_line_thr")
|
227 |
+
short_line_length_slider = gr.Slider(0, 100, value=30, step=1, label="short_line_length")
|
228 |
+
char_duplicates_ratio_slider = gr.Slider(0, 1, value=0.01, step=0.01, label="char_duplicates_ratio")
|
229 |
+
new_line_ratio_slider = gr.Slider(0, 1, value=0.3, step=0.01, label="new_line_ratio")
|
230 |
+
custom_filters_checkbox.change(lambda visible: gr.Accordion(visible=visible), inputs=custom_filters_checkbox, outputs=acc)
|
231 |
+
custom_filters_parameters_components = [line_punct_thr_slider, line_punct_exclude_zero, short_line_thr_slider, short_line_length_slider, char_duplicates_ratio_slider, new_line_ratio_slider]
|
232 |
+
with gr.Column(visible=False) as col:
|
233 |
+
blocks_uis.append(col)
|
234 |
+
gr.Markdown("## 6. C4 Filters\n\nUses the [C4](https://huggingface.co/datasets/allenai/c4) text size and content filters.")
|
235 |
+
with gr.Group():
|
236 |
+
c4_filters_checkbox = gr.Checkbox(True, label="Enable")
|
237 |
+
with gr.Accordion(" Parameters", open=True) as acc:
|
238 |
+
with gr.Group():
|
239 |
+
with gr.Row():
|
240 |
+
split_paragraph_checkbox = gr.Checkbox(True, label="split_paragraph", info="disable to apply the filters to each sentence instead of to each line")
|
241 |
+
with gr.Row():
|
242 |
+
language_dropdown2 = gr.Dropdown([v for k, v in vars(Languages).items() if not k.startswith("__")], value=Languages.english, label="language", info="tokenizer language")
|
243 |
+
min_num_sentences_slider = gr.Slider(0, 10, value=5, step=1, label="min_num_sentences", info="remove documents that do not have at least this number of sentences (after line filtering)")
|
244 |
+
min_words_per_line_slider = gr.Slider(0, 10, value=3, step=1, label="min_words_per_line", info="drop lines without this min number of words")
|
245 |
+
max_word_length_slider = gr.Slider(0, 2000, value=1000, step=10, label="max_word_length", info=" drop lines where at least one word has more than this number of characters")
|
246 |
+
with gr.Row():
|
247 |
+
remove_citations_checkbox = gr.Checkbox(True, label="remove_citations", info="remove wikipedia style citations from the text")
|
248 |
+
filter_no_terminal_punct_checkbox = gr.Checkbox(True, label="filter_no_terminal_punct", info="remove lines without terminal punctuation marks")
|
249 |
+
filter_lorem_ipsum_checkbox = gr.Checkbox(True, label="filter_lorem_ipsum", info="drop documents that contain 'lorem ipsum'")
|
250 |
+
filter_javascript_checkbox = gr.Checkbox(True, label="filter_javascript", info="drop lines mentioning 'javascript'")
|
251 |
+
filter_curly_bracket = gr.Checkbox(True, label="filter_curly_bracket", info="drop documents containing {")
|
252 |
+
filter_policy = gr.Checkbox(True, label="filter_policy", info="drop lines containing any of the policy phrases (e.g. 'terms of use', 'use cookies')")
|
253 |
+
c4_filters_checkbox.change(lambda visible: gr.Accordion(visible=visible), inputs=c4_filters_checkbox, outputs=acc)
|
254 |
+
c4_filters_parameters_components = [split_paragraph_checkbox, language_dropdown2, min_num_sentences_slider, min_words_per_line_slider, max_word_length_slider, remove_citations_checkbox, filter_no_terminal_punct_checkbox, filter_lorem_ipsum_checkbox, filter_javascript_checkbox, filter_curly_bracket, filter_policy]
|
255 |
+
with gr.Column(visible=False) as col:
|
256 |
+
blocks_uis.append(col)
|
257 |
+
gr.Markdown("## 5. Gopher Filtering (quality) \n\nUses the [Gopher](https://huggingface.co/papers/2112.11446) text quality filters.")
|
258 |
+
with gr.Group():
|
259 |
+
gopher_filtering_quality_checkbox = gr.Checkbox(True, label="Enable")
|
260 |
+
with gr.Accordion("Parameters", open=True) as acc:
|
261 |
+
with gr.Group():
|
262 |
+
with gr.Row():
|
263 |
+
language_dropdown2 = gr.Dropdown([v for k, v in vars(Languages).items() if not k.startswith("__")], value=Languages.english, label="language", info="tokenizer language")
|
264 |
+
min_doc_words_slider = gr.Slider(0, 1000, value=50, step=10, label="min_doc_words")
|
265 |
+
max_doc_words_slider = gr.Slider(0, 200_000, value=100_000, step=10_000, label="max_doc_words")
|
266 |
+
with gr.Row():
|
267 |
+
min_avg_word_length_slider = gr.Slider(0, 20, value=3, step=1, label="min_avg_word_length")
|
268 |
+
max_avg_word_length_slider = gr.Slider(0, 20, value=10, step=1, label="max_avg_word_length")
|
269 |
+
with gr.Row():
|
270 |
+
max_symbol_word_ratio_slider = gr.Slider(0, 1, value=0.1, step=0.05, label="max_symbol_word_ratio")
|
271 |
+
max_bullet_lines_ratio_slider = gr.Slider(0, 1, value=0.9, step=0.05, label="max_bullet_lines_ratio")
|
272 |
+
max_ellipsis_lines_ratio_slider = gr.Slider(0, 1, value=0.3, step=0.05, label="max_ellipsis_lines_ratio")
|
273 |
+
max_non_alpha_words_ratio_slider = gr.Slider(0, 1, value=0.8, step=0.05, label="max_non_alpha_words_ratio")
|
274 |
+
with gr.Row():
|
275 |
+
min_stop_words_slider = gr.Slider(0, 10, value=2, step=1, label="min_stop_words")
|
276 |
+
stop_words_textbox = gr.Textbox("the, be, to, of, and, that, have, with", label="stop_words")
|
277 |
+
stop_words_textbox.prepare_parameter = prepare_as_list_or_none
|
278 |
+
gopher_filtering_quality_checkbox.change(lambda visible: gr.Accordion(visible=visible), inputs=gopher_filtering_quality_checkbox, outputs=acc)
|
279 |
+
gopher_filtering_quality_parameters_components = [language_dropdown2, min_doc_words_slider, max_doc_words_slider, min_avg_word_length_slider, max_avg_word_length_slider, max_symbol_word_ratio_slider, max_bullet_lines_ratio_slider, max_ellipsis_lines_ratio_slider, max_non_alpha_words_ratio_slider, min_stop_words_slider, stop_words_textbox]
|
280 |
+
|
281 |
+
view_pipeline_results_button = gr.Button("View Pipeline Results", variant="primary")
|
282 |
+
|
283 |
+
steps = [
|
284 |
+
URLFilter,
|
285 |
+
Trafilatura,
|
286 |
+
LanguageFilter,
|
287 |
+
GopherRepetitionFilter,
|
288 |
+
GopherQualityFilter,
|
289 |
+
C4QualityFilter,
|
290 |
+
FineWebQualityFilter,
|
291 |
+
PIIFormatter
|
292 |
+
]
|
293 |
+
steps_parameters_components = [
|
294 |
+
url_filtering_parameters_components,
|
295 |
+
text_extraction_parameters_components,
|
296 |
+
language_filtering_parameters_components,
|
297 |
+
gopher_filtering_repetitions_parameters_components,
|
298 |
+
gopher_filtering_quality_parameters_components,
|
299 |
+
c4_filters_parameters_components,
|
300 |
+
custom_filters_parameters_components,
|
301 |
+
pii_removal_parameters_components
|
302 |
+
]
|
303 |
+
|
304 |
+
with gr.Tab("Output") as output_tab:
|
305 |
+
output_dataframe_diff = gr.DataFrame(datatype="markdown")
|
306 |
+
with gr.Tab("Python code") as code_tab:
|
307 |
+
python_code_markdown = gr.Markdown(build_code_snippet(steps))
|
308 |
+
|
309 |
+
|
310 |
+
gr.Markdown("_powered by [datatrove](https://github.com/huggingface/datatrove)_")
|
311 |
+
|
312 |
+
def show_block_ui(i):
|
313 |
+
return {**{block_ui: gr.Column(visible=(j == i)) for j, block_ui in enumerate(blocks_uis)}, state: {"selected_block": i}}
|
314 |
+
|
315 |
+
for i, button in enumerate(gallery_image_buttons):
|
316 |
+
button.click(partial(show_block_ui, i), outputs=blocks_uis + [state])
|
317 |
+
|
318 |
+
|
319 |
+
inputs = [
|
320 |
+
url_filtering_checkbox,
|
321 |
+
text_extraction_checkbox,
|
322 |
+
language_filtering_checkbox,
|
323 |
+
gopher_filtering_repetitions_checkbox,
|
324 |
+
gopher_filtering_quality_checkbox,
|
325 |
+
c4_filters_checkbox,
|
326 |
+
custom_filters_checkbox,
|
327 |
+
pii_removal_checkbox
|
328 |
+
] + sum(steps_parameters_components, [])
|
329 |
+
|
330 |
+
@view_pipeline_results_button.click(inputs=inputs, outputs=[output_tab, output_dataframe_diff])
|
331 |
+
def view_pipeline_results(*args):
|
332 |
+
enable_steps, steps_parameters = args[:len(steps)], args[len(steps):]
|
333 |
+
steps_parameters_iter = iter(steps_parameters)
|
334 |
+
steps_parameters = [
|
335 |
+
{
|
336 |
+
parameters_component.label: parameters_component.prepare_parameter(parameter) if hasattr(parameters_component, "prepare_parameter") else parameter
|
337 |
+
for parameters_component, parameter in zip(step_parameters_components, steps_parameters_iter)
|
338 |
+
}
|
339 |
+
for step_parameters_components in steps_parameters_components
|
340 |
+
]
|
341 |
+
default_steps_parameters = [
|
342 |
+
{
|
343 |
+
parameters_component.label: parameters_component.prepare_parameter(parameters_component.value) if hasattr(parameters_component, "prepare_parameter") else parameters_component.value
|
344 |
+
for parameters_component in step_parameters_components
|
345 |
+
}
|
346 |
+
for step_parameters_components in steps_parameters_components
|
347 |
+
]
|
348 |
+
|
349 |
+
with tempfile.TemporaryDirectory() as output_path:
|
350 |
+
steps_to_run = [
|
351 |
+
step(**step_parameters, **({"exclusion_writer": JsonlWriter(f"{output_path}/base_processing/removed/{step.__name__}/{DUMP_TO_PROCESS}")} if issubclass(step, BaseFilter) and False else {}))
|
352 |
+
for step, step_parameters, enable_step in zip(steps, steps_parameters, enable_steps)
|
353 |
+
if enable_step
|
354 |
+
]
|
355 |
+
output_docs = []
|
356 |
+
if steps_parameters[:2] == default_steps_parameters[:2] and all(enable_steps[:2]):
|
357 |
+
num_warc_samples = 2000
|
358 |
+
default_output_docs = default_output_docs_2k
|
359 |
+
pipeline = LocalPipelineExecutor(
|
360 |
+
pipeline=[
|
361 |
+
JsonlReader(data_folder=f"output_text_extraction-2k/base_processing/output/{DUMP_TO_PROCESS}", glob_pattern="*.jsonl.gz")
|
362 |
+
] + steps_to_run[2:] + [
|
363 |
+
lambda data, rank, world_size: map(output_docs.append, data)
|
364 |
+
],
|
365 |
+
logging_dir="logs",
|
366 |
+
skip_completed=False
|
367 |
+
)
|
368 |
+
else:
|
369 |
+
num_warc_samples = 200
|
370 |
+
default_output_docs = default_output_docs_200
|
371 |
+
pipeline = LocalPipelineExecutor(
|
372 |
+
pipeline=[
|
373 |
+
WarcReader(data_folder="data", glob_pattern="*.warc.gz"),
|
374 |
+
lambda data, rank, world_size: islice(data, num_warc_samples),
|
375 |
+
] + steps_to_run + [
|
376 |
+
lambda data, rank, world_size: map(output_docs.append, data)
|
377 |
+
],
|
378 |
+
logging_dir="logs",
|
379 |
+
skip_completed=False
|
380 |
+
)
|
381 |
+
pipeline.run()
|
382 |
+
out = [doc.text[:1_000] + f" [+{len(doc.text) - 1000} chars]" if len(doc.text) > 1_000 else doc.text for doc in output_docs]
|
383 |
+
default_out = [doc["text"][:1_000] + f" [+{len(doc['text']) - 1000} chars]" if len(doc["text"]) > 1_000 else doc["text"] for doc in default_output_docs]
|
384 |
+
output_diff = []
|
385 |
+
for text_diff in Differ().compare(default_out, out[:len(default_out) * 10]):
|
386 |
+
opcode, text = text_diff[0], text_diff[2:]
|
387 |
+
if opcode == "-":
|
388 |
+
text = f'<div class="diffDeletion">\n\n{text}\n\n</div>'
|
389 |
+
elif opcode == "+":
|
390 |
+
text = f'<div class="diffInsertion">\n\n{text}\n\n</div>'
|
391 |
+
output_diff.append(text)
|
392 |
+
return {
|
393 |
+
output_tab: gr.Tab(f"Output: kept {len(out)/num_warc_samples*100:.02f}% of data"),
|
394 |
+
output_dataframe_diff: pd.DataFrame({"text": output_diff}),
|
395 |
+
}
|
396 |
|
397 |
|
|
|
398 |
demo.launch()
|
CC-MAIN-20231128083443-20231128113443-00000.warc.gz → data/CC-MAIN-20231128083443-20231128113443-00000.warc.gz
RENAMED
File without changes
|
images/00_1st_step_url_filtering.png
ADDED
images/01_2nd_step_text_extraction.png
ADDED
images/02_3rd_step_language_filtering.png
ADDED
images/03_4th_step_gopher_filtering.png
ADDED
images/10_8th_step_pii_removal.png
ADDED
images/11_7th_step_custom_filters.png
ADDED
images/12_6th_step_c4_filters.png
ADDED
images/13_5th_step_gopher_filtering.png
ADDED
output_all-200/base_processing/output/CC-MAIN-2023-50/00000.jsonl.gz
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7798c4f4cb22b19532ea4c5a58dbc94b72dd7627007a90dc0b2d83cf6ac56007
|
3 |
+
size 28010
|
output_all-2k/base_processing/output/CC-MAIN-2023-50/00000.jsonl.gz
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e32e8d71f3bcf050fe2d0a744b21e411c66b95ee4f88a4fa8eac5f6b459ce345
|
3 |
+
size 299465
|
output_text_extraction-2k/base_processing/output/CC-MAIN-2023-50/00000.jsonl.gz
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d17adea750d20daae760f1ed8f4ebde38e6e2e7ad6d0e2b6e98d044f459a5ac8
|
3 |
+
size 1922310
|
requirements.txt
CHANGED
@@ -1 +1,2 @@
|
|
1 |
datatrove[all]
|
|
|
|
1 |
datatrove[all]
|
2 |
+
lxml_html_clean
|