6 Steps to AI-Ready Data Sets

See how to prepare AI-ready LLM training data sets with filtering, deduplication, and data blending to improve model quality and support enterprise AI.


Summary

This article walks through how to build AI-ready LLM training data sets using proven data preparation techniques that improve model accuracy and accelerate enterprise AI adoption.

image_pdfimage_print

Welcome back to our technical how-to series on AI. In this installment, we’ll go through a step-by-step walkthrough to turn data sources into a clean, deduplicated, well-blended training corpus. In essence, covering the process frontier labs use before training an LLM.

The quality of training data is the single biggest lever for model quality. A smaller model trained on well-curated data routinely outperforms a larger model trained on raw web crawls. The DCLM paper demonstrated that switching from heuristic-only filtering to model-based quality filtering improved downstream task accuracy by 6.6 percentage points, with the same model architecture and training budget.

Every frontier lab—OpenAI, Anthropic, Google, Meta—invests heavily in data pipelines before a single training run begins.

Step 1: Download data sources

We start by pulling raw text from four open, high-quality sources that mirror what frontier labs use. Each source is streamed from HuggingFace using the “datasets” library and saved as a JSONL file (one JSON object per line, with “text,” “source,” and “url” fields).

Source

HuggingFace Dataset

Why We Use It

FineWeb-Edu

HuggingFaceFW/fineweb-edu-score-2

Best-quality filtered web text with an educational focus

DCLM-Baseline

mlfoundations/dclm-baseline-1.0

Broad high-quality web, filtered with a GPT-4-style classifier

Wikipedia

wikimedia/wikipedia

High-precision factual grounding—the gold standard

Books (PG-19)

emozilla/pg19

Long-range coherence and narrative from Project Gutenberg

We download ~1.7M items per source for a Chinchilla-optimal data set.

Step 2: Safety and PII filtering

This runs before quality scoring on purpose. A well-written military manual would score high on quality—we need to remove dangerous content before any quality classifier ever sees it.

Harmful content blocking

Pattern matches for weapon synthesis instructions (e.g., nerve agents, explosives) and CSAM indicators. The check is applied to the first 5,000 characters of each document. Any match means the entire document is discarded.

PII detection and redaction—a three-tier policy

The pipeline applies a tiered approach to personally identifiable information (PII):

  1. Hard discard: Documents containing Social Security numbers or credit card numbers are removed entirely—these are too sensitive to redact.
  2. Density discard: If the total PII character count exceeds 1% of the document length, the document is discarded. A page that is mostly phone numbers and email addresses is likely a data dump, not useful training text.
  3. Redaction: For documents with low-density PII (a stray email address, a phone number in a contact section), the PII is replaced with placeholders: “[EMAIL],” “[PHONE],” “[IP],” etc. The document is kept.

The five PII types detected are: email addresses, US phone numbers, US SSNs, credit card numbers (Visa, Mastercard, Amex, Diners), and IPv4 addresses.

Everything else passes through

The vast majority of documents are clean and go straight to the next step. We log per-file statistics to show how many documents were blocked, discarded, redacted, or passed clean.

Step 3: Heuristic filters

These are the cheapest filters in the pipeline, pure CPU string operations. Their job: Throw away documents that are obviously not useful text before we spend compute on the quality classifier.

Based on the Gopher paper—the same rules used by FineWeb, DCLM, Dolma, and RedPajama:

Filter

Threshold

What It Catches

Too short

< 300 characters

Stubs, error pages, empty wrappers

Too long

> 100,000 characters

Data dumps, log files

Too few words

< 50 words

Nav bars, footers, cookie banners

Mean word length abnormal

< 3 or > 10 chars/word

SEO spam, base64-encoded data

No sentence-ending punctuation

Missing “.,” “!,” or “?”

Not prose (code dumps, tables)

Mostly bullet points

> 90% bullet lines

Lists without context

High ellipsis lines

> 30% of lines end in “…”

Clickbait, spam

Too many digits

> 15% digit characters

Data tables, phone directories

Too much punctuation

> 15% punctuation characters

Decorative text, ASCII art

Duplicate lines

> 30% of lines are duplicates

Repeated headers/footers, boilerplate

Repetitive 5-grams

> 60% of character-level 5-grams are repeated

Template-generated pages, SEO filler

Text normalization

Before applying filters, every document is normalized:

  • Encoding fixes via “ftfy” repairs mojibake, broken Unicode, and HTML entities
  • Unicode NFC normalization ensures consistent representation of accented characters
  • Whitespace cleanup collapses runs of three or more newlines into double newlines

The normalized text is passed downstream so the following steps work with clean text.

Step 4: Quality classifier (DCLM)

This is the core third-generation technique that separates modern pipelines from the heuristic-only era. We train a fastText classifier to distinguish high-quality text from mediocre web text.

We use the approach from DCLM, the best-performing open quality filter as of 2024.

How it works

  1. Build training data. The classifier needs labeled examples:
  • Positive class (“__label__hq”): Wikipedia text from the heuristic-filtered output. 
  • Negative class (“__label__lq”): Random web text sampled from FineWeb-Edu and DCLM-Baseline files.

