今年早些时候,艾伦人工智能研究所发布了olmOCR——一个基于Qwen2-VL-7B视觉语言模型(VLM)的开源文档OCR工具。看到这个高质量、开放源码的PDF及复杂文档解析方案时我们倍感振奋,并开始探索如何通过更新的基础模型和轻量化优化实现更多可能性。
由此诞生的RolmOCR,作为olmOCR的即插即用替代方案,不仅运行速度更快、内存占用更低,还能在各种文档类型上保持优异性能。我们以Apache 2.0协议开源此项目,供所有人试用、研究或二次开发。
该模型是在完整allenai/olmOCR-mix-0225数据集上微调Qwen/Qwen2.5-VL-7B-Instruct得到的版本。
我们进行了三项重要调整:
新版基础模型:采用更新的Qwen2.5-VL-7B模型作为基础架构
取消元数据输入:与原始方案不同,我们不再使用从PDF提取的元数据。此举显著缩短提示词长度,从而降低处理时间和显存占用,且在多数情况下不影响识别精度
训练数据旋转增强:对约15%的训练数据实施旋转处理,提升模型对非常规角度文档的鲁棒性。其余训练集保持不变
通过vLLM部署模型:
export VLLM_USE_V1=1
vllm serve reducto/RolmOCR 通过OpenAI兼容服务器调用模型:
# HOST YOUR OPENAI COMPATIBLE API WITH THE FOLLOWING COMMAND in VLLM:
# export VLLM_USE_V1=1
# vllm serve reducto/RolmOCR
from openai import OpenAI
import base64
client = OpenAI(api_key="123", base_url="http://localhost:8000/v1")
model = "reducto/RolmOCR-7b"
def encode_image(image_path):
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode("utf-8")
def ocr_page_with_rolm(img_base64):
response = client.chat.completions.create(
model=model,
messages=[
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": {"url": f"data:image/png;base64,{img_base64}"},
},
{
"type": "text",
"text": "Return the plain text representation of this document as if you were reading it naturally.\n",
},
],
}
],
temperature=0.2,
max_tokens=4096
)
return response.choices[0].message.content
test_img_path = "path/to/image.png"
img_base64 = encode_image(test_img_path)
print(ocr_page_with_rolm(img_base64))@misc{RolmOCR,
author = {Reducto AI},
title = {RolmOCR: A Faster, Lighter Open Source OCR Model},
year = {2025},
}