Document Extraction from Web Crawls

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

One Page, Three Texts: WET Keeps 3,000 More Characters Than FineWeb

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.

By the End of This Deck You Can

Goals

  • read a WARC file record by record from a byte range, and check the reader;
  • decode a page by a logged chain of charset evidence;
  • measure what an extractor loses on prose, code and tables, without a reference extractor;
  • set a language threshold, and say what its score is not;
  • choose a Unicode normalization and a PII rule, and name their failures;
  • write a manifest whose hash names the corpus.

Running example: the first 256 MiB of one Common Crawl archive file of January 2025, and FineWeb’s text for the same records.

Six Steps From a Crawl Record to a Token on Disk

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
  • Here: bytes → records → characters → text → English → NFC → scrubbed, each step in one manifest.
  • Skips: quality, duplicates, tokenization.

Each Record Is Its Own Gzip Member, So Any Byte Prefix Is a Valid Sample

WARC

type offset compressed bytes
warcinfo 0 471
request 471 432
response 903 1,903
metadata 2,806 424
request, response, metadata, … 3,230 …
  • An HTTP 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.

Two Records in Three Are Not Documents

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: 285 Responses in the First 4 MiB. How Many in 256 MiB?

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.

Decode by Evidence, Not by Assuming UTF-8

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
  • A declared charset counts only if it decodes with at most 1 U+FFFD per 1,000 characters.
  • UTF-8 read as Latin-1: wrong letters, no error.

Each document’s log records which link decided.

Four Texts per Page: One Keeps Everything, Three Guess the Article

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.

Score Extractors Against Strings Read From the HTML, Not Against Another Extractor

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
  • Pages: English by their HTML, score \ge 0.65; no extractor chooses them.
  • Intervals: bootstrap over registered domains (one site counts once).

Thresholds were set while looking at this sample: not held out.

Extractors Differ Most on Tables; on Prose the Two Libraries Agree

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.

Agreement With FineWeb Is Closeness to Its Pipeline, Not Accuracy

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
  • FineWeb’s text is trafilatura’s, with other settings (precision first, no comments) and addresses replaced: mask both sides before comparing.

Resiliparse finds more table cells yet agrees less: the reference is trafilatura.

fastText’s Score Is a Preference Among 176 Labels, Not P(English)

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: Your Filter Keeps en ≥ 0.65. What Happens to a Python File?

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.

Raising the Threshold to 0.8 Removes 857 Documents, 14 of Which FineWeb Kept

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
  • At 0.65: 30% of our English documents are in FineWeb; quality filters and deduplication removed the rest.
  • A low score tends to mark pages that later filters drop anyway.

NFC Changes No Document; NFKC Rewrites One in Five

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.

Normalize Once, With NFC, Before Any Tokenizer; Count Bytes After It

The rule

é written as code points UTF-8 bytes
U+00E9 1 C3 A9
e + U+0301 2 65 CC 81
  • A byte-level tokenizer sees bytes: two identical-looking documents give different tokens.
  • Bits per byte divides by the byte count, so it must be the count of the normalized text, the same for every tokenizer compared.
  • Keep the zero-width joiner: in Devanagari it selects a half-form.

Two Regular Expressions Remove Addresses, and Also Version Numbers

Personal data

pattern, 120-string fixture precision false positives
email 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
  • Recall 1.0 by construction: the fixture was written with the rules.
  • On c0, unchecked rule matches: emails in 173 documents, IPs in 8.
  • No rule finds names, street addresses or a diagnosis in prose.

Common Crawl Is an Archive, Not a Licence

Rights

  • Public is not permitted: copyright and site terms still apply.
  • Consent in Crisis (2024): restrictions on AI crawlers spread within a year, most among actively maintained sites.
  • The Stack v2: a licence per file, opt-out repositories removed before each release.
  • This book ships a pin (URL, range, SHA-256 per 16 MiB), ids, offsets and hashes; the text is rebuilt from Common Crawl.

With a byte offset in every row, a takedown is the deletion of one row.

Every Stage Balances: 9,731 Responses Become 3,288 Documents

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.

A Hash Names the Corpus: Same Decisions, Same Hash, on Any Machine

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: Swap the Order of Two Drop Rules. What Changes?

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

Recap

  • 256 MiB: 29,195 records, 9,731 responses; iter_warc matches warcio on 857 of 857.
  • Tables separate the extractors (Resiliparse 0.73, trafilatura 0.61, naive 0.24); prose does not; WET’s precision proxy 0.44.
  • Agreement with FineWeb: trafilatura 0.92, the others 0.63 to 0.78, closeness to a pipeline, not accuracy.
  • At en \ge 0.65: 3,288 documents, 30% of them in FineWeb.
  • NFC changes none, NFKC 19%; the PII rules also hit version numbers.
  • The manifest balances every stage and rebuilds c0 with 0 mismatches.

Next: which of the 3,288 documents are worth training on, and who checks what a quality filter removes.