文章目录
- 一、关于 olmOCR
- 相关资源
- 包含内容
- 团队
- 二、安装
- 三、本地使用示例
- 查看结果
- 多节点/集群使用
- 管道完整文档
一、关于 olmOCR
olmOCR 是用于训练语言模型处理PDF文档的工具包,支持大规模PDF文本解析和转换。
相关资源
- 源码:https://github.com/allenai/olmocr
- 技术报告:https://olmocr.allenai.org/papers/olmocr.pdf
- 在线演示:https://olmocr.allenai.org/
- 社区交流:https://discord.gg/sZq3jTNVNG
- LICENSE:Apache 2.0
包含内容
- 使用ChatGPT 4o获取高质量自然文本解析的提示策略 - buildsilver.py
- 比较不同管道版本的并排评估工具 - runeval.py
- 基于语言和SEO垃圾邮件移除的基本过滤 - filter.py
- Qwen2-VL和Molmo-O的微调代码 - train.py
- 使用Sglang通过微调模型处理数百万PDF文件 - pipeline.py
- 查看从PDF创建的Dolma文档 - dolmaviewer.py
团队
olmOCR 由AllenNLP团队开发并维护,由艾伦人工智能研究所(AI2)支持。
AI2是一个非营利性研究所,其使命是通过高影响力的AI研究和工程为人类做出贡献。
有关具体贡献此代码库的人员信息,请参阅我们的贡献者页面。
二、安装
要求:
- 近期NVIDIA GPU(已在RTX 4090、L40S、A100、H100上测试),至少20 GB的GPU RAM
- 30GB的可用磁盘空间
您需要安装poppler-utils和用于渲染PDF图像的附加字体。
安装依赖项(Ubuntu/Debian)
sudo apt-get update
sudo apt-get install poppler-utils ttf-mscorefonts-installer msttcorefonts fonts-crosextra-caladea fonts-crosextra-carlito gsfonts lcdf-typetools
设置conda环境并安装olmocr
conda create -n olmocr python=3.11
conda activate olmocrgit clone https://github.com/allenai/olmocr.git
cd olmocr# 对于仅CPU操作,例如运行基准测试
pip install -e .# 对于实际上传文件并使用自己的GPU进行转换
pip install -e .[gpu] --find-links https://flashinfer.ai/whl/cu124/torch2.4/flashinfer/
三、本地使用示例
为了快速测试,请尝试网络演示。要本地运行,需要GPU,因为推理由sglang提供支持。
转换单个PDF:
python -m olmocr.pipeline ./localworkspace --pdfs tests/gnarly_pdfs/horribleocr.pdf
转换图像文件:
python -m olmocr.pipeline ./localworkspace --pdfs random_page.png
转换多个PDF:
python -m olmocr.pipeline ./localworkspace --pdfs tests/gnarly_pdfs/*.pdf
结果将存储为JSON在./localworkspace
中。
查看结果
提取的文本存储为Dolma风格的JSONL在./localworkspace/results
目录中。
cat localworkspace/results/output_*.jsonl
与原始PDF并排查看结果(使用dolmaviewer
命令):
python -m olmocr.viewer.dolmaviewer localworkspace/results/output_*.jsonl
现在在您喜欢的浏览器中打开./dolma_previews/tests_gnarly_pdfs_horribleocr_pdf.html
。
多节点/集群使用
如果您想使用多个并行运行的节点转换数百万PDF文件,那么olmOCR支持从AWS S3读取PDF,并使用AWS S3输出存储桶协调工作。
例如,您可以在第一个工作节点上启动此命令,它将在您的AWS存储桶中设置一个简单的工作队列,并开始转换PDF。
python -m olmocr.pipeline s3://my_s3_bucket/pdfworkspaces/exampleworkspace --pdfs s3://my_s3_bucket/jakep/gnarly_pdfs/*.pdf
现在在任意后续节点上运行此命令,它们将开始从相同的工作区队列中获取项目。
python -m olmocr.pipeline s3://my_s3_bucket/pdfworkspaces/exampleworkspace
如果您在Ai2,并想使用beaker高效地线性化数百万PDF文件,只需添加--beaker
标志。这将准备您本地机器上的工作区,然后在集群中启动N个GPU工作节点以开始转换PDF。
例如:
python -m olmocr.pipeline s3://my_s3_bucket/pdfworkspaces/exampleworkspace --pdfs s3://my_s3_bucket/jakep/gnarly_pdfs/*.pdf --beaker --beaker_gpus 4
管道完整文档
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]workspaceManager for running millions of PDFs through a batch inference pipelinepositional arguments: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/options:-h, --help show this help message and exit--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--workspace_profile WORKSPACE_PROFILES3 configuration profile for accessing the workspace--pdf_profile PDF_PROFILES3 configuration profile for accessing the raw pdf documents--pages_per_group PAGES_PER_GROUPAiming for this many pdf pages per work item group--max_page_retries MAX_PAGE_RETRIESMax number of times we will retry rendering a page--max_page_error_rate MAX_PAGE_ERROR_RATERate of allowable failed pages in a document, 1/250 by default--workers WORKERS Number of workers to run at a time--apply_filter Apply basic filtering to English pdfs which are not forms, and not likely seo spam--stats Instead of running any job, reports some statistics about the current workspace--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 theone which is fastest to access--model_max_context MODEL_MAX_CONTEXTMaximum context length that the model was fine tuned under--model_chat_template MODEL_CHAT_TEMPLATEChat template to pass to sglang server--target_longest_image_dim TARGET_LONGEST_IMAGE_DIMDimension on longest side to use for rendering the pdf pages--target_anchor_text_len TARGET_ANCHOR_TEXT_LENMaximum amount of anchor text to use (characters)--beaker Submit this job to beaker instead of running locally--beaker_workspace BEAKER_WORKSPACEBeaker workspace to submit to--beaker_cluster BEAKER_CLUSTERBeaker clusters you want to run on--beaker_gpus BEAKER_GPUSNumber of gpu replicas to run--beaker_priority BEAKER_PRIORITYBeaker priority level for the job
伊织 xAI 2025-05-01(二)