Each example is truncated to 500 characters. A 95/5 train/validation split is applied. In our labs, we used 20,000 examples per class.

2. Train a fastText classifier. The model is lightweight and trains on CPU in seconds. Validation precision and recall are logged so you can sanity-check the model before it filters your corpus.

3. Score every document. Each document’s first 512 characters are scored on a 0–1 scale. Documents scoring below 0.5 (the DCLM baseline threshold) are discarded. The score is saved as “dclm_score” in the output for later analysis.

Typical retention: 10%–30% of web text passes. Wikipedia passes almost entirely (it is similar to the positive training data). This is by design—the classifier learns to prefer Wikipedia-like writing quality. The trained classifier model is saved and reused on subsequent runs.

Step 5: Deduplication and contamination removal

Deduplication has the highest ROI of any single pipeline step. A few duplicate copies of a document barely matter, but heavy duplication causes memorization and inflated benchmark scores.

The approach is a streaming, memory-efficient architecture: Documents flow through disk-backed intermediate files rather than being loaded entirely into RAM. Temporary files are cleaned up automatically when the step completes.

Layer 1: Exact hash dedup (SHA-256)

Each document’s text is whitespace-normalized (collapsed to single spaces, lowercased) and hashed with SHA-256. If two documents produce the same hash, only the first is kept. Only the set of hash digests lives in memory; documents themselves stream through disk.

Layer 2: MinHash LSH (near-duplicate detection)

Approximates Jaccard similarity between documents using five-word shingles and 128-hash permutations. Documents sharing more than 70% of their shingles are considered near-duplicates. The LSH index is built per file and freed before processing the next file to manage memory.

In our implementation, we use the “datasketch” library’s “MinHash” and “MinHashLSH” classes. This step catches reworded copies, boilerplate-heavy pages, and syndicated content with minor edits.

Layer 3: Eval set contamination removal

Before finalizing training data, we check for overlap with evaluation benchmarks. We build a set of 13-word n-grams from up to 2,000 examples each from HellaSwag and MMLU (streamed from HuggingFace). If more than 10% of a document’s 13 grams match the eval set, the document is discarded.

Without this step, your benchmark scores are inflated—the model has “seen the test.” This is the standard approach used by GPT-3 and Llama.

Step 6: Blending, Packing, and Corpus Card

The final step transforms clean, deduplicated sources into training-ready data.

Blending

If you concatenate all sources naively, web text dominates at 90%+. Overrepresenting books and Wikipedia—even though they are a tiny fraction of total tokens—measurably improves coherence and factual accuracy. This mirrors Llama 3, Falcon, and Gemma data mixing decisions.

The blend weights (must sum to 1.0):

Source

Weight

Role

FineWeb-Edu

40%

Best-quality filtered web

DCLM-Baseline

25%

Second high-quality web source

Wikipedia

20%

High-precision factual grounding

Books PG-19

15%

Long-range coherence

The blending is done by streaming: We count lines in each source file, pre-compute a random set of line indices to keep for each source (proportional to the blend weight), then stream through each file writing only the selected lines. Only the index sets live in memory, not the documents.

After blending, the corpus is shuffled. The shuffle is also memory-efficient: Only byte offsets of line boundaries are stored in RAM, shuffled, then lines are read back in the new order.

Document packing into WebDataset shards

Documents are concatenated end to end with an “<|endoftext|>” (EOD) marker between them. The concatenated stream is then sliced into fixed-length token-based chunks (2,048 tokens in our setup).

The packed chunks are written as WebDataset tar shards using the “webdataset” library. Each shard contains up to 10,000 chunks. This format is widely used for large-scale distributed training because tar files can be streamed sequentially from disk or cloud storage without random access.

Corpus card

The last element is to save a JSON metadata file documenting exactly what went into the corpus: sources, licenses, filter thresholds, PII policy, dedup settings, document counts, and token counts. This is required by the EU AI Act (2025) for frontier models and is essential for reproducibility.

Summary

Preparing a well-balanced data set for model training is more than just an accumulation of data; it requires a well-thought-out multi-step pipeline to:

  1. Download sources          
  2. Implement safety and PII filtering    
  3. Apply heuristic filters        
  4. Train a quality classifier 
  5. Remove deduplication 
  6. Blend, pack, and  finalize

Everpure Data Stream reduces the complexities of data wrangling such pipelines, and enables an enterprise-grade end-to-end NVIDIA AI Data Platform experience. Get in touch to schedule a demo. 

For further reading, check out these key papers:

  • DCLM: Model-based quality filtering at scale; the approach used in Step 4
  • FineWeb: HuggingFace web curation pipeline; one of our data sources
  • Gopher:  Appendix C details the heuristic filters implemented in Step 3
  • Deduplicating Training Data: Foundational work on dedup for LLM training
  • DoReMi: Learned domain mixing weights (the theory behind Step 6 blending)
  • Dolma: Fully documented open pipeline, good reference implementation