新闻动态
体育游戏app平台 XML ) 压缩包使用方式上-开云官网切尔西赞助商(2025已更新(最新/官方/入口)
微软官方开源了一款文献方法调遣器具——MarkItDown!体育游戏app平台
它不仅不错将常见的 Office 文档(Word、PowerPoint、Excel)、PDF、图像、音频等调遣为对大模子更友好的Markdown方法。
况且还赞成集成像 GPT-4o 这么的多模态 LLM,不错告成对图片、音频文献进行更高档的解决,比如快速输出买卖呈报。
以后设立者们上传进修数据、微调 LLM 愚弄都更便捷了。
发布仅两个月,它的 GitHub 保藏数就卓绝了3 万。
具体来说,它赞成的文献方法包括:
PowerPoint
Word
Excel
图像(含 OCR 和 EXIF 元数据)
音频(含 EXIF 元数据和转录)
HTML
其他基于文本的方法 ( CSV, JSON, XML )
压缩包
使用方式上,MarkItDown 提供了敕令行、Python API以及Docker三种形势。
关注网友 Aark Kodur 还制作了在线版的网页愚弄,点开网址就能告成试用。
可接多模态 LLM 告成生成呈报
哥伦比亚大学讲师Tharsis 用一个证券呈报分析任务测试了 MarkItDown 的性能,同期也将它与 IBM 的热点 Markdown 调遣库Docling进行了对比,一都来望望吧。
当先望望两个库的基本信息。
MarkItDown 是由微软 AutoGen 团队设立的 Python 包和 CLI,用于将各式文献方法调遣为 Markdown。
它赞成包括 PDF、PowerPoint、Word、Excel、图像(含 OCR 和 EXIF 元数据)、音频(含转录)、HTML 以偏激他基于文本的方法,是文档索引和构建基于 LLM 愚弄方法的有效器具。
主要特色:
浅易敕令行和 Python API 接口
赞成多种文献方法
可集成 LLM增强图像描摹
赞成批解决智商
赞成Docker容器化使用
使用示例:
from markitdown import MarkItDown
md = MarkItDown ( ) result = md.convert ( "test.xlsx" ) print ( result.text_content )
Docling 是由 IBM 磋议院设立的 Python 包,用于瓦解和将文档调遣为各式方法。
它提供高档文档默契智商,要点在于保握文档结构和方法。
赞成多种文档方法(PDF、DOCX、PPTX、XLSX、图片、HTML 等)
高档 PDF 瓦解,包括布局分析和表格索要
调处的文档暗示方法
集成LlamaIndex 和 LangChain
赞成 OCR 分析扫描文档
浅易敕令行界面
from docling.document_converter import DocumentConverter
converter = DocumentConverter ( ) result = converter.convert ( "document.pdf" ) print ( result.document.export_to_markdown ( ) )
本案例磋议将主要从好意思林证券(Merrill Lynch)于 2024 年 12 月 16 日发布的首席信息官成本阛阓预测中索要经济预测。
咱们将主要关注该文档的第 7 页,其中包含多个经济变量,这些变量以表格、文本和图像的搀杂形势组织。
FORECAST_FILE_PATH = "../data/input/forecast.pdf"
当先,咱们将使用 MarkItDown 从文档中索要文本内容。
from markitdown import MarkItDown
md = MarkItDown ( ) result_md = md.convert ( FORECAST_FILE_PATH ) .text_content
接下来,咱们使用 Docling 进行相同的操作。
from docling.document_converter import DocumentConverter
converter = DocumentConverter ( ) forecast_result_docling = converter.convert ( source ) .document.export_to_markdown ( )
这两个效果有多相似?
咱们不错使用Levenshtein 距离来斟酌两个效果之间的相似度。
还不错使用 difflib 包中的SequenceMatcher来盘算一个浅易的分数,这是基于最长巨匠子序列中匹配数来斟酌两个字符串相似度的一个浅易度量。
import Levenshteindef levenshtein_similarity ( text1: str, text2: str ) -> float: """ Calculate normalized Levenshtein distance Returns value between 0 ( completely different ) and 1 ( identical ) """ distance = Levenshtein.distance ( text1, text2 ) max_len = max ( len ( text1 ) , len ( text2 ) ) return 1 - ( distance / max_len )
from difflib import SequenceMatcherdef simple_similarity ( text1: str, text2: str ) -> float: """ Calculate similarity ratio using SequenceMatcher Returns value between 0 ( completely different ) and 1 ( identical ) """ return SequenceMatcher ( None, text1, text2 ) .ratio ( )
底下是 Levenshtein 和 SequenceMatcher 的具体分数:
levenshtein_similarity ( forecast_result_md, forecast_result_docling )
0.13985705461925346
simple_similarity ( forecast_result_md, forecast_result_docling )
0.17779960707269155
效果显露,这两个效果相配不同,Levenshtein 和 SequenceMatcher 的相似度得分分离为约 13.98% 和 17.77%。
Docling 的效果是一份极度易读的 Markdown,展示了要道经济变量偏激预测。
相悖,MarkItDown 的效果有些狼藉,难以阅读,但信息如实存在,仅仅莫得以结构化的方法呈现。
可是,这费力吗?
先来望望 Docling 的效果:
display ( Markdown ( forecast_result_docling ) )
MarkItDown 的效果:
from IPython.display import display, Markdowndisplay ( Markdown ( forecast_result_md [ :500 ] ) )
现时,让咱们看一下经济预测的效果,主要关注索要 CIO 的 2025E 预测。
咱们将界说一个 Forecast pydantic 模子来暗示由 financial_variable 和 financial_forecast 构成的经济预测。
界说另外一个 EconForecast pydantic 模子来暗示咱们思要从文档中索要的经济预测列表。
from pydantic import BaseModelclass Forecast ( BaseModel ) : financial_variable: str financial_forecast: floatclass EconForecast ( BaseModel ) : forecasts: list [ Forecast ]
以下为指示模板,其中 extract_prompt 是用户但愿索要的数据, doc 是待分析的输入文档。
BASE_PROMPT = f""" ROLE: You are an expert at structured data extraction. TASK: Extract the following data {extract_prompt} from input DOCUMENT FORMAT: The output should be a JSON object with 'financial_variable' as key and 'financial_forecast' as value. """prompt = f"{BASE_PROMPT} nn DOCUMENT: {doc}"
咱们编写了一个浅易的函数,使用 LLM 模子(具有结构化输出)从文档中索要经济预测
def extract_from_doc ( extract_prompt: str, doc: str, client ) -> EconForecast: """ Extract data of a financial document using an LLM model. Args: doc: The financial document text to analyze client: The LLM model to use for analysis extract_prompt: The prompt to use for extraction Returns: EconForecasts object containing sentiment analysis results """
BASE_PROMPT = f""" ROLE: You are an expert at structured data extraction. TASK: Extract the following data {extract_prompt} from input DOCUMENT FORMAT: The output should be a JSON object with 'financial_variable' as key and 'financial_forecast' as value. """ prompt = f"{BASE_PROMPT} nn DOCUMENT: {doc}" completion = client.beta.chat.completions.parse ( model="gpt-4o-mini", messages= [ { "role": "system", "content": prompt }, {"role": "user", "content": doc} ] , response_format=EconForecast ) return completion.choices [ 0 ] .message.parsed
from dotenv import load_dotenvimport os
# Load environment variables from .env fileload_dotenv ( override=True ) from openai import OpenAIclient = OpenAI ( )
然后,用户调用 extract_from_doc 函数,浅易地界说" 2025E 经济预测"是他们思要从文档中索要的数据。
咱们执行索要两次,一次使用 MarkItDown,一次使用 Docling。
extract_prompt = "Economic Forecasts for 2025E"md_financials = extract_from_doc ( extract_prompt, forecast_result_md, client ) docling_financials = extract_from_doc ( extract_prompt, forecast_result_docling, client )
反应是一个包含 Forecast 对象列表的 EconForecast 对象,如 pydantic 模子中界说的那样。
md_financials
EconForecast ( forecasts= [ Forecast ( financial_variable='Real global GDP ( % y/y annualized ) ', financial_forecast=3.2 ) , Forecast ( financial_variable='Real U.S. GDP ( % q/q annualized ) ', financial_forecast=2.4 ) , Forecast ( financial_variable='CPI inflation ( % y/y ) ', financial_forecast=2.5 ) , Forecast ( financial_variable='Core CPI inflation ( % y/y ) ', financial_forecast=3.0 ) , Forecast ( financial_variable='Unemployment rate ( % ) ', financial_forecast=4.3 ) , Forecast ( financial_variable='Fed funds rate, end period ( % ) ', financial_forecast=3.88 ) ] )
然后咱们不错将反应调遣为 pandas DataFrame 方法,以便于比拟。
df_md_forecasts = pd.DataFrame ( [ ( f.financial_variable, f.financial_forecast ) for f in md_financials.forecasts ] , columns= [ 'Variable', 'Forecast' ] ) df_docling_forecasts = pd.DataFrame ( [ ( f.financial_variable, f.financial_forecast ) for f in docling_financials.forecasts ] , columns= [ 'Variable', 'Forecast' ] )
df_md_forecasts
df_docling_forecasts
MarkItDown 和 Docling 的效果都备推敲,与文档中的真确值准确匹配。
这标明,尽管从东谈主类阅读的角度来看,MarkItDown 的输出看起来不太易读,但在此特定情况下,两种措施都使 LLM 以推敲的准确性收效索要经济预测数据。
现时,让咱们关注钞票类别权重。
咱们将从文档中索要钞票类别权重,并比拟 MarkItDown 和 Docling 的效果。
现时信息呈现的结构极度不同。CIO 的不雅点信息以" underweight "启动,进程" neutral ",达到" overweight "。
本体信息在图表中以一些彩色点标出。让咱们望望咱们是否不错从文档中索要这些信息。
用户只需界说以下数据以索要:"搁置 2024 年 12 月 3 日的钞票类别权重(-2 至 2 的刻度)"。
这么,咱们预计" underweight "将映射为 -2," neutral "映射为 0," overweight "映射为 2,之间还有一些数值。
extract_prompt = "Asset Class Weightings ( as of 12/3/2024 ) in a scale from -2 to 2"asset_class_docling = extract_from_doc ( extract_prompt, forecast_result_docling, client ) asset_class_md = extract_from_doc ( extract_prompt, forecast_result_md, client )
df_md = pd.DataFrame ( [ ( f.financial_variable, f.financial_forecast ) for f in asset_class_md.forecasts ] , columns= [ 'Variable', 'Forecast' ] ) df_docling = pd.DataFrame ( [ ( f.financial_variable, f.financial_forecast ) for f in asset_class_docling.forecasts ] , columns= [ 'Variable', 'Forecast' ] )
现时咱们构建一个 DataFrame 来比拟 MarkItDown 和 Docling 的效果,并添加一个包含从文档中手动索要的真确值的" true_value "列。
# Create DataFrame with specified columnsdf_comparison = pd.DataFrame ( { 'variable': df_docling [ 'Variable' ] .iloc [ :-1 ] , 'markitdown': df_md [ 'Forecast' ] , 'docling': df_docling [ 'Forecast' ] .iloc [ :-1 ] , # Drop last row 'true_value': [ 1.0, 0.0, 1.0, 1.0, 1.0, -1.0, 0.0, -1.0, 1.0, 1.0, -1.0, 0.0, -1.0, 0.0, -1.0 ] } )
display ( df_comparison )
然后咱们盘算出 Docling 和 MarkItDown 的准确率:
# Calculate accuracy for markitdown and doclingmarkitdown_accuracy = ( df_comparison [ 'markitdown' ] == df_comparison [ 'true_value' ] ) .mean ( ) docling_accuracy = ( df_comparison [ 'docling' ] == df_comparison [ 'true_value' ] ) .mean ( )
print ( f"Markitdown accuracy: {markitdown_accuracy:.2%}" ) print ( f"Docling accuracy: {docling_accuracy:.2%}" )
Markitdown accuracy: 53.33%Docling accuracy: 93.33%
Docling 的准确率达到了93.33%,仅缺失一个值。MarkItDown 的准确率为 53.33%,在狭窄的钞票类别权重进展较差。
在这种情况下,LLM 从 Docling 的结构化瓦解的输出如实比从 MarkItDown 的无结构化输出中索要了更精准的信息。
更庄重的分析将需要在开阔样本数据上运行屡次数据索要以算计失实率。
若是咱们思系统地从文档中索要统统表格呢?
咱们不错通过浅易地拜谒 DocumentConverter 对象的 tables 属性来使用 Docling 杀青这极少。
import timefrom pathlib import Pathimport pandas as pdfrom docling.document_converter import DocumentConverter
def convert_and_export_tables ( file_path: Path ) -> list [ pd.DataFrame ] : """ Convert document and export tables to DataFrames. Args: file_path: Path to input document Returns: List of pandas DataFrames containing the tables """ doc_converter = DocumentConverter ( ) start_time = time.time ( ) conv_res = doc_converter.convert ( file_path ) tables = [ ] # Export tables for table in conv_res.document.tables: table_df: pd.DataFrame = table.export_to_dataframe ( ) tables.append ( table_df )
end_time = time.time ( ) - start_time print ( f"Document converted in {end_time:.2f} seconds." ) return tables
# Convert and export tablestables = convert_and_export_tables ( Path ( FORECAST_FILE_PATH ) )
咱们不雅察到 Docling 从文档中索要了 7 个表格。按照文档中出现的章程,从上到下、从左到右导出表格。
len ( tables )
7
底下,咱们不错看到收效索要的第一个表格是对于股票预测的,第二个是对于固定收益预测的,以及临了一个包含首席投资官股票行业不雅点的表格。
display ( tables [ 0 ] )
display ( tables [ 1 ] )
display ( tables [ 6 ] )
回到 MarkItDown,它的一个费力秉性是不错集成一个多模态 LLM,从图像中索要信息并进行分析与描摹。
md_llm = MarkItDown ( llm_client=client, llm_model="gpt-4o-mini" )
result = md_llm.convert ( "../data/input/forecast.png" )
以下是咱们从输入文档的图像中获得的描摹。
display ( Markdown ( result.text_content ) )
总体而言,该描摹在某种进程上是准确的,但包含了一些不准确之处,包括:
对于板块权重,描摹中提到"在好意思国小盘成长股方面存在低配偶寸",但从钞票类别权重图表来看,好意思国小盘成长股本体上显露为超配偶寸(绿色圆圈)。
描摹中提到"在公用处事和金融等某些板块存在超配偶寸",但从首席投资官股票板块不雅点来看,这两个板块都显露为中立头寸,而非超配偶寸。
对于固定收益,描摹中提到" 10 年期(4.03%)"收益率,但图片显露的是 30 年期收益率为 4.03%,而本体上 10 年期收益率为 4.40%。
不错说,描摹中的这些不准确之处可能是底层大型言语模子无法解决图像的效果。需要进一步磋议来笃定是否如实如斯。
更多好用的调遣库
网友们还共享了其他好用的方法调遣库,比如MinerU和Pandoc等。
MinerU 保藏数卓绝2.4万,还加多了对 json 方法的赞成。
而 Pandoc 保藏数卓绝3.5万,赞成的文献类型更无为,以致还包括输出 epub、ipynb 等等。
下次需要将文献调遣成 LLM 容易解决的数据方法的技术,都不错试试哦!
在线版:https://www.getmarkdown.com/
MarkltDown 库地址:github.com/microsoft/markitdown
参考流通:
[ 1 ] https://www.tamingllms.com/notebooks/input.html#structured-extraction体育游戏app平台