Clean OCR output into a training dataset for an LLM
I was asked this
No reports yet. Sign in to say where you were asked it.
An AI/ML design interview question asked in Microsoft's system design round, last asked Feb 2026. It tests ocr, data cleaning and llm training.
You have a large amount of text produced by OCR from scanned documents: broken words, misread characters, page headers and footers mixed into the text, columns read in the wrong order, and some pages that are pure noise. Design the pipeline that cleans it and turns it into a dataset for training a language model, including the option of training a model to correct OCR text, and show that the result helps.
Requirements
- Functional: normalise and clean text; remove layout noise; fix or drop garbled passages; deduplicate; filter by quality; produce training examples (plain text for pretraining, or noisy-to-clean pairs for a correction task); hold out evaluation data.
- Non-functional: runs over millions of pages; reproducible, with each rule's effect measurable; does not drop rare but valid content (tables, other languages, technical terms).
Clarifying questions
- What is the dataset for: continued pretraining, fine-tuning a correction model, or both?
- Do we have the page images and OCR confidence scores, or only the text?
- Which languages and document types?
- Is any clean ground truth available, even for a small sample?
- What licensing or privacy limits apply (personal data in scans)?
What a strong answer covers
- Normalisation: Unicode, hyphenation across line breaks, joined or split words, whitespace and reading order.
- Layout noise: detecting repeated headers, footers and page numbers across pages; using OCR boxes and confidence when available.
- Quality filtering: character and word-level heuristics (ratio of dictionary words, symbol density), a language model's perplexity, and OCR confidence, with thresholds tuned on a labelled sample.
- Deduplication: exact and near-duplicate (MinHash) across documents and editions.
- For a correction model: pairs from the noisy OCR and a clean version (aligned ground truth, or synthetic noise applied to clean text that mimics real OCR errors), with loss masked to the target.
- Evaluation: character and word error rates against ground truth, a small model trained with and without the cleaned data compared on fixed tasks, and checking that filters did not remove valid content.
Follow-ups
- A filter removes most tables and math. How do you notice, and what do you do?
- How do you create clean targets when there is no ground truth?
- Would you rerun OCR with a better engine instead of cleaning? How would you decide?
- How do you handle personal information found in the scans?
Where it's asked
- Microsoft · System design · Last asked Feb 202660 min · Design discussion
What it tests
ocr · data cleaning · llm training
No official answer yet. Draw yours on the right; publish it and it shows under Community.
Nothing published yet. Publish your canvas and it shows here for others to open and remix.
