File size: 3,133 Bytes
4dce182
d9afd9b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4dce182
 
1e79657
4dce182
8941e3a
 
 
4dce182
8941e3a
9d054d4
cc8bc99
4dce182
8941e3a
 
4dce182
8941e3a
4dce182
 
 
 
 
 
8941e3a
 
4dce182
 
 
8941e3a
 
 
 
 
 
9d054d4
8941e3a
4dce182
 
 
8941e3a
 
 
 
 
 
d9afd9b
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
---
license: apache-2.0
language:
- en
pipeline_tag: image-to-text
library_name: onnx
tags:
- ocr
- document-understanding
- document-parsing
- key-information-extraction
- receipts
- invoices
- pdf
- onnx
- cpu
datasets:
- naver-clova-ix/cord-v2
- docling-project/DocLayNet-v1.2
metrics:
- cer
model-index:
- name: tinydoc
  results:
  - task:
      type: image-to-text
      name: OCR
    dataset:
      name: OmniDocBench v1.5, English pages
      type: opendatalab/OmniDocBench
    metrics:
    - type: edit_distance
      value: 0.117
      name: Text edit distance, page average (lower is better)
  - task:
      type: image-to-text
      name: Text-line recognition
    dataset:
      name: CORD-v2 receipt lines
      type: naver-clova-ix/cord-v2
      split: test
    metrics:
    - type: cer
      value: 1.23
      name: Character error rate, % (lower is better)
  - task:
      type: image-to-text
      name: Text-line recognition
    dataset:
      name: DocLayNet v1.2 lines
      type: docling-project/DocLayNet-v1.2
      split: test
    metrics:
    - type: cer
      value: 8.94
      name: Character error rate, % (lower is better)
---

![tinydoc](banner.png)

A small OCR model (5.1M parameters, 20 MB) that reads printed receipts, invoices, PDFs and ordinary pages
on a CPU. It returns the text and the key fields (merchant, date, totals, line items) as JSON, with a
confidence for every value and a pointer to where on the page it was read.

## Benchmarks

![tinydoc benchmarks](benchmarks/grid.png)

Measured on an Apple M5 Pro, CPU only, with the same pages and crops for every engine. Indra OCR's
figures are the ones Datalab published; Indra was not run here.

## Quick start

```bash
pip install -r requirements.txt
python -m tinydoc extract receipt.jpg invoice.pdf --backend onnx --weights onnx --out result.json
```

Every field has a `confidence` and a `needs_review` flag. Missing values are `null`, never guessed.
Check `validation.needs_review` before trusting totals.

## Training data

| Source | Licence |
|---|---|
| [CORD-v2](https://huggingface.co/datasets/naver-clova-ix/cord-v2) (Park et al., 2019) | CC BY 4.0 |
| [WildReceipt](https://download.openmmlab.com/mmocr/data/wildreceipt.tar) (Sun et al., 2021) | Apache 2.0 |
| [DocLayNet v1.2](https://huggingface.co/datasets/docling-project/DocLayNet-v1.2) subset (Pfitzmann et al., 2022) | CDLA-Permissive-1.0 |
| Synthetic receipts, invoices and pages | rendered with OFL, Apache and UFL fonts |

Trained from scratch: no pretrained weights, and nothing distilled from another model.

## Limitations

- Printed Latin-script text only; no handwriting.
- Table structure is weak (OmniDocBench TEDS 0.29).
- With several workers in parallel, Tesseract is slightly faster (3.26 against 3.17 pages per second
  with 4 workers) and uses far less memory (120 MB against 1.3 GB per worker).
- Line items and unfamiliar invoice layouts are the least reliable fields.
- Dense multi-column pages (newspapers, magazines) are the hardest for reading order.

## Licence

Apache 2.0 (see `LICENSE`). The training data keeps its own licences, listed above.