KatInterview

Building a Training Set for an OCR Error-Correction Model

Machine LearningModel answer
MediumModel answerMachine Learningllm-fine-tuningdata-pipelinesynthetic-data

Last updated

Design a scalable pipeline that scores noisy OCR pages, distills a small verified gold set from a stronger LLM, and filters out pages too degraded to repair.

Scenario

Your team has scanned 100,000 document pages and run them through an OCR engine. The text that comes out is messy:

  • characters are swapped for lookalikes (l vs 1, O vs 0),
  • line breaks fall in the wrong places and words get split,
  • low-contrast regions produce characters that are not on the page at all.

You want to fine-tune a compact language model to act as an OCR post-correction model: it reads noisy OCR text and returns the corrected text. Almost none of the pages have reference transcriptions.

Task

Propose an end-to-end approach for turning this raw material into a fine-tuning corpus. Cover three areas:

  1. Cleaning and detection. Which heuristic rules or statistical signals would you use to flag low-confidence OCR segments? How would you treat artifacts such as repeated characters and unnatural word splits?
  2. Gold data from a stronger model. With no ground truth for most pages, how would you use a much larger LLM as a teacher to build a smaller, trustworthy dataset for fine-tuning the target model?
  3. Filtering hopeless pages. What metric or classifier would you use to discard pages so degraded (blurry, distorted, garbled) that even a strong model cannot recover them?

Example

Input: The 1nvestment was 500,000 dol1ars in 202O.

Expected output: The investment was 500,000 dollars in 2020.

Constraints

  • The target model has a 4,096-token context window.
  • Weigh the cost of calling a proprietary LLM API on every page against labeling only a sample.
  • The approach must scale to repositories measured in multiple terabytes.

State any assumptions you make, and discuss trade-offs and failure modes.

Hints

Hint 1

Separate cheap scoring and routing (runs over everything) from expensive correction (runs only on a small sample). Do a quick token-count estimate to see why labeling the whole corpus with an API is impractical.

Hint 2

A teacher model's output is not ground truth. Think about checks you can run automatically: how much it changed, where it changed things, whether repeated samples agree, and whether digits only changed in plausible ways.

Hint 3

Real noisy/clean pairs can be manufactured by rendering clean text, degrading the image, and re-running the same OCR engine. Also think about what happens if the student never sees clean text that should be left alone.