【源码阅读】olmocr中的prompts

[复制链接]
发表于 2025-10-13 12:32:26 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
一、PDF转换为练习数据


让 ChatGPT-4 将文档(如 PDF 文件)转换为结构化的“银级”练习数据(silver training data)
  1. # This is the prompt we use for getting chat gpt 4o to convert documents into our silver training data
  2. def build_openai_silver_data_prompt(base_text: str) -> str:
  3.     return (
  4.         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). "
  5.         f"Just return the plain text representation of this document as if you were reading it naturally.\n"
  6.         f"Turn equations into a LaTeX representation, and tables into markdown format. Remove the headers and footers, but keep references and footnotes.\n"
  7.         f"Read any natural handwriting.\n"
  8.         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"
  9.         f"If there is no text at all that you think you should read, you can output null.\n"
  10.         f"Do not hallucinate.\n"
  11.         f"RAW_TEXT_START\n{base_text}\nRAW_TEXT_END"
  12.     )
复制代码
以下是 PDF 文档某一页的图像,以及之前为该页提取的一些原始文本内容,此中包罗每个图像和文本块的位置信息(坐标的起始点 [0x0] 位于图像的左下角)。 请将此文档的纯文本表现情势原原来本地返回,就好像您是在天然状态下阅读它一样。 将方程转换为 LaTeX 表现情势,将表格转换为 Markdown 格式。删除页眉和页脚,但生存引用和脚注。 读取任何天然手写体。 这很大概是文档中多少页中的一页,因此请务必生存来自前一页的任何句子,大概假如必要的话直接转到下一页,保持其原样。 假如您以为文档中没有任何您以为应该阅读的文本,您可以输出 null。 不要产生幻觉。
提示词写的很完备,清晰且具体,如许才气将模子输出得到的是险些和原pdf一样格式准确的markdown
二、使用微调模子


  1. # This is a base prompt that will be used for training and running the fine tuned model
  2. # It's simplified from the prompt which was used to generate the silver data, and can change from dataset to dataset
  3. def build_finetuning_prompt(base_text: str) -> str:
  4.     return (
  5.         f"Below is the image of one page of a document, as well as some raw textual content that was previously extracted for it. "
  6.         f"Just return the plain text representation of this document as if you were reading it naturally.\n"
  7.         f"Do not hallucinate.\n"
  8.         f"RAW_TEXT_START\n{base_text}\nRAW_TEXT_END"
  9.     )
复制代码
天生一个底子提示(prompt),该提示将用于**微调模子(fine-tuning)**或在微调后的模子上运行使命
提示内容详解: 天生的提示包罗以下指令: 告诉模子,输入是一个文档的某一页的图像及其提取的原始文本内容。 返回文档的天然阅读文本。明白要求模子不要天生虚伪内容(即不要“幻觉”)。 使用 RAW_TEXT_START 和 RAW_TEXT_END 标记包裹原始文本内容,以便模子辨认。
这应该是一个底子的prompt,不消于具体的实行步调
三、比力差别


让模子比力两个差别模子从同一文档页面提取的文本内容,并找出差别,同时判断哪个模子的提取结果更正确。
  1. def build_find_difference_prompt(base_text: str) -> str:
  2.     return (
  3.         f"Below is an image of a document page, along with raw textual content previously extracted using different models."
  4.         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."
  5.         f"Only return the differences and specify which model extracted the text with higher accuracy.\n"
  6.         f"Do not hallucinate.\n"
  7.         f"RAW_TEXT_START\n{base_text}\nRAW_TEXT_END"
  8.     )
复制代码
输入是一个文档页面的图像以及两段从差别模子提取的原始文本内容。过细比力两段提取文本的差别。通过对比图像,确定哪一段文本提取得更正确。只输出两段文本之间的差别。明白指出哪个模子的提取结果更正确。明白要求模子不要天生虚伪内容(即不要“幻觉”)。使用 RAW_TEXT_START 和 RAW_TEXT_END 标记包裹原始文本内容,以便模子辨认。
总结


这个提示词确实一步步写的清晰具体,而且给了充足的思索过程,有一个头脑链的感觉,让他渐渐地按步调去推理。然后给的配景信息放在最反面

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

×
登录参与点评抽奖,加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表