Dharma Field Extractor: Any Document In, Structured Fields in JSON Out

本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。

Dharma Field Extractor: Any Document In, Structured Fields in JSON Out

Dharma Field Extractor:输入任意文档,输出结构化 JSON 字段

Back to Articles Dharma Field Extractor: Any Document In, Structured Fields in JSON Out Team Article Published November 4, 2026 Upvote 16 +10 Gabriel Pimenta de Freitas Cardoso GabrielPimenta99 Follow Dharma-AI Paulo Henrique de Medeiros Araujo Paulo-DharmaAI Follow Dharma-AI Bruno Duarte brunoduarte01 Follow Dharma-AI Francisco de Almeida Rocha Alves falves9101 Follow 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.

返回文章列表 Dharma Field Extractor:输入任意文档,输出结构化 JSON 字段。团队文章,发布于 2026 年 11 月 4 日。点赞 16 +10。Gabriel Pimenta de Freitas Cardoso、Paulo Henrique de Medeiros Araujo、Bruno Duarte、Francisco de Almeida Rocha Alves 关注 Dharma-AI。这是一个拥有 20 亿参数的模型,能够从任何类型的文档中精确提取你所要求的字段,其性能优于我们测试过的所有前沿大语言模型(LLM),且成本仅为后者的一小部分。

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.

今年 4 月,我们发布了 DharmaOCR-LITE,这是一款专门用于处理各种文档的 OCR 模型,涵盖从合同、法庭文件到发票、身份证件和表格等多种类型。其背后的论文提出了一个精准且经过深思熟虑的观点,即领域专业化:一个针对特定任务训练的小型模型,在处理该任务时能够胜过通用的前沿 API。

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.

OCR 可以为你提供页面上的文本,并忠实于原始格式。当你需要处理整个文档时(例如从头到尾阅读一份合同或数字化一份手稿),这正是你所需要的。然而,还有另一种使用场景:你不需要整个页面,而是需要从中提取特定的字段,并将其转换为下游系统可以使用的格式。

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.

例如,将发票上的每一项明细提取为列表;从医疗申请单中提取患者姓名、检查类型和日期,以便进行预约;或者将身份证件上的字段映射到员工记录的列中。如果通过 OCR 运行这些文档,你只会得到逐行打印的所有内容,而无法区分哪个字符串是检查类型,哪个是日期,或者哪个数字是总金额。

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.

在数据进入数据库之前,仍然需要有人编写代码将每个值映射到正确的字段。如今,通过精心设计的提示词(Prompting),通用大语言模型可以完成这项工作。但在处理许多企业需要大规模运行的任务时,考虑到前沿 API 的定价和延迟,这很快就会成为解决一个明确问题的高成本方案。因此,我们专门为此构建了一个模型。

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.

Field Extractor 接收文档图像,以及“提取所有能找到的内容”的请求或“待填充的精确模式(Schema)”,并返回结构化的 JSON:按字段分类、标注类型,并根据文档结构进行嵌套。发票返回时,每一项明细都作为有序列表,包含各自的数量和价值,以及总计金额。身份证件返回时,字段名称将与你系统中已使用的名称一致。同一个检查点(Checkpoint)可以处理所有这些任务,无需针对每种类型进行微调。你可以在此处亲自尝试。

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.

使用 Field Extractor 有两种请求方式:开放式(Open):不提供模式。模型通过上下文和布局(而非固定的字段名称列表)读取页面,并判断哪些部分是结构化字段(例如标签后跟值,或带有标题行的表格),然后将找到的所有内容以键值对的形式返回。

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.

模式导向式(Schema-directed):你指定所需的精确格式,逐个字段定义类型(字符串、数字或布尔值),并使用你系统中已有的键名。如果你要求“service_provider”和“client_company”,返回的键名将完全一致。如果你要求提取表格,它会逐行逐列填充,将每个单元格匹配到所属的键下。如果你要求的字段在文档中不存在,它会返回 null,而不是编造一个值。

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.

选择哪种方式取决于你已知的信息。当你不知道文档包含什么内容时,发送开放式请求;当输出必须匹配现有格式时,发送模式导向式请求。无论哪种方式,返回的都是 JSON:字段作为键,值按要求标注类型,文档中缺失的内容则返回 null。当你发送模式时,输出将严格遵循该模式,使用相同的键且不包含额外字段,因此可以直接进入下一个系统。

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.

训练过程:基础模型是 DharmaOCR-LITE v1.1,这是一个从论文模型优化而来的全新 20 亿参数版本,已通过监督微调和 DPO 专门针对 OCR 进行了优化。在此检查点之上,我们使用 43,384 个涵盖两种请求模式的训练示例训练了一个 LoRA 适配器。数据分为三个流:英语多领域数据(从公共网络收集的各种文档,涵盖多种类型)、巴西领域数据(内部来源的真实巴西文档,使用葡萄牙语)、多语言数据(涵盖其他欧洲和亚洲语言的一小部分数据,旨在实现除英语和葡萄牙语之外更广泛的泛化)。

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.

基准测试的界限:完整的基准测试涵盖了三种请求场景下的 546 份文档,总计 1,638 个案例:无模式提取所有字段、仅命名真实字段的部分模式,以及包含故意不存在字段的模式。评分标准是字段级 F1 分数(按路径匹配,包括表格内的位置),乘以匹配值的 Levenshtein 相似度,再乘以返回有效 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

我们针对四种通用前沿配置运行了相同的基准测试。与通用大语言模型相比,质量差距从 1.8 个点(最接近的 Claude Opus 5)到 9.3 个点(差距最大的 GPT-5.6 Luna)不等。成本方面,大约低 6 倍(GPT-5.6 Luna)到大约低 147 倍(GPT-5.6 Sol)。双方的定价方式不同。前沿……