No history yet

Data Curation Pipelines

From Raw Data to Model Fuel

A Large Language Model is only as good as the data it learns from. While massive web scrapes like Common Crawl provide petabytes of raw text, this data is messy, redundant, and often low-quality. Feeding it directly to a model would be like fueling a race car with dirty, unfiltered gasoline. The result is poor performance and unreliable behavior.

To prevent this, we build a data curation pipeline. This multi-stage process transforms the chaotic raw data from the web into a clean, structured, and efficient format that a model can actually learn from. It’s less about simply collecting data and more about refining it with surgical precision.

Lesson image

Cleaning the Digital Ocean

The first major task is tackling redundancy. The internet is filled with identical or nearly identical content, from boilerplate legal text in footers to syndicated news articles. Training on this repeated data wastes computational resources and can bias the model.

Finding exact duplicates is simple. The real challenge is finding near-duplicates—texts that are mostly the same but have minor differences. To solve this efficiently at scale, we use a technique based on MinHash.

After deduplication, we apply heuristic filters to improve overall quality. These are rule-based systems designed to discard documents that are unlikely to be useful for training. Inspired by Google's paper, these rules can include:

  • Language Identification: Discarding documents not in the target language(s).
  • Text-to-Code Ratio: Removing pages that are mostly code menus or navigation bars.
  • Word Count: Filtering out documents that are too short or excessively long.
  • Symbol Ratios: Removing text with a high percentage of non-alphanumeric characters or a low percentage of stopwords (like "the", "a", "is").

Finally, we perform safety filtering. This crucial step involves removing or redacting Personally Identifiable Information (PII) like names, email addresses, and phone numbers. We also use classifiers to identify and filter out toxic or harmful content, ensuring the model isn't trained on the worst parts of the web.

Breaking Down Language

With clean data in hand, the next step is tokenization: converting raw text into a sequence of numerical IDs that a model can process. This isn't as simple as splitting by spaces. To handle the vast vocabulary of human language, including misspellings and rare words, models use subword tokenization algorithms.

AlgorithmApproachKey Feature
Byte-Pair Encoding (BPE)Iteratively merges the most frequent pair of adjacent characters or tokens.Starts from individual characters and builds up. Can represent any word.
WordPieceSimilar to BPE, but merges pairs that maximize the likelihood of the training data.Used by BERT and other popular models. Focuses on statistical probability.
SentencePieceTreats the entire input as a raw stream, including spaces.Normalization is reversible, and it doesn't assume spaces are word separators, making it robust across languages.

The choice of tokenization algorithm and, crucially, the vocabulary size (the total number of unique tokens) involves important trade-offs. A larger vocabulary can represent common words with a single token, leading to shorter sequences. This reduces computational load during training and can speed up inference.

Large Vocabulary → Shorter Sequences → Faster Inference, More Memory

However, a larger vocabulary also means the model's final embedding layer, which stores a vector for each token, becomes much larger. This increases the model's memory footprint and parameter count. Conversely, a smaller vocabulary is more memory-efficient but must break down more words into multiple subword tokens, creating longer sequences that require more processing.

Small Vocabulary → Longer Sequences → Slower Inference, Less Memory

Finding the right balance is key. For many models, a vocabulary size between 32,000 and 128,000 tokens has proven to be a practical sweet spot.

After tokenization, the pipeline's final output is a massive collection of tokenized tensors. This is the refined, high-quality fuel, ready to be fed into the model for pre-training.

Time to check your understanding of the data curation pipeline.

Quiz Questions 1/5

What is the primary purpose of using a data curation pipeline before training a Large Language Model?

Quiz Questions 2/5

In the context of data curation, what is the main trade-off when choosing a larger vocabulary size for tokenization?

This structured pipeline is the unsung hero of LLM development, turning the chaotic web into the ordered data that enables models to learn.