Skip to content

5.5 Data

ready≈ 14 hoursNeeds: 4.1
  1. 1 Learn
  2. 2 Bridge & derive
  3. 3 Explore (Data pipeline explorer)
  4. 4 Do
  5. 5 Check

Most of the web is not training data. Common Crawl holds billions of pages: menus, spam, machine-generated lists, other languages and the same article copied a thousand times. FineWeb turns it into 15 T tokens by extracting text from the HTML, keeping English, applying quality filters, and deduplicating, and it measures every choice by training small models on the result (Penedo et al. 2024). CS336 Assignment 4 builds the same pipeline (handout and tests).

Heuristic filters. Gopher’s rules remove pages with too few or too many words, implausible word lengths, many lines trailing off in ”…”, or few alphabetic words (Rae et al. 2021, appendix A). They are cheap and transparent but blunt: they also drop tables, code and poetry. Classifiers trained to recognise reference-quality text are the other common approach.

Deduplication. Repeated text wastes compute and gets memorised (Lee et al. 2022). Lines that repeat across a corpus are mostly boilerplate, so exact line deduplication removes them. Near-duplicate documents need a similarity: the Jaccard similarity of their sets of word n-grams. Comparing every pair is quadratic, so MinHash summarises each set by a short signature whose agreement rate estimates Jaccard, and locality-sensitive hashing compares only documents whose signatures agree on a whole band (Leskovec, Rajaraman and Ullman, chapter 3).

Personal information. Regular expressions mask email addresses, phone numbers and IP addresses. They miss names and addresses and also catch false positives; real pipelines combine several methods and still leak some (CS336 Assignment 4, section on PII).

Why MinHash and banding workstep 1 of 5
  1. hπ(A)=min⁡x∈Aπ(x)h_\pi(A) = \min_{x \in A} \pi(x)

Data pipeline explorer

Deduplication and quality filtering

Static view on small screens. Open this page on a laptop to interact.

stages applied:
#0 coastalnotes.org/tide-pools kept
Home | Recipes | About | Contact
Tide pools form where the sea retreats from rocky shores twice a day,
leaving behind shallow basins of water. The animals that live there
must survive rapid changes in temperature, salinity and oxygen as the
pool warms in the sun. Anemones close up to keep moisture in, while
hermit crabs move between shells as they grow. Visit at low tide, step
only on bare rock, and return any stone you turn over to the place you
found it.
© 2024 Coastal Notes. All rights reserved.
We use cookies to improve your experience. Accept all cookies
#1 coastalnotes.org/kelp kept
Home | Recipes | About | Contact
Kelp forests grow along cold coasts where nutrients rise from the
deep. A single kelp frond can grow half a metre in a day, and the
canopy shelters fish, urchins and sea otters. When otters disappear,
urchins multiply and graze the forest down to bare rock. Questions
about our guided snorkel trips can go to |||EMAIL_ADDRESS||| or
call |||PHONE_NUMBER||| between nine and five on weekdays.
© 2024 Coastal Notes. All rights reserved.
We use cookies to improve your experience. Accept all cookies
#2 seaside-digest.net/tidepools removed: near-duplicate of #0
#3 deals4u.biz/win removed: word count
12 words · mean length 4.4 · 100% alphabetic · 0% of lines end in …
#4 stats-dump.info/table removed: alphabetic words
116 words · mean length 3.7 · 25% alphabetic · 0% of lines end in …
#5 top10-lists.com/beaches removed: lines ending in …
118 words · mean length 3.8 · 93% alphabetic · 100% of lines end in …
#6 breadlab.example/basic-loaf kept
Good bread needs only flour, water, salt and time. Mix the dough, let it rest
for half an hour, then fold it every thirty minutes for two hours to build
strength without kneading. Shape the loaf, let it rise overnight in the fridge,
and bake it in a very hot covered pot. Our recipe server at |||IP_ADDRESS||| hosts
printable versions of every step, with timings for different flours.
#7 mirror.breadlab.example/basic-loaf removed: near-duplicate of #6
#8 spokes-and-chains.org/chain-care kept
A bicycle chain wears slowly and stretches as its pins and rollers wear,
and a stretched chain grinds down the cassette and chainrings. Measure it
every few months with a simple chain checker. Clean the chain with a rag,
apply one drop of lubricant to each roller, and wipe off the excess so that
dirt has nothing to stick to. A new chain costs far less than a new
drivetrain.
#9 link-farm.example/index removed: mean word length
56 words · mean length 59.3 · 100% alphabetic · 0% of lines end in …
000.250.250.50.50.750.7511#0 and #1: J = 0.07#0 and #2: J = 0.74, candidate#0 and #6: J = 0.00#0 and #7: J = 0.00#0 and #8: J = 0.00#1 and #2: J = 0.00#1 and #6: J = 0.00#1 and #7: J = 0.00#1 and #8: J = 0.00#2 and #6: J = 0.00#2 and #7: J = 0.00#2 and #8: J = 0.00#6 and #7: J = 1.00, candidate#6 and #8: J = 0.00#7 and #8: J = 0.00x: Jaccard similarity · y: P(candidate)
100 hashes; steepest near s ≈ (1/b)1/r = 0.55 P(candidate) at J = 0.5: 0.470, at J = 0.9: 1.000 candidates found: 2, merged (J ≥ 0.70): 2
afterdocumentswords
raw crawl10784
quality6482
MinHash4330
line dedup4282

