OCR & Document AI
OCR is two problems, not one
Optical Character Recognition (OCR) sounds like a single task — turn an image of text into actual text — but it's really two problems stacked together. First, text detection: finding the regions of an image that contain text at all, which is itself a detection/segmentation problem over an image that might contain photos, tables, logos, and handwriting mixed in with printed text. Second, text recognition: converting each detected text region into actual character sequences.
A scanned receipt, a street sign photographed at an angle, and a page from a PDF are all "text in an image," but they stress very different parts of the pipeline — skewed perspective, inconsistent fonts, poor lighting, and overlapping content all break naive approaches differently.
The classical OCR pipeline
Traditional OCR engines followed a fairly rigid sequence: binarize the image (convert to pure black and white to separate ink from background), detect and deskew text lines, segment each line into individual characters, then classify each isolated character against a template or simple classifier, and finally run the raw character output through a language model or dictionary to fix likely mistakes (e.g., correcting "rn" misread as "m"). This worked reasonably well on clean, scanned, single-font documents, but degraded badly on photographed text, unusual fonts, or any layout more complex than a single column of text.
Neural OCR: detection and recognition as learned networks
Modern OCR replaces each classical stage with a trained neural network. Text detection uses the same object-detection and segmentation techniques covered earlier — predicting bounding boxes or pixel masks around text regions, rather than relying on hand-tuned binarization rules. Text recognition typically uses a CNN to extract visual features from each cropped text region, followed by a sequence model (an RNN, or increasingly a transformer) that reads out the character sequence — directly handling variable-length text without needing to segment it into individual characters first, which was always the most fragile step in the classical pipeline.
This end-to-end neural approach is why modern OCR tolerates skewed photos, varied fonts, and low contrast far better than older template-matching engines ever could — it was trained on exactly that kind of messy, real-world variation.
Beyond plain text: layout matters
Extracting correct characters is often not enough. An invoice isn't just text — it's text arranged into meaningful structure: this number is a total, that block is an address, this grid is a table with rows and columns. Reading the characters correctly but losing that structure (for example, flattening a two-column layout into one jumbled stream of text) can make the extracted output nearly useless for downstream processing like automated invoice entry.
Document AI is the broader field addressing this: understanding not just *what* the text says but *where* it sits and *what role* it plays on the page — labels, values, headers, table cells — so that extracted information can be used programmatically rather than just read.
Note
OCR vs. full document AI
| Capability | Plain OCR | Document AI |
|---|---|---|
| Output | Flat text string per detected region | Structured fields with position and semantic role |
| Handles tables/forms | Poorly — structure is lost | Explicitly models rows, columns, key-value pairs |
| Understands field meaning | No — purely visual/character level | Yes — combines vision and language signals |
| Typical use case | Digitizing scanned text for search | Automated invoice/form/contract data extraction |
What's next
OCR and document AI are applied computer vision and language problems. The remaining lessons shift focus to the practical data science toolkit — starting with NumPy Fundamentals for Machine Learning, the array library almost every other tool in this track is built on top of.
I build these systems professionally.
Whether it's a RAG pipeline, analytics migration, or AI workflow — let's talk.