Gradient LabSign up free

Trending › OCR model

OCRia-nano: reading documents with 8.1M parameters on a CPU

LlamaIndex released open weights for OCRia-nano-1: seven tiny models, 8.1M parameters in total, that turn PDFs and scans into Markdown on a single CPU core in about 0.4 seconds a page. A lesson in splitting one hard job into small specialists and distilling from a big model.

Watch it move. This is an animated lesson on Gradient Lab.

Start the animated lesson

Step by step

Concept

From a page to clean text

Before a RAG system can search a contract or an invoice, something has to turn the page into text with its structure intact: headings, lists and tables. Big vision models do this well but need GPUs. OCRia-nano-1 does it on a CPU with 8.1 million parameters.

A page goes in; Markdown text comes out.

Build

Skip OCR when you can

Many PDFs already contain their text. For those, the tool reads the text layer directly, which is fast and exact. Only scanned pages or photos, which are just pixels, go through OCR.

Two routes: digital PDFs (fast lane) and scans (OCR lane).

Key idea

Seven small specialists

Instead of one big model, OCRia-nano chains small ones: a line detector finds text lines, a script router decides which writing system each line uses, one of four recognizers reads it, and LayoutNet (4.3M parameters) rebuilds tables and blocks from the words, their positions and the image.

Block sizes roughly follow parameter counts.

Build

Learn from a big teacher

Where do tiny models get good labels? LlamaIndex used its 4-billion-parameter OCRia-1 to produce transcriptions, table annotations and layout labels, then trained the small models to copy them. This is distillation, a form of transfer learning.

The big teacher writes the answers; the small students learn to match them.

Insight

Fast, with clear limits

LlamaIndex reports about 426 ms per page on one CPU core and 59.2 overall on its ParseBench-2 benchmark, and says it beats Tesseract, Marker and PP-OCRv6 tiny on tables and layout. It has no chart model, so charts stay as images; for handwriting, charts and maths the company points to its bigger models.

Speed per page on a single CPU core, as reported by LlamaIndex.

Quick check: What does distillation mean here?

Pseudocode

def parse(page):
    if page.has_text_layer:              # digital PDF: just read the text
        words = read_text_layer(page)
    else:                                 # scan or photo: run OCR
        lines = line_detector(page)       #  82k parameters
        for line in lines:
            script = script_router(line)  #  38k: Latin? CJK? right-to-left?
            words += recognizer[script](line)   # 0.7-1.3M each
    blocks = layout_net(words, page)      # 4.3M: tables, headings, lists
    return to_markdown(blocks)

Go deeper

Sources

  1. LlamaIndex: Introducing OCRia-nano-1
  2. LlamaIndex: Introducing OCRia-1.5
  3. LlamaIndex: ParseBench-2