KatInterview

Building a Pipeline to Curate Math Training Data from Web Crawls

System DesignModel answer
HardModel answerSystem Designml-system-designdata-pipelineocr

Last updated

Design a daily batch pipeline that turns 100 TB of noisy HTML, PDF and image crawl data into a deduplicated, safe, high-rigor mathematical text corpus for LLM pretraining.

Scenario

Your team trains large language models and wants more high-quality mathematical text: definitions, theorems, proofs, worked derivations and solved problems. The source is a stream of web crawl output that arrives every day as HTML pages, PDF files and standalone images. Most of it is not math. What is math is often badly extracted, repeated across mirrors, or of low quality (broken OCR, symbol soup, thin content).

What you need to build

A batch system that ingests the daily crawl and publishes a clean, versioned, training-ready math corpus.

Functional goals

  1. Extraction. Convert the different formats into one normalized text representation, with equations preserved in a usable form.
  2. Quality scoring. Detect mathematical content and rank it by rigor and value, favoring documents with real definitions, arguments and derivations.
  3. Safety and deduplication. Remove exact and near-duplicate documents, and filter out copyrighted material.

Scale and constraints

  • About 100 TB of raw data per day.
  • The pipeline is batch, not real time, but it must keep up with daily volume at a sensible cost.
  • The final corpus must have a high signal-to-noise ratio. Precision matters more than recall, so borderline documents may be dropped.

What to cover in your answer

  • Data pipeline: the stages from raw crawl to final corpus, and how you control cost at this scale.
  • Modeling: how you would approach document classification, OCR/extraction of math, and quality scoring, including how you get training labels.
  • Storage and indexing: how documents, metadata and versions are stored so that any model's training set can be reproduced.
  • Monitoring: how you detect drift and protect training-set quality over time.

State your assumptions and do some back-of-envelope sizing.

Hints

Hint 1

Do the arithmetic first: 100 TB/day is on the order of a billion documents. Expensive steps like GPU OCR or LLM scoring cannot run on all of them, so think of a funnel where each stage is costlier and sees far fewer documents.

Hint 2

Extraction is where math pipelines quietly lose quality. Generic boilerplate removers drop MathML, MathJax and KaTeX content, and PDF text layers are often garbled. Plan format-specific paths and a fallback to math-aware OCR only for documents likely to be worth it.

Hint 3

Labels and thresholds: use a strong LLM with a rubric to label a sample, check it against a small set of human expert labels, and distill into cheap classifiers. Pick filter thresholds by training small proxy models and measuring downstream math benchmarks, and do not forget benchmark decontamination and a persistent cross-day near-duplicate index.