【源码阅读】olmocr中的prompts

目录

一、PDF转换为训练数据


让 ChatGPT-4 将文档(如 PDF 文件)转换为结构化的"银级"训练数据(silver training data)

bash 复制代码
# This is the prompt we use for getting chat gpt 4o to convert documents into our silver training data
def build_openai_silver_data_prompt(base_text: str) -> str:
    return (
        f"Below is the image of one page of a PDF document, as well as some raw textual content that was previously extracted for it that includes position information for each image and block of text (The origin [0x0] of the coordinates is in the lower left corner of the image). "
        f"Just return the plain text representation of this document as if you were reading it naturally.\n"
        f"Turn equations into a LaTeX representation, and tables into markdown format. Remove the headers and footers, but keep references and footnotes.\n"
        f"Read any natural handwriting.\n"
        f"This is likely one page out of several in the document, so be sure to preserve any sentences that come from the previous page, or continue onto the next page, exactly as they are.\n"
        f"If there is no text at all that you think you should read, you can output null.\n"
        f"Do not hallucinate.\n"
        f"RAW_TEXT_START\n{base_text}\nRAW_TEXT_END"
    )

以下是 PDF 文档某一页的图像,以及之前为该页提取的一些原始文本内容,其中包括每个图像和文本块的位置信息(坐标的起始点 [0x0] 位于图像的左下角)。 请将此文档的纯文本表示形式原原本本地返回,就好像您是在自然状态下阅读它一样。 将方程转换为 LaTeX 表示形式,将表格转换为 Markdown 格式。删除页眉和页脚,但保留引用和脚注。 读取任何自然手写体。 这很可能是文档中若干页中的一页,因此请务必保留来自前一页的任何句子,或者如果需要的话直接转到下一页,保持其原样。 如果您认为文档中没有任何您认为应该阅读的文本,您可以输出 null。 不要产生幻觉。

提示词写的很完整,清晰且具体,这样才能将模型输出得到的是几乎和原pdf一样格式正确的markdown

二、使用微调模型


bash 复制代码
# This is a base prompt that will be used for training and running the fine tuned model
# It's simplified from the prompt which was used to generate the silver data, and can change from dataset to dataset
def build_finetuning_prompt(base_text: str) -> str:
    return (
        f"Below is the image of one page of a document, as well as some raw textual content that was previously extracted for it. "
        f"Just return the plain text representation of this document as if you were reading it naturally.\n"
        f"Do not hallucinate.\n"
        f"RAW_TEXT_START\n{base_text}\nRAW_TEXT_END"
    )

生成一个基础提示(prompt),该提示将用于**微调模型(fine-tuning)**或在微调后的模型上运行任务
提示内容详解: 生成的提示包含以下指令: 告诉模型,输入是一个文档的某一页的图像及其提取的原始文本内容。 返回文档的自然阅读文本。明确要求模型不要生成虚假内容(即不要"幻觉")。 使用 RAW_TEXT_START 和 RAW_TEXT_END 标记包裹原始文本内容,以便模型识别。

这应该是一个基础的prompt,不用于具体的执行步骤

三、比较差异


让模型比较两个不同模型从同一文档页面提取的文本内容,并找出差异,同时判断哪个模型的提取结果更准确。

bash 复制代码
def build_find_difference_prompt(base_text: str) -> str:
    return (
        f"Below is an image of a document page, along with raw textual content previously extracted using different models."
        f"Your goal is to carefully identify the differences between the extracted texts from both models and determine which one is more accurate by comparing them with the image."
        f"Only return the differences and specify which model extracted the text with higher accuracy.\n"
        f"Do not hallucinate.\n"
        f"RAW_TEXT_START\n{base_text}\nRAW_TEXT_END"
    )

输入是一个文档页面的图像以及两段从不同模型提取的原始文本内容。仔细比较两段提取文本的差异。通过对比图像,确定哪一段文本提取得更准确。只输出两段文本之间的差异。明确指出哪个模型的提取结果更准确。明确要求模型不要生成虚假内容(即不要"幻觉")。使用 RAW_TEXT_START 和 RAW_TEXT_END 标记包裹原始文本内容,以便模型识别。

总结


这个提示词确实一步步写的清晰具体,而且给了足够的思考过程,有一个思维链的感觉,让他慢慢地按步骤去推理。然后给的背景信息放在最后面

相关推荐
weixin_3975740910 天前
PDF复杂表格的1:1还原引擎:跨页表格自动拼接技术实战
大数据·人工智能·pdf
Metaphor69210 天前
使用 Python 将 PDF 转换为 HTML
python·pdf·html
2601_9618451510 天前
粉笔行测5000题电子版|pdf|解析
pdf·新媒体运营·github·个人开发·内容运营·规格说明书·极限编程
Sour10 天前
PDF翻译卡住不动怎么办?扫描件、OCR 和大文件排查清单
前端·pdf·ocr
狂奔solar10 天前
OpenDataLoader-PDF 做 PDF 解析可视化调试器
pdf·rag 预处理
chatexcel10 天前
ChatExcel Max使用教程:图片、PDF、网页与复杂Excel的一站式数据分析
数据分析·pdf·excel
绘梨衣54710 天前
PDF表格解析知识总结
开发语言·python·pdf
qq_5469372710 天前
Excel批量转PDF_Word_图片,支持自动合并报表,效率翻倍。
pdf·word·excel
zyplayer-doc11 天前
企业知识库安全与权限管理完全指南:从加密到审计的六层防护
人工智能·安全·pdf·编辑器·创业创新
易鹤鹤.11 天前
pdf标注高亮
pdf