2025-02-25 08:44:36 -08:00
< div align = "center" >
<!-- <img src="https://github.com/allenai/OLMo/assets/8812459/774ac485 - a535 - 4768 - 8f7c - db7be20f5cc3" width="300"/> -->
2025-01-27 10:21:59 -08:00
< img src = "https://github.com/user-attachments/assets/d70c8644-3e64-4230-98c3-c52fddaeccb6" alt = "olmOCR Logo" width = "300" / >
2025-05-19 17:30:21 +00:00
< hr / >
2025-02-25 08:44:36 -08:00
< / div >
< p align = "center" >
< a href = "https://github.com/allenai/OLMo/blob/main/LICENSE" >
< img alt = "GitHub License" src = "https://img.shields.io/github/license/allenai/OLMo" >
< / a >
< a href = "https://github.com/allenai/olmocr/releases" >
< img alt = "GitHub release" src = "https://img.shields.io/github/release/allenai/olmocr.svg" >
< / a >
< a href = "https://olmocr.allenai.org/papers/olmocr.pdf" >
< img alt = "Tech Report" src = "https://img.shields.io/badge/Paper-olmOCR-blue" >
< / a >
2025-02-27 14:56:05 -08:00
< a href = "https://olmocr.allenai.org" >
2025-02-25 09:17:15 -08:00
< img alt = "Demo" src = "https://img.shields.io/bad g e/Ai2-Demo-F0529C" >
2025-02-25 08:44:36 -08:00
< / a >
< a href = "https://discord.gg/sZq3jTNVNG" >
< img alt = "Discord" src = "https://img.shields.io/badge/Discord%20-%20blue?style=flat&logo=discord&label=Ai2&color=%235B65E9" >
< / a >
< / p >
2025-05-19 16:56:22 +00:00
A toolkit for converting PDFs and other image-based document formats into clean, readable, plain text format.
2024-10-02 20:48:39 +00:00
2025-02-13 13:46:02 -08:00
Try the online demo: [https://olmocr.allenai.org/ ](https://olmocr.allenai.org/ )
2024-11-04 16:20:36 +00:00
2025-05-19 16:56:22 +00:00
Features:
- Convert PDF, PNG, and JPEG based documents into clean Markdown
- Support for equations, tables, handwriting, and complex formatting
- Automatically removes headers and footers
- Convert into text with a natural reading order, even in the presence of
figures, multi-column layouts, and insets
- Efficient, less than $200 USD per million pages converted
- (Based on a 7B parameter VLM, so it requires a GPU)
2024-10-02 20:48:39 +00:00
2025-05-19 17:30:21 +00:00
### News
- May 19, 2025 - v0.1.68 - [olmOCR-Bench ](https://github.com/allenai/olmocr/tree/main/olmocr/bench ) launch, scoring 77.4. Launch includes 2 point performance boost in olmOCR pipeline due to bug fixes with prompts.
- Mar 17, 2025 - v0.1.60 - Performance improvements due to better temperature selection in sampling.
- Feb 25, 2025 - v0.1.58 - Initial public launch and demo.
2025-05-19 16:56:22 +00:00
### Benchmark
2025-05-15 16:17:29 -07:00
[**olmOCR-Bench** ](https://github.com/allenai/olmocr/tree/main/olmocr/bench ):
2025-05-19 16:56:22 +00:00
We also ship a comprehensive benchmark suite covering over 7,000 test cases across 1,400 documents to help measure performance of OCR systems.
< table >
< thead >
< tr >
< th align = "left" > < strong > Model< / strong > < / th >
< th align = "center" > AR< / th >
< th align = "center" > OSM< / th >
< th align = "center" > TA< / th >
< th align = "center" > OS< / th >
< th align = "center" > HF< / th >
< th align = "center" > MC< / th >
< th align = "center" > LTT< / th >
< th align = "center" > Base< / th >
2025-05-19 11:10:09 -07:00
< th align = "center" > Overall Score< / th >
2025-05-19 16:56:22 +00:00
< / tr >
< / thead >
< tbody >
< tr >
< td align = "left" > Marker v1.6.2< / td >
< td align = "center" > 24.3< / td >
< td align = "center" > 22.1< / td >
< td align = "center" > 69.8< / td >
< td align = "center" > 24.3< / td >
< td align = "center" > 87.1< / td >
< td align = "center" > 71.0< / td >
< td align = "center" > 76.9< / td >
< td align = "center" > < strong > 99.5< / strong > < / td >
< td align = "center" > 59.4 ± 1.1< / td >
< / tr >
< tr >
< td align = "left" > MinerU v1.3.10< / td >
< td align = "center" > 75.4< / td >
< td align = "center" > 47.4< / td >
< td align = "center" > 60.9< / td >
< td align = "center" > 17.3< / td >
< td align = "center" > < strong > 96.6< / strong > < / td >
< td align = "center" > 59.0< / td >
< td align = "center" > 39.1< / td >
< td align = "center" > 96.6< / td >
< td align = "center" > 61.5 ± 1.1< / td >
< / tr >
< tr >
< td align = "left" > Mistral OCR API< / td >
< td align = "center" > < strong > 77.2< / strong > < / td >
< td align = "center" > 67.5< / td >
< td align = "center" > 60.6< / td >
< td align = "center" > 29.3< / td >
< td align = "center" > 93.6< / td >
< td align = "center" > 71.3< / td >
< td align = "center" > 77.1< / td >
< td align = "center" > 99.4< / td >
< td align = "center" > 72.0 ± 1.1< / td >
< / tr >
< tr >
< td align = "left" > olmOCR v0.1.68 (pipeline.py)< / td >
< td align = "center" > 75.6< / td >
< td align = "center" > 75.1< / td >
< td align = "center" > 70.2< / td >
< td align = "center" > < strong > 44.5< / strong > < / td >
< td align = "center" > 93.4< / td >
< td align = "center" > < strong > 79.4< / strong > < / td >
< td align = "center" > 81.7< / td >
< td align = "center" > 99.0< / td >
< td align = "center" > < strong > 77.4 ± 1.0< / strong > < / td >
< / tr >
< / tbody >
< / table >
2025-05-15 16:17:29 -07:00
2024-11-04 17:08:29 +00:00
### Installation
2024-10-02 20:48:39 +00:00
2025-01-30 12:48:10 -08:00
Requirements:
2025-03-03 15:54:47 -08:00
- Recent NVIDIA GPU (tested on RTX 4090, L40S, A100, H100) with at least 20 GB of GPU RAM
2025-01-30 12:48:10 -08:00
- 30GB of free disk space
2025-03-03 20:08:27 -08:00
2025-02-07 16:05:00 -08:00
You will need to install poppler-utils and additional fonts for rendering PDF images.
2024-10-02 20:48:39 +00:00
2025-02-07 16:05:00 -08:00
Install dependencies (Ubuntu/Debian)
2024-11-04 17:08:29 +00:00
```bash
2025-01-30 12:48:10 -08:00
sudo apt-get update
2024-11-01 09:49:41 -07:00
sudo apt-get install poppler-utils ttf-mscorefonts-installer msttcorefonts fonts-crosextra-caladea fonts-crosextra-carlito gsfonts lcdf-typetools
2024-11-04 17:08:29 +00:00
```
2025-05-19 16:56:22 +00:00
Set up a conda environment and install olmocr. The requirements for running olmOCR
are difficult to install in an existing python environment, so please do make a clean python environment to install into.
2024-11-04 17:08:29 +00:00
```bash
2025-01-29 13:37:13 -08:00
conda create -n olmocr python=3.11
conda activate olmocr
2025-05-20 16:42:21 +00:00
# For CPU-only operations, ex running the benchmark
pip install olmocr[bench]
2025-04-07 20:01:22 -07:00
# For actually converting the files with your own GPU
2025-05-20 16:42:21 +00:00
pip install olmocr[gpu] --find-links https://flashinfer.ai/whl/cu124/torch2.4/flashinfer/
2025-01-29 11:13:06 -08:00
```
2024-10-21 16:45:06 +00:00
2025-01-29 11:13:06 -08:00
### Local Usage Example
2024-11-18 12:44:34 -08:00
2025-02-07 16:05:00 -08:00
For quick testing, try the [web demo ](https://olmocr.allen.ai/ ). To run locally, a GPU is required, as inference is powered by [sglang ](https://github.com/sgl-project/sglang ) under the hood.
2025-05-19 16:56:22 +00:00
2025-02-07 16:05:00 -08:00
Convert a Single PDF:
2025-01-29 11:13:06 -08:00
```bash
2025-05-20 19:51:29 +00:00
# Download a sample PDF
curl -o olmocr-sample.pdf https://olmocr.allenai.org/papers/olmocr_3pg_sample.pdf
# Convert it to markdown
python -m olmocr.pipeline ./localworkspace --markdown --pdfs olmocr-sample.pdf
2025-01-29 11:13:06 -08:00
```
2025-03-31 13:50:07 -07:00
Convert an Image file:
```bash
2025-05-20 19:51:29 +00:00
python -m olmocr.pipeline ./localworkspace --markdown --pdfs random_page.png
2025-03-31 13:50:07 -07:00
```
2025-02-07 16:05:00 -08:00
Convert Multiple PDFs:
2025-01-29 11:13:06 -08:00
```bash
2025-05-20 19:51:29 +00:00
python -m olmocr.pipeline ./localworkspace --markdown --pdfs tests/gnarly_pdfs/*.pdf
2025-01-29 11:13:06 -08:00
```
2025-05-20 19:51:29 +00:00
With the addition of the `--markdown` flag, results will be stored as markdown files inside of `./localworkspace/markdown/` .
2025-01-29 11:38:53 -08:00
2025-05-20 19:51:29 +00:00
#### Viewing Results
2025-01-29 11:23:04 -08:00
2025-05-20 19:51:29 +00:00
The `./localworkspace/` workspace folder will then have both [Dolma ](https://github.com/allenai/dolma ) and markdown files (if using `--markdown` ).
2025-01-29 11:23:04 -08:00
2025-01-29 11:27:55 -08:00
```bash
2025-05-20 19:51:29 +00:00
cat localworkspace/markdown/olmocr-sample.md
2025-01-29 11:23:04 -08:00
```
2025-05-20 19:51:29 +00:00
< pre >
olmOCR: Unlocking Trillions of Tokens in PDFs with Vision Language Models
...
< / pre >
2025-01-29 11:28:38 -08:00
2025-01-29 11:23:04 -08:00
2025-01-29 11:13:06 -08:00
### Multi-node / Cluster Usage
If you want to convert millions of PDFs, using multiple nodes running in parallel, then olmOCR supports
reading your PDFs from AWS S3, and coordinating work using an AWS S3 output bucket.
For example, you can start this command on your first worker node, and it will set up
a simple work queue in your AWS bucket and start converting PDFs.
2024-11-18 12:44:34 -08:00
```bash
2025-01-29 11:13:06 -08:00
python -m olmocr.pipeline s3://my_s3_bucket/pdfworkspaces/exampleworkspace --pdfs s3://my_s3_bucket/jakep/gnarly_pdfs/*.pdf
2024-11-18 12:44:34 -08:00
```
2025-03-03 20:08:27 -08:00
Now on any subsequent nodes, just run this and they will start grabbing items from the same workspace queue.
2025-01-29 11:13:06 -08:00
```bash
python -m olmocr.pipeline s3://my_s3_bucket/pdfworkspaces/exampleworkspace
```
2024-11-18 12:44:34 -08:00
2025-02-07 16:05:00 -08:00
If you are at Ai2 and want to linearize millions of PDFs efficiently using [beaker ](https://www.beaker.org ), just add the `--beaker`
2025-01-29 11:13:06 -08:00
flag. This will prepare the workspace on your local machine, and then launch N GPU workers in the cluster to start
converting PDFs.
For example:
```bash
python -m olmocr.pipeline s3://my_s3_bucket/pdfworkspaces/exampleworkspace --pdfs s3://my_s3_bucket/jakep/gnarly_pdfs/*.pdf --beaker --beaker_gpus 4
```
2024-11-18 12:44:34 -08:00
2025-01-29 11:53:40 -08:00
### Full documentation for the pipeline
2024-11-18 12:44:34 -08:00
```bash
2025-01-29 11:13:06 -08:00
python -m olmocr.pipeline --help
usage: pipeline.py [-h] [--pdfs PDFS] [--workspace_profile WORKSPACE_PROFILE] [--pdf_profile PDF_PROFILE] [--pages_per_group PAGES_PER_GROUP]
[--max_page_retries MAX_PAGE_RETRIES] [--max_page_error_rate MAX_PAGE_ERROR_RATE] [--workers WORKERS] [--apply_filter] [--stats] [--model MODEL]
[--model_max_context MODEL_MAX_CONTEXT] [--model_chat_template MODEL_CHAT_TEMPLATE] [--target_longest_image_dim TARGET_LONGEST_IMAGE_DIM]
[--target_anchor_text_len TARGET_ANCHOR_TEXT_LEN] [--beaker] [--beaker_workspace BEAKER_WORKSPACE] [--beaker_cluster BEAKER_CLUSTER]
[--beaker_gpus BEAKER_GPUS] [--beaker_priority BEAKER_PRIORITY]
workspace
2024-11-18 12:44:34 -08:00
Manager for running millions of PDFs through a batch inference pipeline
positional arguments:
2025-01-29 11:13:06 -08:00
workspace The filesystem path where work will be stored, can be a local folder, or an s3 path if coordinating work with many workers, s3://bucket/prefix/
2024-11-18 12:44:34 -08:00
options:
-h, --help show this help message and exit
2025-01-29 11:13:06 -08:00
--pdfs PDFS Path to add pdfs stored in s3 to the workspace, can be a glob path s3://bucket/prefix/*.pdf or path to file containing list of pdf paths
2024-11-18 12:44:34 -08:00
--workspace_profile WORKSPACE_PROFILE
S3 configuration profile for accessing the workspace
--pdf_profile PDF_PROFILE
S3 configuration profile for accessing the raw pdf documents
--pages_per_group PAGES_PER_GROUP
Aiming for this many pdf pages per work item group
2024-11-20 08:55:57 -08:00
--max_page_retries MAX_PAGE_RETRIES
Max number of times we will retry rendering a page
--max_page_error_rate MAX_PAGE_ERROR_RATE
Rate of allowable failed pages in a document, 1/250 by default
2024-11-18 12:44:34 -08:00
--workers WORKERS Number of workers to run at a time
2025-01-29 11:13:06 -08:00
--apply_filter Apply basic filtering to English pdfs which are not forms, and not likely seo spam
2024-11-18 12:44:34 -08:00
--stats Instead of running any job, reports some statistics about the current workspace
2025-05-20 19:51:29 +00:00
--markdown Also write natural text to markdown files preserving the folder structure of the input pdfs
2025-01-29 11:13:06 -08:00
--model MODEL List of paths where you can find the model to convert this pdf. You can specify several different paths here, and the script will try to use the
one which is fastest to access
2024-11-18 12:44:34 -08:00
--model_max_context MODEL_MAX_CONTEXT
Maximum context length that the model was fine tuned under
--model_chat_template MODEL_CHAT_TEMPLATE
Chat template to pass to sglang server
--target_longest_image_dim TARGET_LONGEST_IMAGE_DIM
Dimension on longest side to use for rendering the pdf pages
--target_anchor_text_len TARGET_ANCHOR_TEXT_LEN
Maximum amount of anchor text to use (characters)
--beaker Submit this job to beaker instead of running locally
--beaker_workspace BEAKER_WORKSPACE
Beaker workspace to submit to
--beaker_cluster BEAKER_CLUSTER
Beaker clusters you want to run on
--beaker_gpus BEAKER_GPUS
Number of gpu replicas to run
--beaker_priority BEAKER_PRIORITY
Beaker priority level for the job
```
2025-05-19 16:56:22 +00:00
## Code overview
There are some nice reusable pieces of the code that may be useful for your own projects:
- A prompting strategy to get really good natural text parsing using ChatGPT 4o - [buildsilver.py ](https://github.com/allenai/olmocr/blob/main/olmocr/data/buildsilver.py )
- An side-by-side eval toolkit for comparing different pipeline versions - [runeval.py ](https://github.com/allenai/olmocr/blob/main/olmocr/eval/runeval.py )
- Basic filtering by language and SEO spam removal - [filter.py ](https://github.com/allenai/olmocr/blob/main/olmocr/filter/filter.py )
- Finetuning code for Qwen2-VL and Molmo-O - [train.py ](https://github.com/allenai/olmocr/blob/main/olmocr/train/train.py )
- Processing millions of PDFs through a finetuned model using Sglang - [pipeline.py ](https://github.com/allenai/olmocr/blob/main/olmocr/pipeline.py )
- Viewing [Dolma docs ](https://github.com/allenai/dolma ) created from PDFs - [dolmaviewer.py ](https://github.com/allenai/olmocr/blob/main/olmocr/viewer/dolmaviewer.py )
2024-11-18 12:44:34 -08:00
2025-02-24 09:37:12 -08:00
## Team
<!-- start team -->
**olmOCR** is developed and maintained by the AllenNLP team, backed by [the Allen Institute for Artificial Intelligence (AI2) ](https://allenai.org/ ).
AI2 is a non-profit institute with the mission to contribute to humanity through high-impact AI research and engineering.
To learn more about who specifically contributed to this codebase, see [our contributors ](https://github.com/allenai/olmocr/graphs/contributors ) page.
<!-- end team -->
## License
<!-- start license -->
**olmOCR** is licensed under [Apache 2.0 ](https://www.apache.org/licenses/LICENSE-2.0 ).
A full copy of the license can be found [on GitHub ](https://github.com/allenai/olmocr/blob/main/LICENSE ).
<!-- end license -->
2025-03-03 13:48:21 -08:00
## Citing
```bibtex
@misc {olmocr,
2025-03-03 20:08:27 -08:00
title={{olmOCR: Unlocking Trillions of Tokens in PDFs with Vision Language Models}},
2025-03-03 13:48:21 -08:00
author={Jake Poznanski and Jon Borchardt and Jason Dunkelberger and Regan Huff and Daniel Lin and Aman Rangapur and Christopher Wilhelm and Kyle Lo and Luca Soldaini},
year={2025},
eprint={2502.18443},
archivePrefix={arXiv},
primaryClass={cs.CL},
2025-03-03 20:08:27 -08:00
url={https://arxiv.org/abs/2502.18443},
2025-03-03 13:48:21 -08:00
}
```