4.3.4 · HinglishPretraining & Fine-Tuning LLMs

Pretraining data curation and cleaning

2,616 words12 min readRead in English

4.3.4 · AI-ML › Pretraining & Fine-Tuning LLMs


WHY curate at all?


The pipeline (WHAT the stages are)

Figure — Pretraining data curation and cleaning

HOW each stage works (derived from first principles)

1. Language identification

2. Quality filtering — deriving a heuristic score

3. Deduplication — deriving why and how

Exact dedup (WHAT): har document ko hash karo; repeats drop karo. , lekin sirf byte-identical copies pakad sakta hai.

Near-dedup via MinHash + LSH (HOW, from scratch):

4. Content & PII filtering

5. Decontamination

6. Domain mixing / upsampling


Worked examples


Common mistakes (Steel-manned)


Active recall

Recall Feynman: explain to a 12-year-old

Socho tum flashcards bana rahe ho padhne ke liye, lekin tumhare papers ke dher mein bahut saare duplicate cards hain, kuch cards sirf ads hain, aur kuch mein actual test ke answers kisi ne daal diye hain. Agar tum yeh sara dher memorize karo toh duplicates par time waste hoga, ad-slogans seekhoge, aur test answers memorize karke cheat hoga (toh real test mein actually kuch nahi kar paoge). Data cleaning duplicate cards, ad cards, aur sneaked-in test answers ko nikaal dena hai, taaki jo bacha woh actually sochna sikhaye. "Thoda alag likha same card" pakadne ke liye hum ek clever trick use karte hain (MinHash): hum har card ko ek random lottery number dete hain aur check karte hain ki kya do cards same winning number baar baar draw karte hain — jitna zyada karte hain, utne zyada same hain.


Flashcards

Curation ko "token-budget allocation" kyun kaha jaata hai?
Fixed compute = fixed tokens; ek junk token remove karne se ek achha token add ho sakta hai, isliye cleaning directly budget ko useful data ki taraf reallocate karti hai.
Symbol-to-word ratio define karo aur uska filter rule batao.
; wale docs drop karo kyunki junk/SEO pages symbols spam karte hain.
MinHash identity state karo.
, yani Jaccard similarity.
MinHash identity hold kyun karta hai?
The global minimum hash over uniformly likely hai kisi bhi element ke liye; yeh mein land karta hai (mins ko agree karata hua) probability ke saath.
LSH candidate probability formula kya hai?
for bands of rows; yeh ek S-curve hai.
LSH ka exact 50% crossover similarity kya hai?
, solve karke. Rule sirf ek approximation hai.
Near-dedup kyun use karo, exact dedup hi kyun nahi?
Zyaatar web duplication mein ads/ek word ka fark hota hai; exact hashing near-duplicates miss kar deta hai jo MinHash/LSH pakad leta hai.
Decontamination kya hai aur ek typical rule kya hai?
Pretraining docs jo eval benchmarks ke saath overlap karte hain unhe remove karna; jo docs kisi benchmark example ke saath 13-gram share karein unhe drop karo.
Kisi domain par effective epochs ka formula.
; upsampling karte waqt memorization se bachne ke liye ise ~4 se neeche rakho.
Steel-man: "filter harder hamesha better hai" kyun galat hai?
Yeh narrow style ki taraf bias karta hai, diversity khatam karta hai, aur token budget ko scaling-law needs se neeche shrink karta hai; soft filters use karo jo downstream validate hoon.
Dedup privacy mein kaise help karta hai?
Kam repeated strings ka matlab hai model specific documents/PII memorize aur regurgitate karne ki bahut kam probability rakhta hai.
hashes ke saath MinHash Jaccard estimate ki variance kya hai?
Approximately ; badhne se kam hoti hai, isliye hundreds of hashes use karo.
Language ID mein argmax ki jagah threshold kyun?
Ek threshold target language ke liye recall vs precision trade karta hai aur low-confidence, code-switched, ya short docs ko discard karta hai.

Connections

  • Scaling Laws for LLMs — curation decide karta hai ki budget mein kitne useful tokens fit honge.
  • Tokenization — cleaning text par hoti hai; tokenizer stats cleaned corpus par depend karte hain.
  • Deduplication and Memorization — dedup verbatim memorization/privacy leakage reduce karta hai.
  • Benchmark Contamination — decontamination eval validity protect karta hai.
  • Data Mixture and Domain Weighting — upsampling weights .
  • MinHash and LSH — near-dedup ki machinery.
  • Fine-Tuning and Instruction Data — baad ka, chhota, higher-quality curation stage.

Concept Map

is ~90% junk

goal

remove junk token = add good token

stage 1

p lang gt threshold

heuristic + model scores

remove copies

drop toxic PII

drop eval overlap

reweight domains

uses

uses

prevents

prevents

Raw web dump C0

Curation pipeline

Token-budget allocation

Better model per compute

Language ID

Quality filtering

Deduplication

Content / safety filter

Decontamination

Mixing / upsampling

Clean corpus Cn

Symbol-to-word ratio r_sym

Repetition penalty

Wasted capacity on duplicates

Benchmark contamination