Dive into Deep Learning · §20.1
Document Extraction from Web Crawls
WARC records · charsets · main-content extraction · language identification · Unicode normalization · personal data · the manifest
The problem
A page of the Apache HTTP Server manual, crawled in January 2025:
| view of the same record | size |
|---|---|
| HTML | 27,385 bytes; a menu bar of 5 links and a breadcrumb trail of 5 before the heading |
| WET, Common Crawl’s text | 14,217 characters; 34% of its 127 lines under 30 characters |
| FineWeb’s text | 11,159 characters; menu and breadcrumbs gone |
| our trafilatura text | 12,658 characters; character-5-gram F1 0.96 against FineWeb |
What the extractor drops, the model never sees; what it keeps, the model learns.
Goals
Running example: the first 256 MiB of one Common Crawl archive file of January 2025, and FineWeb’s text for the same records.
Where this fits
| step | section |
|---|---|
| get text | Document Extraction from Web Crawls |
| choose text | Quality Filtering |
| Deduplication and Decontamination | |
| mix text | Data Mixtures |
| Synthetic and Rephrased Data | |
| cut text | Tokenizers at Scale |
WARC
| type | offset | compressed bytes |
|---|---|---|
| warcinfo | 0 | 471 |
| request | 471 | 432 |
| response | 903 | 1,903 |
| metadata | 2,806 | 424 |
| request, response, metadata, … | 3,230 | … |
Range request for bytes 0..n-1 returns complete members plus one that the cut splits: count it, drop it.iter_warc against warcio on 4 MiB: 857 of 857 records identical.warcio yields the split member as a record, cut short.
The range
| 256 MiB of a 1.14 GB file | records |
|---|---|
| request | 9,732 |
| response, all HTTP 200 | 9,731 |
| metadata | 9,731 |
| warcinfo | 1 |
| truncated member at the cut | 1 |
Responses: 9,591 HTML (median body 71 KB), 67 PDF. WET, Common Crawl’s text of the same file: 102 MB, one conversion record per HTML page, but none for 151 of ours.
Check
Same file, same crawl, 64 times the bytes.
Answer. Proportion says 285 \times 64 = 18{,}240. Measured: 9,731. The first 4 MiB hold 71 responses per MiB, the range 38. A prefix is a valid sample of records, not a representative one; the 41,000 for the whole file is an extrapolation of the same kind.
Charsets
| link of the chain | HTML pages decided |
|---|---|
Content-Type header |
8,606 |
<meta charset> in the first 4 KiB |
850 |
statistical detector (charset_normalizer) |
125 |
| UTF-8 with replacements | 10 |
Each document’s log records which link decided.
Extractors
| source | mechanism | speed |
|---|---|---|
| WET | all visible text, one line per block | precomputed |
| trafilatura | scores the document tree; FineWeb’s extractor | 1× |
| Resiliparse | C++, main-content rules; DCLM’s extractor | more than 10× |
| naive, ours | dense blocks with few links | several × |
Naive rule, block of t characters with l in links: keep if t \ge 40 and l \le t/3; keep neighbors within 2 blocks if t \ge 15 and l \le t/3.
DCLM: both libraries trained better models than WET text.
Measures
| measure | share found in the output |
|---|---|
| code recall | lines of <pre>/<code> blocks of 3+ lines |
| table recall | cells of 3 to 200 characters |
| math recall | TeX strings |
| prose recall | 5-grams of <p> text, 100+ characters, outside menus |
| precision proxy | output characters on lines of the content elements |
Thresholds were set while looking at this sample: not held out.
Recall by page class
| class (pages) | WET | naive | trafilatura | Resiliparse |
|---|---|---|---|---|
| prose (1,434) | 0.99 | 0.96 | 0.87 | 0.86 |
| code (44) | 0.99 | 0.95 | 0.92 | 0.82 |
| table (391) | 1.00 | 0.24 | 0.61 | 0.73 |
| math (4) | too few | |||
| precision proxy | 0.44 | 0.60 | 0.64 | 0.63 |
Paired, trafilatura − Resiliparse: tables −0.12 [−0.18, −0.06]; prose +0.01, interval includes 0; code too few pages to separate.
WET recalls everything and keeps the menus: more than half of its characters lie outside the content elements.
A second view
1,002 FineWeb rows of the range, joined by record id, never by URL.
| extractor | character-5-gram F1 against FineWeb |
|---|---|
| WET | 0.63 |
| naive | 0.78 |
| trafilatura | 0.92 |
| Resiliparse | 0.76 |
Resiliparse finds more table cells yet agrees less: the reference is trafilatura.
Language identification
Words and character n-grams → embeddings (n-grams hashed) → mean → linear layer → softmax over 176 languages. FineWeb keeps en \ge 0.65.
| text | top labels |
|---|---|
| an English sentence | en 1.00 |
| the same sentence as a code comment | en 0.98 |
| half English, half Spanish | es 0.90 |
Against Common Crawl’s CLD2 labels: mostly diagonal; 40 pages Japanese → Chinese.
Check
Two lines of code with an English comment.
Answer. It is kept as English, at 0.98. The identifier sees English words and ignores the code; a score says how sure it is of the top label, not how much of the text is in that language.
The threshold
threshold on en |
0.50 | 0.65 | 0.80 | 0.90 |
|---|---|---|---|---|
| English documents kept | 3,546 | 3,288 | 2,689 | 1,941 |
| of them in FineWeb | 999 | 997 | 985 | 866 |
Unicode
| on 3,288 English documents | NFC | NFKC |
|---|---|---|
| documents changed | 0 | 619 (19%) |
| code points rewritten | 0 | 7,911 |
| NFKC rewrites | becomes | count |
|---|---|---|
| no-break space, ellipsis | space, ... |
6,245, 949 |
| ″ (double prime), ™ | ′′, TM |
200, 103 |
| ½, mathematical bold 𝐚 | 1⁄2, a |
15, 11 |
x² → x2: NFKC changes formulas and code.
The rule
| é written as | code points | UTF-8 bytes |
|---|---|---|
| U+00E9 | 1 | C3 A9 |
e + U+0301 |
2 | 65 CC 81 |
Personal data
| pattern, 120-string fixture | precision | false positives |
|---|---|---|
| 0.91 | [email protected], [email protected], [email protected]:… |
|
| public IP address | 0.83 | 4.2.1.0, kernel build 5.15.0.91, section 3.4.1.2 |
Rights
With a byte offset in every row, a takedown is the deletion of one row.
The manifest
n_\textrm{in} = n_\textrm{out} + \sum_r \textrm{drops}_r \quad\text{(first rule that fires is charged)}
| stage | in | out | dropped |
|---|---|---|---|
| extract (trafilatura 2.1.0) | 9,731 | 9,286 | not HTML 140, empty 305 |
lang_id (en \ge 0.65) |
9,286 | 3,288 | other language 5,448, low score 550 |
| nfc | 3,288 | 3,288 | — |
| pii | 3,288 | 3,288 | — |
Canonical JSON: sorted keys, floats to 4 decimals, no time stamps, no absolute paths.
Round trip
docs_hash: SHA-256 over the sorted pairs (id, SHA-256 of the text).
| test | result |
|---|---|
| manifest saved and loaded | hash unchanged |
| documents permuted | docs_hash unchanged |
| one character edited | docs_hash changed |
| 3,288 documents rebuilt from rows without text | 0 mismatches, same hash |
A dataset card from the manifest states sources, stages and counts; it cannot say why the corpus exists or whose writing is in it.
Check
A filter stage drops by too_short, then low_quality; 100 documents fire both rules. Swap the order.
Answer. The documents kept, n_\textrm{out} and out_hash stay the same; 100 drops move from too_short to low_quality, and the manifest’s hash changes. The order is part of the stage’s parameters.
Recap
iter_warc matches warcio on 857 of 857.en \ge 0.65: 3,288 documents, 30% of them in FineWeb.Next: which of the 3,288 documents are worth training on, and who checks what a quality filter removes.