Ten pages from an imaginary crawl. The quality filter applies the Gopher rules and says which rule a page failed. MinHash then compares 5-word shingles: #2 is #0 syndicated, rewrapped with a different header, and #7 is an exact mirror of #6. Dots on the S-curve are the pairs of pages that passed the filter, filled when LSH made them candidates; only candidates are checked against the threshold. Raise r to make the curve steeper and later, raise b to move it left. Exact line deduplication across what remains then strikes out the site's shared menu and footer, which would otherwise be repeated in every page it crawled. Last, email addresses, phone numbers and IP addresses are masked.

Left: ten sample web pages, each marked kept or removed with the reason, after the stages chosen with the buttons: quality filter, MinHash deduplication, exact line deduplication and PII masking. Removed lines are struck through and masked text is highlighted. Right: the LSH S-curve, the probability that a pair of pages becomes a candidate against its Jaccard similarity, for the rows per band, bands and threshold set with sliders, with one dot per pair of pages that passed the filter. Below it, a table of pages and words left after each stage. Keyboard: Tab to a stage button and press Enter; Tab to the sliders and use the arrow keys.
PII masking, quality filters and deduplication stubs/m5_5_data.py

Loading starter file…

Prefer your own editor? Edit exercises/stubs/m5_5_data.py and run mlc check 5.5. The tests are identical; import the results on the progress page.

Hints · exact_line_dedup 0/3 revealed
Hints · lsh_candidates 0/3 revealed
Hints · minhash_dedup 0/3 revealed

Then run it on real web text. Open notebooks/5.5-data-pipeline.ipynb on Kaggle (no GPU needed, internet on) and paste in your file. It streams 3,000 pages from one Common Crawl WET file, keeps English with fastText’s language identifier, and runs your filters and deduplication, printing what each stage removed. Look at the removed pages: do you agree with each decision?

1. Two documents agree in 60 of 100 MinHash positions. What does that estimate?
2. With more rows r per band (and the same number of bands), the LSH S-curve…
3. Why does exact line deduplication remove boilerplate?
4. Which page would the Gopher rules most likely remove wrongly?
  • not yet: All tests pass (0/?)
  • not yet: Checkpoint quiz ≥ 80%
Finish the items above first.
Learner log: time spent and points of confusion

Every confusion you note becomes a fix before the module is marked stable. Export it from the progress page and attach it to an issue.