BYOSM publish doctype/v2-ditft
Browse files
README.md
CHANGED
|
@@ -30,15 +30,19 @@ base_model_relation: finetune
|
|
| 30 |
---
|
| 31 |
# Document type
|
| 32 |
|
| 33 |
-
**
|
| 34 |
|
| 35 |
-
|
| 36 |
|
| 37 |
## Table of Contents
|
| 38 |
|
| 39 |
- [Overview](#overview)
|
| 40 |
- [How It Works](#how-it-works)
|
| 41 |
- [Architecture and Training](#architecture-and-training)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
- [Benchmarks](#benchmarks)
|
| 43 |
- [Usage](#usage)
|
| 44 |
- [Deployment Requirements](#deployment-requirements)
|
|
@@ -49,22 +53,11 @@ On a held-out set of 3200 RVL-CDIP pages it reaches **0.948 accuracy** (95% CI 0
|
|
| 49 |
|
| 50 |
## Overview
|
| 51 |
|
| 52 |
-
Document pipelines often need to
|
| 53 |
|
| 54 |
-
A
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
- inputs are **scanned or born-digital business documents**, mostly single page (typically grayscale scans of around 1000px)
|
| 59 |
-
- the text is in **English**
|
| 60 |
-
- the RVL-CDIP class set fits your routing needs
|
| 61 |
-
|
| 62 |
-
## How It Works
|
| 63 |
-
|
| 64 |
-
1. **Input**: a document page as an image or PDF. The runtime renders PDFs and runs **OCR** on scanned pages. OCR text is cut off at **256 tokens**.
|
| 65 |
-
2. **Prediction**: the model combines image features with the OCR text (the **fused** route) and scores all 16 classes.
|
| 66 |
-
3. **Decision threshold**: none is set. The model picks the class with the highest score.
|
| 67 |
-
4. **Output**: one label from the set below.
|
| 68 |
|
| 69 |
| Label | Description |
|
| 70 |
|---|---|
|
|
@@ -85,43 +78,43 @@ Use it when:
|
|
| 85 |
| `scientific_report` | scientific / technical reports, lab reports |
|
| 86 |
| `specification` | product or technical specifications, spec sheets |
|
| 87 |
|
| 88 |
-
##
|
| 89 |
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
-
|
| 93 |
|
| 94 |
-
|
| 95 |
|
| 96 |
-
-
|
| 97 |
-
- That backbone was then replaced with `microsoft/dit-base`, a document-domain encoder.
|
| 98 |
-
- The final experiment (**v2-ditft**) switched to the RVL-CDIP fine-tuned DiT checkpoint. This is the same model used as the rival in the benchmark below.
|
| 99 |
|
| 100 |
### Training Data
|
| 101 |
|
| 102 |
-
- **
|
| 103 |
-
- **train
|
| 104 |
-
- Total training rows: **34935**
|
| 105 |
-
- Dev rows: **3881**
|
| 106 |
-
-
|
| 107 |
-
|
| 108 |
-
The amount of data per label went up over several experiments, ending with all available rows for the rarest label in the source split.
|
| 109 |
|
| 110 |
### Pretraining and Refinement
|
| 111 |
|
| 112 |
-
- **Pretraining**:
|
| 113 |
-
- **
|
| 114 |
-
- **Refinement**: one round, starting from 34935 rows, which reached a dev
|
|
|
|
| 115 |
|
| 116 |
### Quantization and Export
|
| 117 |
|
| 118 |
-
-
|
| 119 |
-
-
|
| 120 |
-
- Size: **113.2 MB**
|
| 121 |
|
| 122 |
## Benchmarks
|
| 123 |
|
| 124 |
-
This model and microsoft/dit-base-finetuned-rvlcdip
|
| 125 |
|
| 126 |
### Results, measured by code
|
| 127 |
|
|
@@ -155,13 +148,13 @@ and its rivals were scored by the same code, each with its decision threshold ca
|
|
| 155 |
| objective | accuracy, primary suite `rvl` |
|
| 156 |
| decision policy | `threshold`, threshold – (calibrated on `rvl`'s calib split) |
|
| 157 |
|
| 158 |
-
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
## Usage
|
| 163 |
|
| 164 |
-
|
| 165 |
|
| 166 |
```bash
|
| 167 |
pip install huggingface_hub numpy onnxruntime tokenizers pillow pypdfium2 rapidocr_onnxruntime
|
|
@@ -188,38 +181,30 @@ python byosm_rt.py serve . --port 8800
|
|
| 188 |
|
| 189 |
## Deployment Requirements
|
| 190 |
|
| 191 |
-
- **CPU only**, no GPU
|
| 192 |
-
- Size
|
| 193 |
-
- Latency: **43.3 ms** per
|
| 194 |
-
- Dependencies:
|
| 195 |
-
- `numpy`
|
| 196 |
-
- `onnxruntime`
|
| 197 |
-
- `tokenizers`
|
| 198 |
-
- `pillow`
|
| 199 |
-
- `pypdfium2`
|
| 200 |
-
- `rapidocr_onnxruntime` (OCR for scanned pages)
|
| 201 |
|
| 202 |
## Limitations
|
| 203 |
|
| 204 |
-
- Evaluated only on rvl (3200 test items). Small test suites have wide confidence intervals.
|
| 205 |
-
- The backbone is **microsoft/dit-base-finetuned-rvlcdip**, the same model used as the rival. The benchmark therefore shows what additional training adds to that model, not how two independent models compare.
|
| 206 |
- English only.
|
| 207 |
-
-
|
| 208 |
-
-
|
| 209 |
-
-
|
| 210 |
-
-
|
| 211 |
-
- No decision threshold is set, so the model has no built-in way to abstain on low-confidence pages.
|
| 212 |
|
| 213 |
## License
|
| 214 |
|
| 215 |
-
cc-by-nc-4.0
|
| 216 |
|
| 217 |
## Resources
|
| 218 |
|
| 219 |
-
- BYOSM on GitHub
|
| 220 |
-
-
|
| 221 |
-
-
|
| 222 |
-
-
|
| 223 |
|
| 224 |
## Reproduce
|
| 225 |
|
|
|
|
| 30 |
---
|
| 31 |
# Document type
|
| 32 |
|
| 33 |
+
**Document type** classifies business document pages into the **16 RVL-CDIP classes**, such as letter, invoice, form and scientific report. It runs on CPU as an **int8 ONNX** export with a one-file Python runtime.
|
| 34 |
|
| 35 |
+
At **109.5M** parameters this model is **not smaller** than the best rival, **microsoft/dit-base-finetuned-rvlcdip** (**85.8M**), because it is **built on that rival's own checkpoint**. It scores **0.948** accuracy against the rival's **0.94**.
|
| 36 |
|
| 37 |
## Table of Contents
|
| 38 |
|
| 39 |
- [Overview](#overview)
|
| 40 |
- [How It Works](#how-it-works)
|
| 41 |
- [Architecture and Training](#architecture-and-training)
|
| 42 |
+
- [Base Model](#base-model)
|
| 43 |
+
- [Training Data](#training-data)
|
| 44 |
+
- [Pretraining and Refinement](#pretraining-and-refinement)
|
| 45 |
+
- [Quantization and Export)](#quantization-and-export)
|
| 46 |
- [Benchmarks](#benchmarks)
|
| 47 |
- [Usage](#usage)
|
| 48 |
- [Deployment Requirements](#deployment-requirements)
|
|
|
|
| 53 |
|
| 54 |
## Overview
|
| 55 |
|
| 56 |
+
Document pipelines often need to route incoming pages by type before extraction, filing or review. The inputs are **scanned or born-digital business documents**, mostly single page, typically grayscale scans of about 1000px.
|
| 57 |
|
| 58 |
+
A single-task specialist does one thing and runs locally on CPU, without a hosted service. Use it when your pages fit the RVL-CDIP taxonomy and are in **English**.
|
| 59 |
|
| 60 |
+
The model predicts one of these labels:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
| Label | Description |
|
| 63 |
|---|---|
|
|
|
|
| 78 |
| `scientific_report` | scientific / technical reports, lab reports |
|
| 79 |
| `specification` | product or technical specifications, spec sheets |
|
| 80 |
|
| 81 |
+
## How It Works
|
| 82 |
|
| 83 |
+
1. **Input**: a document page as an image or PDF. For scanned pages, the text is extracted with OCR. The text input is limited to **256 tokens**.
|
| 84 |
+
2. **Prediction**: the model uses a **fused** route that combines the page image with the document text, then scores all 16 classes.
|
| 85 |
+
3. **Decision threshold**: none. This is a single-label, 16-way task.
|
| 86 |
+
4. **Output**: the label with the highest score.
|
| 87 |
|
| 88 |
+
## Architecture and Training
|
| 89 |
|
| 90 |
+
### Base Model
|
| 91 |
|
| 92 |
+
The image backbone is **microsoft/dit-base-finetuned-rvlcdip**, which is the best rival in the benchmark, and the image features come from its **pooler** output. Earlier experiments used `facebook/dinov2-small` and then **microsoft/dit-base**. DiT-base is self-supervised with masked image modelling on 42M unlabelled document scans and never saw RVL-CDIP labels. The final step switched to the RVL-CDIP fine-tuned checkpoint.
|
|
|
|
|
|
|
| 93 |
|
| 94 |
### Training Data
|
| 95 |
|
| 96 |
+
- **chainyo/rvl-cdip**: **29112** labeled training rows, drawn from its validation split
|
| 97 |
+
- **Unlabeled train inputs**: **29112** rows
|
| 98 |
+
- **Total training rows**: **34935**
|
| 99 |
+
- **Dev rows**: **3881**
|
| 100 |
+
- **Test rows**: **3200**, held out
|
|
|
|
|
|
|
| 101 |
|
| 102 |
### Pretraining and Refinement
|
| 103 |
|
| 104 |
+
- **Pretraining steps**: 0
|
| 105 |
+
- **Epochs**: 13
|
| 106 |
+
- **Refinement**: one round, starting from **34935** rows, which reached a dev score of **0.942**. No refinement patterns were applied.
|
| 107 |
+
- **Lineage**: per-label data went from 200 to 800 and then to **2426** (all of it), the backbone moved to a document-domain encoder, and training was extended to 13 epochs. The variant built on the DiT-base backbone scored **0.906** on the test set before the final switch to the rival's fine-tuned checkpoint.
|
| 108 |
|
| 109 |
### Quantization and Export
|
| 110 |
|
| 111 |
+
- **Format**: ONNX, in a single folder with a one-file Python runtime
|
| 112 |
+
- **Precision**: int8
|
| 113 |
+
- **Size**: **113.2 MB**
|
| 114 |
|
| 115 |
## Benchmarks
|
| 116 |
|
| 117 |
+
This model and **microsoft/dit-base-finetuned-rvlcdip** are compared on **accuracy** over **3200** held-out test items from **chainyo/rvl-cdip**. The comparison also reports the share of each label that each model caught. The 95% confidence interval for this model is shown next to its score.
|
| 118 |
|
| 119 |
### Results, measured by code
|
| 120 |
|
|
|
|
| 148 |
| objective | accuracy, primary suite `rvl` |
|
| 149 |
| decision policy | `threshold`, threshold – (calibrated on `rvl`'s calib split) |
|
| 150 |
|
| 151 |
+
This model scores **0.948** (95% CI **0.941** to **0.956**) against **0.94** for the rival, which sits just below the lower bound of the interval. The two models are close: they tie on `news_article`, `questionnaire`, `resume`, `scientific_publication` and `scientific_report`, the rival is ahead on `advertisement` (**0.946** vs **0.941**), and both models are weakest on `scientific_report` (**0.876**).
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
## Usage
|
| 156 |
|
| 157 |
+
Load the exported folder with the bundled Python runtime and pass it a page image or PDF.
|
| 158 |
|
| 159 |
```bash
|
| 160 |
pip install huggingface_hub numpy onnxruntime tokenizers pillow pypdfium2 rapidocr_onnxruntime
|
|
|
|
| 181 |
|
| 182 |
## Deployment Requirements
|
| 183 |
|
| 184 |
+
- **CPU only**, no GPU required
|
| 185 |
+
- **Size**: 113.2 MB (int8 ONNX), 109.5M parameters
|
| 186 |
+
- **Latency**: about **43.3 ms** per item on CPU
|
| 187 |
+
- **Dependencies**: `numpy`, `onnxruntime`, `tokenizers`, `pillow`, `pypdfium2`, `rapidocr_onnxruntime` (OCR for scanned pages)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
|
| 189 |
## Limitations
|
| 190 |
|
| 191 |
+
- Evaluated only on rvl (**3200** test items). Small test suites have wide confidence intervals.
|
|
|
|
| 192 |
- English only.
|
| 193 |
+
- Covers only the 16 RVL-CDIP classes. Pages outside this taxonomy are still assigned one of them.
|
| 194 |
+
- Built on the rival's RVL-CDIP fine-tuned checkpoint, so it is larger than that rival (**109.5M** vs **85.8M** parameters). Its accuracy lead is small.
|
| 195 |
+
- Lowest per-label recall is on `scientific_report` (**0.876**) and `form` (**0.905**).
|
| 196 |
+
- Scanned pages depend on OCR quality for the text input, which is limited to 256 tokens.
|
|
|
|
| 197 |
|
| 198 |
## License
|
| 199 |
|
| 200 |
+
cc-by-nc-4.0
|
| 201 |
|
| 202 |
## Resources
|
| 203 |
|
| 204 |
+
- [BYOSM on GitHub](https://github.com/bsye/BYOSM)
|
| 205 |
+
- [chainyo/rvl-cdip](https://huggingface.co/datasets/chainyo/rvl-cdip) (training and benchmark data)
|
| 206 |
+
- [microsoft/dit-base-finetuned-rvlcdip](https://huggingface.co/microsoft/dit-base-finetuned-rvlcdip) (rival and base checkpoint)
|
| 207 |
+
- [microsoft/dit-base](https://huggingface.co/microsoft/dit-base) (earlier backbone)
|
| 208 |
|
| 209 |
## Reproduce
|
| 210 |
|