0%
AI/ML 2024

AI Document Processing Demo

Tesseract + LayoutLM + FastAPI

Developed intelligent document processing (IDP) demo automating data extraction from unstructured documents using computer vision and NLP. Pipeline: image preprocessing (deskew, denoise) → Tesseract OCR → document classification (ResNet50 CNN) → field extraction (LayoutLM transformer) → validation. LayoutLM understands document layout via position embeddings enabling extraction from variable invoice formats. FastAPI backend processes uploads, React frontend displays extracted fields with confidence scores. Demonstrates production IDP patterns for invoice processing, form digitization.

95%+
OCR Accuracy
96%
Classification
LayoutLM
Model
100+ tested
Documents
4 stages
Pipeline
95% accuracy
Extraction
01

The Challenge

Document processing requires OCR for text extraction, layout understanding for field identification, classification for document types. Tesseract OCR needs preprocessing (deskew, denoise). Variable invoice layouts defeat template matching. LayoutLM transformer understands positional context. Need validation and confidence scores.

02

The Solution

Built multi-stage pipeline: OpenCV preprocessing → Tesseract OCR → ResNet50 classification → LayoutLM field extraction → rule validation. LayoutLM pre-trained on document layouts extracts fields via position embeddings. FastAPI backend, React frontend with drag-drop upload. Confidence scores flag low-quality extractions for review.

Technology Stack

Tesseract 5.3
OpenCV 4.9
PyTorch 2.2+
Hugging Face Transformers
LayoutLM
Python 3.11+
FastAPI 0.109
Celery
Redis 7.2
PostgreSQL 16
React 18
TypeScript 5.x
spaCy 3.7
Pillow
NumPy
Docker 24.0
03

Architecture

  • Multi-stage pipeline: preprocessing → OCR → classification → extraction
  • OpenCV preprocessing: deskew, denoise, binarization
  • Tesseract 5.3 OCR with language models
  • ResNet50 CNN for document type classification
  • LayoutLM transformer for position-aware field extraction
  • spaCy NER for vendor name and address extraction
  • FastAPI async endpoints with Celery background tasks
  • Redis task queue for async document processing
  • React frontend with drag-drop and extracted field display
  • Docker Compose: FastAPI + Celery + Redis + PostgreSQL
04

Key Features

01
OpenCV 4.9 preprocessing: deskew, denoise, binarization, adaptive thresholding
02
Tesseract 5.3 OCR with eng+multi language data
03
ResNet50 CNN document classifier trained on 10 document types
04
LayoutLM-base transformer for position-aware field extraction
05
Table detection and parsing using image processing techniques
06
Named entity recognition with spaCy for vendor names, addresses
07
Business rule validation: amount format, date validation, required fields
08
FastAPI 0.109 async endpoints with Celery task queue
09
React 18 frontend with drag-drop upload and extracted field display
10
Confidence score thresholding for human review flagging
11
Redis 7.2 for task queue and result caching
12
Docker Compose deployment: FastAPI + Celery + Redis + PostgreSQL
05

Results & Impact

  • Multi-stage pipeline: preprocessing → OCR → classification → extraction → validation
  • Tesseract 5.3 OCR with OpenCV preprocessing (deskew, denoise, binarization)
  • ResNet50 CNN document classifier: 96% accuracy across 10 document types
  • LayoutLM-base field extraction: 95% accuracy on invoice test set
  • Processes invoices, receipts, forms extracting vendor, amount, date, line items
  • FastAPI backend with async upload processing and Redis task queue
  • React 18 frontend with drag-drop, extracted field display, confidence scores
  • Tested with 100+ invoice samples from various formats

Explore This Project