一个拥有20亿参数的模型,能够从任何类型的文档中精确提取您要求的字段,性能超越了我们测试过的所有前沿大语言模型,且成本仅为其中的一小部分。
今年四月,我们发布了DharmaOCR-LITE,这是一款专为广泛文档类型进行光学字符识别(OCR)的模型,涵盖合同、法院文件、发票、身份证件和表格等。其背后的论文提出了一个观点明确且有据可依的主张:领域专业化。即通过更贴近任务场景训练出的较小模型,在该特定任务上优于通用型前沿API。
OCR为您提供页面上的文本,并忠实保留原始格式。当您的工作涉及整个文档时,这正是您所需要的,例如通读一份合同或数字化一份手稿。
然而,存在另一种使用场景:您不需要整页内容,而是需要从中提取特定的字段,并以下游系统可消费的格式呈现。例如,将发票上的每一行项目作为列表列出;从医疗申请单中提取患者姓名、检查类型和日期,以便安排日程;或将身份证件上的字段映射到员工记录的列中。
如果将文档通过OCR处理,您将得到页面上打印的所有内容,逐行返回,但没有任何指示表明哪段字符串是检查类型,哪段是日期,哪个数字是总额。在数据到达数据库之前,仍有人需要编写代码,将每个值映射到正确的字段中。
通用大语言模型今天可以通过精心设计的提示词完成这项工作。但在前沿API的定价和延迟下,对于许多企业需要高频率执行的任务来说,这很快会成为解决一个定义明确的问题的高成本方案。
因此,我们为此构建了一个专用模型。Field Extractor(字段提取器)接收文档图像以及“提取所有可发现内容”的请求或用于填充的确切模式,并返回结构化的JSON:按类型、逐个字段输出,并在文档嵌套处保持嵌套结构。发票将以有序列表的形式返回每一行项目,每项包含其数量和金额,同时附带总额。身份证件将返回您存储所需的字段,使用您的系统已为其定义的键名。同一个检查点处理所有情况,无需针对每种类型进行微调。
您可以在此处自行尝试。
模型的功能
假设每天早上有一批供应商发票到达,您需要从每张发票中提取四项内容以推送到您的系统中:供应商、发票号码、到期日和总额。对于进入调度系统的医疗申请单,或为合规系统提供数据的合同,情况也是如此,关键在于当事人、期限、罚款和罚金金额。您不需要整页内容,只需要特定的字段。使用Field Extractor有两种请求方式:
开放模式:不提供模式。模型读取页面,并根据上下文和布局(而非固定的字段名称列表)确定哪些部分是结构化字段(如标签后跟值、表头位于列上方的表格),并返回其发现的所有内容作为键值对。
模式引导模式:您指定所需的精确形状,逐个字段定义,并为每个字段指定类型(字符串、数字或布尔值),使用您的系统已使用的键名。请求“service_provider”和“client_company”,返回的键名将完全一致。请求一个表格,它将逐行、逐列填充,将每个单元格匹配到其所属的键下。如果请求的字段在文档中不存在,则返回null而非编造值。
选择取决于您已知的信息。当不知道文档包含什么时,发送开放请求。当输出必须与某处已存在的形状匹配时,发送模式。
无论哪种方式,返回的都是JSON:字段作为键,值按请求的类型化,在文档未提供所请求内容的位置为null。当您发送模式时,输出将严格遵循该模式,具有相同的键且无额外字段,因此可以直接进入下一个系统。
训练过程
基础模型是 DharmaOCR-LITE v1.1,这是一个新的 20 亿参数版本,在论文中的模型基础上进行了优化,并通过监督微调(SFT)和直接偏好优化(DPO)专门针对光学字符识别(OCR)进行了调整。在该检查点之上,我们在涵盖两种请求模式的 43,384 个训练样本上训练了一个 LoRA 适配器。
数据被组织成三个流:
英语多领域数据:从公共网络收集的多样化文档,涵盖多种文档类型。
巴西领域数据:内部来源的真实巴西文档,使用葡萄牙语。
多语言数据:较小的一部分,涵盖其他欧洲和亚洲语言,以实现超越英语和葡萄牙语的更广泛泛化能力。
所有三个流都在字段级别进行了标注。这种混合刻意采用了多领域策略:包括收据、商业发票、表格、银行对账单、身份证件以及合成文档,而非单一类型的文件。
基准测试的界限在哪里
完整的基准测试涵盖 546 份文档,涉及三种请求场景,共计 1,638 个案例:提取所有字段且无模式约束、仅命名真实字段的局部模式,以及包含故意不存在的字段的完整模式。评分基于字段级别的 F1 分数(通过路径匹配,包括表格内的位置),乘以匹配值的 Levenshtein 相似度,再乘以返回有效 JSON 的输出比例。
我们将相同的基准测试应用于四种通用前沿配置。
与通用大型语言模型相比,质量差距从 1.8 分(Claude Opus 5,最接近者)到 9.3 分(GPT-5.6 Luna,差距最大者)不等。
成本方面,从大约低 6 倍(GPT-5.6 Luna)到大约低 147 倍(GPT-5.6 Sol)不等。双方的定价方式不同。前沿模型的数据基于每页平均输入和输出令牌数(包括推理令牌)与各提供商公布的列表价格进行对比。所有前沿模型均将推理设置为低级别;Claude Opus 5 使用自适应努力机制,可以在处理较简单的页面时跳过推理,同时保持在低级别。我们的模型不按令牌计费:该模型为自托管运行,因此该数据基于单台 L40S GPU 的 GPU 时间计算,每小时成本为 2.24 美元。
这不是销售价格。自托管成本取决于硬件、吞吐量以及每个部署所需的延迟。此处进行比较是为了表明,部署在您自有基础设施上的主权小型语言模型(SSLM)是前沿 API 的真实替代方案。
泛化能力的测试
SROIE 和 FUNSD 是我们基准测试中的两个公开数据集,未在训练中使用。以下是来自每个数据集的一个示例。
在一张 SROIE 收据上,我们要求提取其打印的所有 18 个字段,此次没有幻影字段,结果所有字段均正确返回:多行且无标签的账单地址被捕获为单个字段,两个空白字段(销售员和参考号)正确返回为 null,收据上的每个数字均精确匹配到分。
在一张 FUNSD 复印差异表上,这是一个包含十二个布尔字段的清单,其中嵌套了一组五个子选项。模型准确标记了唯一勾选的复选框(原件质量差,旁边有手写“褪色”备注)为 true,其余十一个为 false,与表格完全匹配。它还正确读取了页面上的手写 Bates ID,并为两个留空的字段返回 null。
同时实现高质量与低成本
一个 20 亿参数的模型取得了 0.834 的得分,高于我们测试的所有前沿配置,从 Claude Opus 5 的 0.816 到 GPT-5.6 Luna 的 0.741,同时在单台 L40S 上运行,每次提取的成本低于比较中的每个 API。在相同的基准测试、相同的运行条件下,实现了更高的质量和更低的成本。
这并非我们首次对此进行测量。我们的 OCR 论文曾指出,首个 DharmaOCR-LITE(一个拥有 30 亿参数的模型)在巴西葡萄牙语任务上超越了所有 tested 的商业前沿 API;三个月后,尽管出现了更新、资源更丰富的模型,这一优势依然保持。如今,一个拥有 20 亿参数的模型在字段提取任务上也实现了同样的突破。每一项结果都为我们要论证的论点提供了佐证:该论点是 Dharma-AI 创立之初的核心主张——在限定任务中,针对该任务训练的较小模型,优于被要求通用执行相同任务的前沿模型。在本基准测试中,其运行成本也仅为前者的 1/6 到 1/147。
参数量设定了上限;训练决定了模型在你的任务中能触及多少潜力。你的业务不需要最大的可用模型,它需要的是一款为你的问题而训练的模型。
在此处试用你自己的文档 。如需了解更多关于 Dharma-AI 及我们构建的专业模型的信息,请访问 dharma-ai.com 。
来源
BID. 巴西身份文件数据集(Brazilian Identity Document Dataset)。Soares, Neves Jr., Bezerra (2020), “BID Dataset: a challenge dataset for document processing tasks,” Anais Estendidos XXXIII SIBGRAPI。github.com/ricardobnjunior/Brazilian-Identity-Document-Dataset
CORD. Park 等人,NAVER CLOVA (2019)。huggingface.co/datasets/naver-clova-ix/cord-v2
DocVQA. Mathew 等人,WACV 2021 (ICDAR 2019)。huggingface.co/datasets/lmms-lab/DocVQA
WildReceipt. Sun 等人,IJCAI 2021。huggingface.co/datasets/Theivaprakasham/wildreceipt
SROIE (ICDAR 2019)。从训练中剔除,仅用于评估。huggingface.co/datasets/darentang/sroie(镜像);上游 rrc.cvc.uab.es/?ch=13
FUNSD. Jaume 等人。从训练中剔除,仅用于评估。huggingface.co/datasets/nielsr/funsd(镜像);guillaumejaume.github.io/FUNSD
Zenodo 发票 (PT)。Cruz & Castelli, NOVA IMS (2022)。zenodo.org/records/6371710
line_items。Sagarjha456,Hugging Face。huggingface.co/datasets/Sagarjha456/line_items
Katanaml 发票 (Donut)。Kozłowski & Weichbroth (2021),Mendeley Data doi:10.17632/tnj49gpmtz.2 。huggingface.co/datasets/katanaml-org/invoices-donut-data-v1
HumynLabs 巴西账单和发票。huggingface.co/datasets/HumynLabs/Brazilian_Bills_and_Invoices_Dataset
Tech4Humans BR-Doc Extraction。huggingface.co/datasets/tech4humans/br-doc-extraction
Cardoso, Gabriel Pimenta de Freitas 等人。“DharmaOCR: Specialized Small Language Models for Structured OCR that outperform Open-Source and Commercial Baselines。” arXiv preprint arXiv:2604.14314 (2026)。
延伸阅读
在 Hugging Face 上探索 Dharma AI,试用我们的交互式演示 ,下载我们的开源模型 ,并了解专业人工智能系统如何在真实的企业应用中超越通用模型。
A 2-billion-parameter model that extracts exactly the fields you ask for, from any document type, outperforming every frontier LLM we tested, at a fraction of the cost.
In April, we released DharmaOCR-LITE , a model specialized for OCR across a wide range of documents, from contracts and court filings to invoices, IDs and forms. The paper behind it made a narrow, well-measured case for domain specialization: a smaller model trained closer to its task beating general-purpose frontier APIs on that task.
OCR gives you the text on a page, faithful to the original formatting. That's exactly what you want when the job is the whole document, like a contract you'll read end to end or a manuscript you're digitizing.
However, there's a different use case: you don't want the page, you want specific fields out of it, in a shape a system downstream can consume. Every line item on an invoice, as a list. The patient name, exam type and date from a medical requisition, ready to schedule. The fields off an ID, mapped to the columns of an employee record.
Run that document through OCR and you get back everything printed on it, line by line, with no indication of which string is the exam type, which is the date or which number is the total. Someone still has to write the code that maps each value to the right field before it reaches the database.
A general-purpose LLM can do this work today, with careful prompting. At frontier API pricing and latency, on a task many businesses need to run at high volume, that quickly becomes the expensive way to solve a well-defined problem.
So we built a model for it instead. The Field Extractor takes a document image and either a request for everything it can find, or an exact schema to fill, and returns structured JSON: typed, field by field, nested where the document nests. An invoice comes back with every line item as an ordered list, each with its own quantity and value, alongside the totals. An ID comes back as the fields you'll store, under the names your system already uses for them. The same checkpoint handles all of it, with no per-type fine-tuning.
You can try it yourself here .
What the Model Does
Say a batch of supplier invoices lands every morning, and you need four things off each one to push into your system: the supplier, the invoice number, the due date, the total. Same story for medical requisitions going into a scheduler, or contracts feeding a compliance system, where what matters is the parties, the term, the penalties and the fine amounts. You don't need the page, you need certain fields. With the Field Extractor there are two ways to ask for them:
Open : no schema supplied. The model reads the page and works out which parts of it are structured fields (a label followed by a value, a table with a header row over its columns) from context and layout, not from a fixed list of field names, and returns everything it finds as key-value pairs.
Schema-directed : you specify the exact shape wanted, field by field, with a type for each one (string, number, or boolean), under the key names your system already uses. Ask for "service_provider" and "client_company", and those are the exact keys that come back. Ask for a table and it fills it row by row, column by column, matching each cell to the key it belongs under. Ask for a field that isn't on the document, and it returns null instead of inventing a value.
The choice comes down to what you already know. Send an open request when you don't know what the document holds. Send a schema when the output has to match a shape that already exists somewhere else.
Either way, what comes back is JSON: the fields as keys, the values typed as requested, and null where the document didn't have what you asked for. When you send a schema, the output follows it exactly, with the same keys and no extra fields, so it can go straight into the next system.
How It Was Trained
The base model is DharmaOCR-LITE v1.1, a new 2-billion-parameter version optimized from the one in the paper and already specialized for OCR through supervised fine-tuning and DPO. On top of that checkpoint we trained a LoRA adapter on 43,384 training examples covering both request modes.
The data is organized into three streams:
English multi-domain data : diverse documents collected from the public web, spanning many document types.
Brazilian domain data : real Brazilian documents sourced internally, in Portuguese.
Multilingual data : a smaller share covering other European and Asian languages, for broader generalization beyond English and Portuguese.
All three streams are annotated at the field level. The mix is deliberately multi-domain: receipts, commercial invoices, forms, bank statements, ID documents and synthetic documents, rather than one filing type.
Where the Benchmark Draws the Line
The full benchmark covers 546 documents across three request scenarios, for 1,638 total cases: extracting every field with no schema, a partial schema naming only real fields, and a schema that also includes deliberately nonexistent fields. The score is field-level F1 (matched by path, including position inside a table), multiplied by the Levenshtein similarity on the values that matched and by the share of outputs that come back as valid JSON.
We ran the same benchmark against four general-purpose frontier configurations.
Against general-purpose LLMs, the quality gap runs from 1.8 points (Claude Opus 5, the closest) to 9.3 points (GPT-5.6 Luna, the widest).
Cost runs from roughly 6 times lower (GPT-5.6 Luna) to roughly 147 times lower (GPT-5.6 Sol). The two sides are priced differently. The frontier figures come from measured average input and output tokens per page, reasoning tokens included, against each provider's published list pricing. Every frontier model ran with reasoning set to low; Claude Opus 5 used adaptive effort, which can skip reasoning on simpler pages while staying at the low level. Ours isn't billed per token: the model runs self-hosted, so the figure is GPU time on a single L40S at $2.24 per hour.
This is not a sales price. Self-hosted cost depends on the hardware, the volume and the latency each deployment needs. The comparison is here to show that a sovereign SSLM, deployed on your own infrastructure, is a real alternative to frontier APIs.
A Test of Generalization
SROIE and FUNSD are two public datasets in our benchmark, not used in training. Below is one example from each.
On a SROIE receipt, we asked for all 18 fields printed on it, with no phantom fields this time, and every one comes back correct: the multi-line, unlabeled billing address captured as a single field, the two blank fields (salesperson and ref) correctly returned as null, and every number on the receipt matching to the cent.
On a FUNSD photocopying variance form, a checklist of twelve boolean fields with one nested group of five sub-options, the model marks exactly the one box that's checked (poor quality original, with a handwritten "faded" note beside it) as true, and the other eleven as false, matching the form exactly. It also reads the handwritten Bates ID off the page correctly, and returns null for the two fields left blank.
Quality and Cost, at the Same Time
A 2-billion-parameter model scored 0.834, above every frontier configuration we tested, from Claude Opus 5 at 0.816 to GPT-5.6 Luna at 0.741, while running on a single L40S at a lower cost per extraction than every API in the comparison. Higher quality and lower cost, measured on the same benchmark, in the same run.
This isn't the first time we've measured it. Our OCR paper put the first DharmaOCR-LITE, a 3-billion-parameter model, above every commercial frontier API tested on Brazilian Portuguese; three months later, newer and better-resourced models arrived, and the gap held. Now a 2-billion-parameter model does it on field extraction. Each result adds evidence for the thesis we started Dharma-AI with: on a bounded task, a small model trained close to that task beats a frontier model asked to do the same thing in general. In this benchmark, it also cost 6 to 147 times less to run.
Parameter count sets the ceiling; training decides how much of it a model reaches on your task. Your business doesn't need the biggest model available. It needs one trained for your problem.
Try it on your own documents here . To learn more about Dharma-AI and the specialized models we build, visit dharma-ai.com .
Sources
BID. Brazilian Identity Document Dataset. Soares, Neves Jr., Bezerra (2020), "BID Dataset: a challenge dataset for document processing tasks," Anais Estendidos XXXIII SIBGRAPI. github.com/ricardobnjunior/Brazilian-Identity-Document-Dataset
CORD. Park et al., NAVER CLOVA (2019). huggingface.co/datasets/naver-clova-ix/cord-v2
DocVQA. Mathew et al., WACV 2021 (ICDAR 2019). huggingface.co/datasets/lmms-lab/DocVQA
WildReceipt. Sun et al., IJCAI 2021. huggingface.co/datasets/Theivaprakasham/wildreceipt
SROIE (ICDAR 2019). Held out from training, evaluation only. huggingface.co/datasets/darentang/sroie (mirror); upstream rrc.cvc.uab.es/?ch=13
FUNSD. Jaume et al. Held out from training, evaluation only. huggingface.co/datasets/nielsr/funsd (mirror); guillaumejaume.github.io/FUNSD
Zenodo Invoices (PT). Cruz & Castelli, NOVA IMS (2022). zenodo.org/records/6371710
line_items. Sagarjha456, Hugging Face. huggingface.co/datasets/Sagarjha456/line_items
Katanaml Invoices (Donut). Kozłowski & Weichbroth (2021), Mendeley Data doi:10.17632/tnj49gpmtz.2 . huggingface.co/datasets/katanaml-org/invoices-donut-data-v1
HumynLabs Brazilian Bills and Invoices. huggingface.co/datasets/HumynLabs/Brazilian_Bills_and_Invoices_Dataset
Tech4Humans BR-Doc Extraction. huggingface.co/datasets/tech4humans/br-doc-extraction
Cardoso, Gabriel Pimenta de Freitas, et al. "DharmaOCR: Specialized Small Language Models for Structured OCR that outperform Open-Source and Commercial Baselines." arXiv preprint arXiv:2604.14314 (2026).
Further Reading
Explore Dharma AI on Hugging Face to try our interactive demos , download our open-source models , and discover how specialized AI systems outperform general-purpose models in real enterprise applications.
首次收录 · 2026-11-05 · 10.74 分