[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-explosion--spacy-layout":3,"tool-explosion--spacy-layout":64},[4,17,27,35,43,56],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":16},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,3,"2026-04-05T11:01:52",[13,14,15],"开发框架","图像","Agent","ready",{"id":18,"name":19,"github_repo":20,"description_zh":21,"stars":22,"difficulty_score":23,"last_commit_at":24,"category_tags":25,"status":16},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",138956,2,"2026-04-05T11:33:21",[13,15,26],"语言模型",{"id":28,"name":29,"github_repo":30,"description_zh":31,"stars":32,"difficulty_score":23,"last_commit_at":33,"category_tags":34,"status":16},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",107662,"2026-04-03T11:11:01",[13,14,15],{"id":36,"name":37,"github_repo":38,"description_zh":39,"stars":40,"difficulty_score":23,"last_commit_at":41,"category_tags":42,"status":16},3704,"NextChat","ChatGPTNextWeb\u002FNextChat","NextChat 是一款轻量且极速的 AI 助手，旨在为用户提供流畅、跨平台的大模型交互体验。它完美解决了用户在多设备间切换时难以保持对话连续性，以及面对众多 AI 模型不知如何统一管理的痛点。无论是日常办公、学习辅助还是创意激发，NextChat 都能让用户随时随地通过网页、iOS、Android、Windows、MacOS 或 Linux 端无缝接入智能服务。\n\n这款工具非常适合普通用户、学生、职场人士以及需要私有化部署的企业团队使用。对于开发者而言，它也提供了便捷的自托管方案，支持一键部署到 Vercel 或 Zeabur 等平台。\n\nNextChat 的核心亮点在于其广泛的模型兼容性，原生支持 Claude、DeepSeek、GPT-4 及 Gemini Pro 等主流大模型，让用户在一个界面即可自由切换不同 AI 能力。此外，它还率先支持 MCP（Model Context Protocol）协议，增强了上下文处理能力。针对企业用户，NextChat 提供专业版解决方案，具备品牌定制、细粒度权限控制、内部知识库整合及安全审计等功能，满足公司对数据隐私和个性化管理的高标准要求。",87618,"2026-04-05T07:20:52",[13,26],{"id":44,"name":45,"github_repo":46,"description_zh":47,"stars":48,"difficulty_score":23,"last_commit_at":49,"category_tags":50,"status":16},2268,"ML-For-Beginners","microsoft\u002FML-For-Beginners","ML-For-Beginners 是由微软推出的一套系统化机器学习入门课程，旨在帮助零基础用户轻松掌握经典机器学习知识。这套课程将学习路径规划为 12 周，包含 26 节精炼课程和 52 道配套测验，内容涵盖从基础概念到实际应用的完整流程，有效解决了初学者面对庞大知识体系时无从下手、缺乏结构化指导的痛点。\n\n无论是希望转型的开发者、需要补充算法背景的研究人员，还是对人工智能充满好奇的普通爱好者，都能从中受益。课程不仅提供了清晰的理论讲解，还强调动手实践，让用户在循序渐进中建立扎实的技能基础。其独特的亮点在于强大的多语言支持，通过自动化机制提供了包括简体中文在内的 50 多种语言版本，极大地降低了全球不同背景用户的学习门槛。此外，项目采用开源协作模式，社区活跃且内容持续更新，确保学习者能获取前沿且准确的技术资讯。如果你正寻找一条清晰、友好且专业的机器学习入门之路，ML-For-Beginners 将是理想的起点。",84991,"2026-04-05T10:45:23",[14,51,52,53,15,54,26,13,55],"数据工具","视频","插件","其他","音频",{"id":57,"name":58,"github_repo":59,"description_zh":60,"stars":61,"difficulty_score":10,"last_commit_at":62,"category_tags":63,"status":16},3128,"ragflow","infiniflow\u002Fragflow","RAGFlow 是一款领先的开源检索增强生成（RAG）引擎，旨在为大语言模型构建更精准、可靠的上下文层。它巧妙地将前沿的 RAG 技术与智能体（Agent）能力相结合，不仅支持从各类文档中高效提取知识，还能让模型基于这些知识进行逻辑推理和任务执行。\n\n在大模型应用中，幻觉问题和知识滞后是常见痛点。RAGFlow 通过深度解析复杂文档结构（如表格、图表及混合排版），显著提升了信息检索的准确度，从而有效减少模型“胡编乱造”的现象，确保回答既有据可依又具备时效性。其内置的智能体机制更进一步，使系统不仅能回答问题，还能自主规划步骤解决复杂问题。\n\n这款工具特别适合开发者、企业技术团队以及 AI 研究人员使用。无论是希望快速搭建私有知识库问答系统，还是致力于探索大模型在垂直领域落地的创新者，都能从中受益。RAGFlow 提供了可视化的工作流编排界面和灵活的 API 接口，既降低了非算法背景用户的上手门槛，也满足了专业开发者对系统深度定制的需求。作为基于 Apache 2.0 协议开源的项目，它正成为连接通用大模型与行业专有知识之间的重要桥梁。",77062,"2026-04-04T04:44:48",[15,14,13,26,54],{"id":65,"github_repo":66,"name":67,"description_en":68,"description_zh":69,"ai_summary_zh":69,"readme_en":70,"readme_zh":71,"quickstart_zh":72,"use_case_zh":73,"hero_image_url":74,"owner_login":75,"owner_name":76,"owner_avatar_url":77,"owner_bio":78,"owner_company":79,"owner_location":79,"owner_email":80,"owner_twitter":79,"owner_website":81,"owner_url":82,"languages":83,"stars":88,"forks":89,"last_commit_at":90,"license":91,"difficulty_score":23,"env_os":92,"env_gpu":92,"env_ram":92,"env_deps":93,"category_tags":100,"github_topics":101,"view_count":23,"oss_zip_url":79,"oss_zip_packed_at":79,"status":16,"created_at":111,"updated_at":112,"faqs":113,"releases":139},4014,"explosion\u002Fspacy-layout","spacy-layout","📚 Process PDFs, Word documents and more with spaCy","spacy-layout 是一款专为处理 PDF、Word 等文档设计的开源插件，它能将非结构化的文档内容转化为机器可读的结构化数据。传统上，从复杂排版的文档中提取文本往往丢失了标题、段落和表格等关键布局信息，导致后续分析困难。spacy-layout 通过与 Docling 集成，完美解决了这一痛点：它不仅能提取纯文本，还能识别文档的逻辑结构（如章节、标题），并将表格直接转换为便于分析的 pandas DataFrame。\n\n该工具的核心亮点在于其输出的数据能直接生成 spaCy 熟悉的 `Doc` 对象。这意味着开发者可以无缝衔接 spaCy 强大的自然语言处理能力，如命名实体识别、文本分类或语言学分析，甚至直接用于构建 RAG（检索增强生成）系统中的文本分块环节。无论是需要批量处理大量文献的研究人员，还是致力于构建文档智能应用的 AI 工程师，spacy-layout 都能提供高效、精准的预处理方案，让文档数据真正变得\"AI 就绪”。只需几行代码，即可将杂乱的文档流转化为富含语义与布局信息的结构化资产。","\u003Ca href=\"https:\u002F\u002Fexplosion.ai\">\u003Cimg src=\"https:\u002F\u002Fexplosion.ai\u002Fassets\u002Fimg\u002Flogo.svg\" width=\"125\" height=\"125\" align=\"right\" \u002F>\u003C\u002Fa>\n\n# spaCy Layout: Process PDFs, Word documents and more with spaCy\n\nThis plugin integrates with [Docling](https:\u002F\u002Fds4sd.github.io\u002Fdocling\u002F) to bring structured processing of **PDFs**, **Word documents** and other input formats to your [spaCy](https:\u002F\u002Fspacy.io) pipeline. It outputs clean, **structured data** in a text-based format and creates spaCy's familiar [`Doc`](https:\u002F\u002Fspacy.io\u002Fapi\u002Fdoc) objects that let you access labelled text spans like sections or headings, and tables with their data converted to a `pandas.DataFrame`.\n\nThis workflow makes it easy to apply powerful **NLP techniques** to your documents, including linguistic analysis, named entity recognition, text classification and more. It's also great for implementing **chunking for RAG** pipelines.\n\n> 📖 **Blog post:** [\"From PDFs to AI-ready structured data: a deep dive\"\n](https:\u002F\u002Fexplosion.ai\u002Fblog\u002Fpdfs-nlp-structured-data) – A new modular workflow for converting PDFs and similar documents to structured data, featuring `spacy-layout` and Docling.\n\n[![Test](https:\u002F\u002Fgithub.com\u002Fexplosion\u002Fspacy-layout\u002Factions\u002Fworkflows\u002Ftest.yml\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Fexplosion\u002Fspacy-layout\u002Factions\u002Fworkflows\u002Ftest.yml)\n[![Current Release Version](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Frelease\u002Fexplosion\u002Fspacy-layout.svg?style=flat-square&logo=github&include_prereleases)](https:\u002F\u002Fgithub.com\u002Fexplosion\u002Fspacy-layout\u002Freleases)\n[![pypi Version](https:\u002F\u002Fimg.shields.io\u002Fpypi\u002Fv\u002Fspacy-layout.svg?style=flat-square&logo=pypi&logoColor=white)](https:\u002F\u002Fpypi.org\u002Fproject\u002Fspacy-layout\u002F)\n[![Built with spaCy](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fbuilt%20with-spaCy-09a3d5.svg?style=flat-square)](https:\u002F\u002Fspacy.io)\n\n## 📝 Usage\n\n> ⚠️ This package requires **Python 3.10** or above.\n\n```bash\npip install spacy-layout\n```\n\nAfter initializing the `spaCyLayout` preprocessor with an `nlp` object for tokenization, you can call it on a document path to convert it to structured data. The resulting `Doc` object includes layout spans that map into the original raw text and expose various attributes, including the content type and layout features.\n\n```python\nimport spacy\nfrom spacy_layout import spaCyLayout\n\nnlp = spacy.blank(\"en\")\nlayout = spaCyLayout(nlp)\n\n# Process a document and create a spaCy Doc object\ndoc = layout(\".\u002Fstarcraft.pdf\")\n\n# The text-based contents of the document\nprint(doc.text)\n# Document layout including pages and page sizes\nprint(doc._.layout)\n# Tables in the document and their extracted data\nprint(doc._.tables)\n# Markdown representation of the document\nprint(doc._.markdown)\n\n# Layout spans for different sections\nfor span in doc.spans[\"layout\"]:\n    # Document section and token and character offsets into the text\n    print(span.text, span.start, span.end, span.start_char, span.end_char)\n    # Section type, e.g. \"text\", \"title\", \"section_header\" etc.\n    print(span.label_)\n    # Layout features of the section, including bounding box\n    print(span._.layout)\n    # Closest heading to the span (accuracy depends on document structure)\n    print(span._.heading)\n```\n\nIf you need to process larger volumes of documents at scale, you can use the `spaCyLayout.pipe` method, which takes an iterable of paths or bytes instead and yields `Doc` objects:\n\n```python\npaths = [\"one.pdf\", \"two.pdf\", \"three.pdf\", ...]\nfor doc in layout.pipe(paths):\n    print(doc._.layout)\n```\n\nspaCy also allows you to call the `nlp` object on an already created `Doc`, so you can easily apply a pipeline of components for [linguistic analysis](https:\u002F\u002Fspacy.io\u002Fusage\u002Flinguistic-features) or [named entity recognition](https:\u002F\u002Fspacy.io\u002Fusage\u002Flinguistic-features#named-entities), use [rule-based matching](https:\u002F\u002Fspacy.io\u002Fusage\u002Frule-based-matching) or anything else you can do with spaCy.\n\n```python\n# Load the transformer-based English pipeline\n# Installation: python -m spacy download en_core_web_trf\nnlp = spacy.load(\"en_core_web_trf\")\nlayout = spaCyLayout(nlp)\n\ndoc = layout(\".\u002Fstarcraft.pdf\")\n# Apply the pipeline to access POS tags, dependencies, entities etc.\ndoc = nlp(doc)\n```\n\n### Tables and tabular data\n\nTables are included in the layout spans with the label `\"table\"` and under the shortcut `Doc._.tables`. They expose a `layout` extension attribute, as well as an attribute `data`, which includes the tabular data converted to a `pandas.DataFrame`.\n\n```python\nfor table in doc._.tables:\n    # Token position and bounding box\n    print(table.start, table.end, table._.layout)\n    # pandas.DataFrame of contents\n    print(table._.data)\n```\n\nBy default, the span text is a placeholder `TABLE`, but you can customize how a table is rendered by providing a `display_table` callback to `spaCyLayout`, which receives the `pandas.DataFrame` of the data. This allows you to include the table figures in the document text and use them later on, e.g. during information extraction with a trained named entity recognizer or text classifier.\n\n```python\ndef display_table(df: pd.DataFrame) -> str:\n    return f\"Table with columns: {', '.join(df.columns.tolist())}\"\n\nlayout = spaCyLayout(nlp, display_table=display_table)\n```\n\n### Serialization\n\nAfter you've processed the documents, you can [serialize](https:\u002F\u002Fspacy.io\u002Fusage\u002Fsaving-loading#docs) the structured `Doc` objects in spaCy's efficient binary format, so you don't have to re-run the resource-intensive conversion.\n\n```python\nfrom spacy.tokens import DocBin\n\ndocs = layout.pipe([\"one.pdf\", \"two.pdf\", \"three.pdf\"])\ndoc_bin = DocBin(docs=docs, store_user_data=True)\ndoc_bin.to_disk(\".\u002Ffile.spacy\")\n```\n\n> ⚠️ **Note on deserializing with extension attributes:** The custom extension attributes like `Doc._.layout` are currently registered when `spaCyLayout` is initialized. So if you're loading back `Doc` objects with layout information from a binary file, you'll need to initialize it so the custom attributes can be repopulated. We're planning on making this more elegant in an upcoming version.\n>\n> ```diff\n> + layout = spacyLayout(nlp)\n> doc_bin = DocBin(store_user_data=True).from_disk(\".\u002Ffile.spacy\")\n> docs = list(doc_bin.get_docs(nlp.vocab))\n> ```\n\n\n## 🎛️ API\n\n### Data and extension attributes\n\n```python\nlayout = spaCyLayout(nlp)\ndoc = layout(\".\u002Fstarcraft.pdf\")\nprint(doc._.layout)\nfor span in doc.spans[\"layout\"]:\n    print(span.label_, span._.layout)\n```\n\n| Attribute | Type | Description |\n| --- | --- | --- |\n| `Doc._.layout` | `DocLayout` | Layout features of the document. |\n| `Doc._.pages` | `list[tuple[PageLayout, list[Span]]]` | Pages in the document and the spans they contain. |\n| `Doc._.tables` | `list[Span]` | All tables in the document. |\n| `Doc._.markdown` | `str` | Markdown representation of the document. |\n| `Doc.spans[\"layout\"]` | `spacy.tokens.SpanGroup` | The layout spans in the document. |\n| `Span.label_` | `str` | The type of the extracted layout span, e.g. `\"text\"` or `\"section_header\"`. [See here](https:\u002F\u002Fgithub.com\u002FDS4SD\u002Fdocling-core\u002Fblob\u002F14cad33ae7f8dc011a79dd364361d2647c635466\u002Fdocling_core\u002Ftypes\u002Fdoc\u002Flabels.py) for options. |\n| `Span.label` | `int` | The integer ID of the span label. |\n| `Span.id` | `int` | Running index of layout span. |\n| `Span._.layout` | `SpanLayout \\| None` | Layout features of a layout span. |\n| `Span._.heading` | `Span \\| None` | Closest heading to a span, if available. |\n| `Span._.data` | `pandas.DataFrame \\| None` | The extracted data for table spans.\n\n### \u003Ckbd>dataclass\u003C\u002Fkbd> PageLayout\n\n| Attribute | Type | Description |\n| --- | --- | --- |\n| `page_no` | `int` | The page number (1-indexed). |\n| `width` | `float` | Page width in pixels. |\n| `height` | `float` | Page height in pixels. |\n\n### \u003Ckbd>dataclass\u003C\u002Fkbd> DocLayout\n\n| Attribute | Type | Description |\n| --- | --- | --- |\n| `pages` | `list[PageLayout]` | The pages in the document. |\n\n### \u003Ckbd>dataclass\u003C\u002Fkbd> SpanLayout\n\n| Attribute | Type | Description |\n| --- | --- | --- |\n| `x` | `float` | Horizontal offset of the bounding box in pixels. |\n| `y` | `float` | Vertical offset of the bounding box in pixels. |\n| `width` | `float` | Width of the bounding box in pixels. |\n| `height` | `float` | Height of the bounding box in pixels. |\n| `page_no` | `int` | Number of page the span is on. |\n\n### \u003Ckbd>class\u003C\u002Fkbd> `spaCyLayout`\n\n#### \u003Ckbd>method\u003C\u002Fkbd> `spaCyLayout.__init__`\n\nInitialize the document processor.\n\n```python\nnlp = spacy.blank(\"en\")\nlayout = spaCyLayout(nlp)\n```\n\n| Argument | Type | Description |\n| --- | --- | --- |\n| `nlp` | `spacy.language.Language` | The initialized `nlp` object to use for tokenization. |\n| `separator` | `str` | Token used to separate sections in the created `Doc` object. The separator won't be part of the layout span. If `None`, no separator will be added. Defaults to `\"\\n\\n\"`. |\n| `attrs` | `dict[str, str]` | Override the custom spaCy attributes. Can include `\"doc_layout\"`, `\"doc_pages\"`, `\"doc_tables\"`, `\"doc_markdown\"`, `\"span_layout\"`, `\"span_data\"`, `\"span_heading\"` and `\"span_group\"`. |\n| `headings` | `list[str]` | Labels of headings to consider for `Span._.heading` detection. Defaults to `[\"section_header\", \"page_header\", \"title\"]`. |\n| `display_table` | `Callable[[pandas.DataFrame], str] \\| str` | Function to generate the text-based representation of the table in the `Doc.text` or placeholder text. Defaults to `\"TABLE\"`. |\n| `docling_options` | `dict[InputFormat, FormatOption]` | [Format options](https:\u002F\u002Fds4sd.github.io\u002Fdocling\u002Fusage\u002F#advanced-options) passed to Docling's `DocumentConverter`. |\n| **RETURNS** | `spaCyLayout` | The initialized object. |\n\n#### \u003Ckbd>method\u003C\u002Fkbd> `spaCyLayout.__call__`\n\nProcess a document and create a spaCy [`Doc`](https:\u002F\u002Fspacy.io\u002Fapi\u002Fdoc) object containing the text content and layout spans, available via `Doc.spans[\"layout\"]` by default.\n\n```python\nlayout = spaCyLayout(nlp)\ndoc = layout(\".\u002Fstarcraft.pdf\")\n```\n\n| Argument | Type | Description |\n| --- | --- | --- |\n| `source` | `str \\| Path \\| bytes \\| DoclingDocument` | Path of document to process, bytes or already created `DoclingDocument`. |\n| **RETURNS** | `Doc` | The processed spaCy `Doc` object. |\n\n#### \u003Ckbd>method\u003C\u002Fkbd> `spaCyLayout.pipe`\n\nProcess multiple documents and create spaCy [`Doc`](https:\u002F\u002Fspacy.io\u002Fapi\u002Fdoc) objects. You should use this method if you're processing larger volumes of documents at scale. The behavior of `as_tuples` works like it does in spaCy's [`Language.pipe`](https:\u002F\u002Fspacy.io\u002Fapi\u002Flanguage#pipe).\n\n```python\nlayout = spaCyLayout(nlp)\npaths = [\"one.pdf\", \"two.pdf\", \"three.pdf\", ...]\ndocs = layout.pipe(paths)\n```\n\n```python\nsources = [(\"one.pdf\", {\"id\": 1}), (\"two.pdf\", {\"id\": 2})]\nfor doc, context in layout.pipe(sources, as_tuples=True):\n    ...\n```\n\n| Argument | Type | Description |\n| --- | --- | --- |\n| `sources` | `Iterable[str \\| Path \\| bytes] \\| Iterable[tuple[str \\| Path \\| bytes, Any]]` | Paths of documents to process or bytes, or `(source, context)` tuples if `as_tuples` is set to `True`. |\n| `as_tuples` | `bool` | If set to `True`, inputs should be an iterable of `(source, context)` tuples. Output will then be a sequence of `(doc, context)` tuples. Defaults to `False`. |\n| **YIELDS** | `Doc \\| tuple[Doc, Any]` | The processed spaCy `Doc` objects or `(doc, context)` tuples if `as_tuples` is set to `True`. |\n\n## 💡 Examples and code snippets\n\nThis section includes further examples of what you can do with `spacy-layout`. If you have an example that could be a good fit, feel free to submit a [pull request](https:\u002F\u002Fgithub.com\u002Fexplosion\u002Fspacy-layout\u002Fpulls)!\n\n### Visualize a page and bounding boxes with matplotlib\n\n```python\nimport pypdfium2 as pdfium\nimport matplotlib.pyplot as plt\nfrom matplotlib.patches import Rectangle\nimport spacy\nfrom spacy_layout import spaCyLayout\n\nDOCUMENT_PATH = \".\u002Fdocument.pdf\"\n\n# Load and convert the PDF page to an image\npdf = pdfium.PdfDocument(DOCUMENT_PATH)\npage_image = pdf[2].render(scale=1)  # get page 3 (index 2)\nnumpy_array = page_image.to_numpy()\n# Process document with spaCy\nnlp = spacy.blank(\"en\")\nlayout = spaCyLayout(nlp)\ndoc = layout(DOCUMENT_PATH)\n\n# Get page 3 layout and sections\npage = doc._.pages[2]\npage_layout = doc._.layout.pages[2]\n# Create figure and axis with page dimensions\nfig, ax = plt.subplots(figsize=(12, 16))\n# Display the PDF image\nax.imshow(numpy_array)\n# Add rectangles for each section's bounding box\nfor section in page[1]:\n    # Create rectangle patch\n    rect = Rectangle(\n        (section._.layout.x, section._.layout.y),\n        section._.layout.width,\n        section._.layout.height,\n        fill=False,\n        color=\"blue\",\n        linewidth=1,\n        alpha=0.5\n    )\n    ax.add_patch(rect)\n    # Add text label at top of box\n    ax.text(\n        section._.layout.x,\n        section._.layout.y,\n        section.label_,\n        fontsize=8,\n        color=\"red\",\n        verticalalignment=\"bottom\"\n    )\n\nax.axis(\"off\")  # hide axes\nplt.show()\n```\n","\u003Ca href=\"https:\u002F\u002Fexplosion.ai\">\u003Cimg src=\"https:\u002F\u002Fexplosion.ai\u002Fassets\u002Fimg\u002Flogo.svg\" width=\"125\" height=\"125\" align=\"right\" \u002F>\u003C\u002Fa>\n\n# spaCy Layout：使用 spaCy 处理 PDF、Word 文档等\n\n此插件与 [Docling](https:\u002F\u002Fds4sd.github.io\u002Fdocling\u002F) 集成，可将 **PDF**、**Word 文档** 等多种输入格式的结构化处理引入您的 [spaCy](https:\u002F\u002Fspacy.io) 流程中。它以文本格式输出干净的 **结构化数据**，并创建 spaCy 熟悉的 [`Doc`](https:\u002F\u002Fspacy.io\u002Fapi\u002Fdoc) 对象，使您能够访问诸如章节或标题等带标签的文本片段，以及已将数据转换为 `pandas.DataFrame` 的表格。\n\n此工作流让您轻松地将强大的 **NLP 技术** 应用于文档，包括语言学分析、命名实体识别、文本分类等。它也非常适合用于实现 **RAG 流水线中的分块操作**。\n\n> 📖 **博客文章**：“从 PDF 到 AI 就绪的结构化数据：深度解析”  \n[](https:\u002F\u002Fexplosion.ai\u002Fblog\u002Fpdfs-nlp-structured-data) —— 一种新的模块化工作流，用于将 PDF 及类似文档转换为结构化数据，其中包含 `spacy-layout` 和 Docling。\n\n[![测试](https:\u002F\u002Fgithub.com\u002Fexplosion\u002Fspacy-layout\u002Factions\u002Fworkflows\u002Ftest.yml\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Fexplosion\u002Fspacy-layout\u002Factions\u002Fworkflows\u002Ftest.yml)\n[![当前发布版本](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Frelease\u002Fexplosion\u002Fspacy-layout.svg?style=flat-square&logo=github&include_prereleases)](https:\u002F\u002Fgithub.com\u002Fexplosion\u002Fspacy-layout\u002Freleases)\n[![PyPI 版本](https:\u002F\u002Fimg.shields.io\u002Fpypi\u002Fv\u002Fspacy-layout.svg?style=flat-square&logo=pypi&logoColor=white)](https:\u002F\u002Fpypi.org\u002Fproject\u002Fspacy-layout\u002F)\n[![基于 spaCy 构建](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fbuilt%20with-spaCy-09a3d5.svg?style=flat-square)](https:\u002F\u002Fspacy.io)\n\n## 📝 使用方法\n\n> ⚠️ 本包需要 **Python 3.10** 或更高版本。\n\n```bash\npip install spacy-layout\n```\n\n在使用 `nlp` 对象初始化 `spaCyLayout` 预处理器进行分词后，您可以调用它来处理文档路径，将其转换为结构化数据。生成的 `Doc` 对象包含布局跨度，这些跨度映射到原始文本，并暴露各种属性，包括内容类型和布局特征。\n\n```python\nimport spacy\nfrom spacy_layout import spaCyLayout\n\nnlp = spacy.blank(\"en\")\nlayout = spaCyLayout(nlp)\n\n# 处理文档并创建 spaCy Doc 对象\ndoc = layout(\".\u002Fstarcraft.pdf\")\n\n# 文档的文本内容\nprint(doc.text)\n# 文档布局，包括页数和页面尺寸\nprint(doc._.layout)\n# 文档中的表格及其提取的数据\nprint(doc._.tables)\n# 文档的 Markdown 表示\nprint(doc._.markdown)\n\n# 不同部分的布局跨度\nfor span in doc.spans[\"layout\"]:\n    # 文档部分及文本中的标记和字符偏移量\n    print(span.text, span.start, span.end, span.start_char, span.end_char)\n    # 部分类型，例如 \"text\"、\"title\"、\"section_header\" 等\n    print(span.label_)\n    # 部分的布局特征，包括边界框\n    print(span._.layout)\n    # 距离该跨度最近的标题（准确性取决于文档结构）\n    print(span._.heading)\n```\n\n如果您需要大规模处理大量文档，可以使用 `spaCyLayout.pipe` 方法，该方法接受路径或字节的可迭代对象，并生成 `Doc` 对象：\n\n```python\npaths = [\"one.pdf\", \"two.pdf\", \"three.pdf\", ...]\nfor doc in layout.pipe(paths):\n    print(doc._.layout)\n```\n\nspaCy 还允许您对已创建的 `Doc` 调用 `nlp` 对象，因此您可以轻松应用组件流水线来进行 [语言学分析](https:\u002F\u002Fspacy.io\u002Fusage\u002Flinguistic-features) 或 [命名实体识别](https:\u002F\u002Fspacy.io\u002Fusage\u002Flinguistic-features#named-entities)，使用 [基于规则的匹配](https:\u002F\u002Fspacy.io\u002Fusage\u002Frule-based-matching) 或 spaCy 支持的任何其他功能。\n\n```python\n# 加载基于 Transformer 的英语流水线\n# 安装：python -m spacy download en_core_web_trf\nnlp = spacy.load(\"en_core_web_trf\")\nlayout = spaCyLayout(nlp)\n\ndoc = layout(\".\u002Fstarcraft.pdf\")\n# 应用流水线以获取词性标注、依存关系、实体等\ndoc = nlp(doc)\n```\n\n### 表格和表格数据\n\n表格在布局跨度中以 `\"table\"` 标签出现，并可通过快捷方式 `Doc._.tables` 访问。它们会暴露一个 `layout` 扩展属性，以及一个包含表格数据并已转换为 `pandas.DataFrame` 的 `data` 属性。\n\n```python\nfor table in doc._.tables:\n    # 标记位置和边界框\n    print(table.start, table.end, table._.layout)\n    # 内容的 pandas.DataFrame\n    print(table._.data)\n```\n\n默认情况下，跨度文本是一个占位符 `TABLE`，但您可以自定义表格的呈现方式，只需向 `spaCyLayout` 提供一个 `display_table` 回调函数，该函数接收数据的 `pandas.DataFrame`。这使您能够在文档文本中包含表格信息，并在后续过程中使用这些信息，例如在使用训练好的命名实体识别器或文本分类器进行信息提取时。\n\n```python\ndef display_table(df: pd.DataFrame) -> str:\n    return f\"表格包含以下列：{', '.join(df.columns.tolist())}\"\n\nlayout = spaCyLayout(nlp, display_table=display_table)\n```\n\n### 序列化\n\n处理完文档后，您可以将结构化的 `Doc` 对象以 spaCy 高效的二进制格式进行 [序列化](https:\u002F\u002Fspacy.io\u002Fusage\u002Fsaving-loading#docs)，这样就不必再次执行资源密集型的转换过程。\n\n```python\nfrom spacy.tokens import DocBin\n\ndocs = layout.pipe([\"one.pdf\", \"two.pdf\", \"three.pdf\"])\ndoc_bin = DocBin(docs=docs, store_user_data=True)\ndoc_bin.to_disk(\".\u002Ffile.spacy\")\n```\n\n> ⚠️ **关于带有扩展属性的反序列化说明：** 自定义扩展属性，如 `Doc._.layout`，目前是在初始化 `spaCyLayout` 时注册的。因此，如果您从二进制文件中加载包含布局信息的 `Doc` 对象，就需要重新初始化 `spaCyLayout` 以便重新填充这些自定义属性。我们计划在未来的版本中对此进行优化。\n>\n> ```diff\n> + layout = spacyLayout(nlp)\n> doc_bin = DocBin(store_user_data=True).from_disk(\".\u002Ffile.spacy\")\n> docs = list(doc_bin.get_docs(nlp.vocab))\n> ```\n\n\n## 🎛️ API\n\n### 数据和扩展属性\n\n```python\nlayout = spaCyLayout(nlp)\ndoc = layout(\".\u002Fstarcraft.pdf\")\nprint(doc._.layout)\nfor span in doc.spans[\"layout\"]:\n    print(span.label_, span._.layout)\n```\n\n| 属性 | 类型 | 描述 |\n| --- | --- | --- |\n| `Doc._.layout` | `DocLayout` | 文档的布局特征。 |\n| `Doc._.pages` | `list[tuple[PageLayout, list[Span]]]` | 文档中的页面及其包含的跨度。 |\n| `Doc._.tables` | `list[Span]` | 文档中的所有表格。 |\n| `Doc._.markdown` | `str` | 文档的 Markdown 表示形式。 |\n| `Doc.spans[\"layout\"]` | `spacy.tokens.SpanGroup` | 文档中的布局跨度。 |\n| `Span.label_` | `str` | 提取的布局跨度的类型，例如 `\"text\"` 或 `\"section_header\"`。选项请参见 [这里](https:\u002F\u002Fgithub.com\u002FDS4SD\u002Fdocling-core\u002Fblob\u002F14cad33ae7f8dc011a79dd364361d2647c635466\u002Fdocling_core\u002Ftypes\u002Fdoc\u002Flabels.py)。 |\n| `Span.label` | `int` | 跨度标签的整数 ID。 |\n| `Span.id` | `int` | 布局跨度的连续索引。 |\n| `Span._.layout` | `SpanLayout \\| None` | 布局跨度的布局特征。 |\n| `Span._.heading` | `Span \\| None` | 如果存在，距离跨度最近的标题。 |\n| `Span._.data` | `pandas.DataFrame \\| None` | 表格跨度提取的数据。\n\n### \u003Ckbd>dataclass\u003C\u002Fkbd> PageLayout\n\n| 属性 | 类型 | 描述 |\n| --- | --- | --- |\n| `page_no` | `int` | 页码（从 1 开始）。 |\n| `width` | `float` | 页面宽度，单位为像素。 |\n| `height` | `float` | 页面高度，单位为像素。 |\n\n### \u003Ckbd>dataclass\u003C\u002Fkbd> DocLayout\n\n| 属性 | 类型 | 描述 |\n| --- | --- | --- |\n| `pages` | `list[PageLayout]` | 文档中的页面。 |\n\n### \u003Ckbd>dataclass\u003C\u002Fkbd> SpanLayout\n\n| 属性 | 类型 | 描述 |\n| --- | --- | --- |\n| `x` | `float` | 包围框的水平偏移量，单位为像素。 |\n| `y` | `float` | 包围框的垂直偏移量，单位为像素。 |\n| `width` | `float` | 包围框的宽度，单位为像素。 |\n| `height` | `float` | 包围框的高度，单位为像素。 |\n| `page_no` | `int` | 跨度所在的页码。 |\n\n### \u003Ckbd>class\u003C\u002Fkbd> `spaCyLayout`\n\n#### \u003Ckbd>method\u003C\u002Fkbd> `spaCyLayout.__init__`\n\n初始化文档处理器。\n\n```python\nnlp = spacy.blank(\"en\")\nlayout = spaCyLayout(nlp)\n```\n\n| 参数 | 类型 | 描述 |\n| --- | --- | --- |\n| `nlp` | `spacy.language.Language` | 用于分词的已初始化 `nlp` 对象。 |\n| `separator` | `str` | 用于在创建的 `Doc` 对象中分隔各部分的标记。该分隔符不会包含在布局跨度中。如果为 `None`，则不添加分隔符。默认值为 `\"\\n\\n\"`。 |\n| `attrs` | `dict[str, str]` | 覆盖自定义 spaCy 属性。可包括 `\"doc_layout\"`、`\"doc_pages\"`、`\"doc_tables\"`、`\"doc_markdown\"`、`\"span_layout\"`、`\"span_data\"`、`\"span_heading\"` 和 `\"span_group\"`。 |\n| `headings` | `list[str]` | 用于检测 `Span._.heading` 的标题标签。默认值为 `[\"section_header\", \"page_header\", \"title\"]`。 |\n| `display_table` | `Callable[[pandas.DataFrame], str] \\| str` | 用于生成表格在 `Doc.text` 中的文本表示或占位符文本的函数。默认值为 `\"TABLE\"`。 |\n| `docling_options` | `dict[InputFormat, FormatOption]` | 传递给 Docling 的 `DocumentConverter` 的 [格式选项](https:\u002F\u002Fds4sd.github.io\u002Fdocling\u002Fusage\u002F#advanced-options)。 |\n| **返回值** | `spaCyLayout` | 初始化后的对象。 |\n\n#### \u003Ckbd>method\u003C\u002Fkbd> `spaCyLayout.__call__`\n\n处理文档并创建一个包含文本内容和布局跨度的 spaCy [`Doc`](https:\u002F\u002Fspacy.io\u002Fapi\u002Fdoc) 对象，默认可通过 `Doc.spans[\"layout\"]` 访问。\n\n```python\nlayout = spaCyLayout(nlp)\ndoc = layout(\".\u002Fstarcraft.pdf\")\n```\n\n| 参数 | 类型 | 描述 |\n| --- | --- | --- |\n| `source` | `str \\| Path \\| bytes \\| DoclingDocument` | 要处理的文档路径、字节数据或已创建的 `DoclingDocument`。 |\n| **返回值** | `Doc` | 处理后的 spaCy `Doc` 对象。 |\n\n#### \u003Ckbd>method\u003C\u002Fkbd> `spaCyLayout.pipe`\n\n处理多个文档并创建 spaCy [`Doc`](https:\u002F\u002Fspacy.io\u002Fapi\u002Fdoc) 对象。如果您需要大规模处理大量文档，建议使用此方法。`as_tuples` 的行为与 spaCy 的 [`Language.pipe`](https:\u002F\u002Fspacy.io\u002Fapi\u002Flanguage#pipe) 相同。\n\n```python\nlayout = spaCyLayout(nlp)\npaths = [\"one.pdf\", \"two.pdf\", \"three.pdf\", ...]\ndocs = layout.pipe(paths)\n```\n\n```python\nsources = [(\"one.pdf\", {\"id\": 1}), (\"two.pdf\", {\"id\": 2})]\nfor doc, context in layout.pipe(sources, as_tuples=True):\n    ...\n```\n\n| 参数 | 类型 | 描述 |\n| --- | --- | --- |\n| `sources` | `Iterable[str \\| Path \\| bytes] \\| Iterable[tuple[str \\| Path \\| bytes, Any]]` | 要处理的文档路径或字节数据，或者当 `as_tuples` 设置为 `True` 时的 `(source, context)` 元组。 |\n| `as_tuples` | `bool` | 如果设置为 `True`，输入应为 `(source, context)` 元组的可迭代对象。输出将是 `(doc, context)` 元组序列。默认值为 `False`。 |\n| **产出** | `Doc \\| tuple[Doc, Any]` | 处理后的 spaCy `Doc` 对象，或当 `as_tuples` 设置为 `True` 时的 `(doc, context)` 元组。 |\n\n## 💡 示例和代码片段\n\n本节包含更多关于如何使用 `spacy-layout` 的示例。如果您有合适的示例，欢迎提交 [pull request](https:\u002F\u002Fgithub.com\u002Fexplosion\u002Fspacy-layout\u002Fpulls)！\n\n### 使用 matplotlib 可视化页面及边界框\n\n```python\nimport pypdfium2 as pdfium\nimport matplotlib.pyplot as plt\nfrom matplotlib.patches import Rectangle\nimport spacy\nfrom spacy_layout import spaCyLayout\n\nDOCUMENT_PATH = \".\u002Fdocument.pdf\"\n\n# 加载 PDF 并将其转换为图像\npdf = pdfium.PdfDocument(DOCUMENT_PATH)\npage_image = pdf[2].render(scale=1)  # 获取第 3 页（索引为 2）\nnumpy_array = page_image.to_numpy()\n# 使用 spaCy 处理文档\nnlp = spacy.blank(\"en\")\nlayout = spaCyLayout(nlp)\ndoc = layout(DOCUMENT_PATH)\n\n# 获取第 3 页的布局和各部分\npage = doc._.pages[2]\npage_layout = doc._.layout.pages[2]\n# 创建图形和坐标轴，并设置页面尺寸\nfig, ax = plt.subplots(figsize=(12, 16))\n# 显示 PDF 图像\nax.imshow(numpy_array)\n# 为每个部分的边界框添加矩形\nfor section in page[1]:\n    # 创建矩形补丁\n    rect = Rectangle(\n        (section._.layout.x, section._.layout.y),\n        section._.layout.width,\n        section._.layout.height,\n        fill=False,\n        color=\"blue\",\n        linewidth=1,\n        alpha=0.5\n    )\n    ax.add_patch(rect)\n    # 在框顶部添加文本标签\n    ax.text(\n        section._.layout.x,\n        section._.layout.y,\n        section.label_,\n        fontsize=8,\n        color=\"red\",\n        verticalalignment=\"bottom\"\n    )\n\nax.axis(\"off\")  # 隐藏坐标轴\nplt.show()\n```","# spaCy Layout 快速上手指南\n\n`spaCy Layout` 是一个强大的 spaCy 插件，集成了 [Docling](https:\u002F\u002Fds4sd.github.io\u002Fdocling\u002F)，能够将 **PDF**、**Word 文档**等非结构化文件转换为带有布局信息的结构化数据。它生成标准的 spaCy `Doc` 对象，支持提取章节、标题、表格（自动转为 pandas DataFrame）等元素，非常适合用于 RAG 管道构建、文档信息抽取及语言学分析。\n\n## 环境准备\n\n在开始之前，请确保满足以下系统要求：\n\n*   **Python 版本**：必须为 **Python 3.10** 或更高版本。\n*   **前置依赖**：需已安装 `spacy`。\n*   **推荐镜像**：国内开发者建议使用清华源或阿里源加速安装。\n\n## 安装步骤\n\n使用 pip 进行安装。如需加速，可指定国内镜像源：\n\n```bash\npip install spacy-layout -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n```\n\n> **注意**：该包会自动处理与 Docling 的集成，无需单独安装 Docling 核心库。\n\n## 基本使用\n\n以下是处理单个 PDF 文档并提取结构化信息的最简示例。\n\n### 1. 初始化与处理文档\n\n首先创建一个空白的 spaCy `nlp` 对象，初始化 `spaCyLayout`，然后直接调用它处理文件路径。\n\n```python\nimport spacy\nfrom spacy_layout import spaCyLayout\n\n# 初始化空白英语模型（仅用于分词基础架构）\nnlp = spacy.blank(\"en\")\n\n# 初始化布局处理器\nlayout = spaCyLayout(nlp)\n\n# 处理文档（支持 .pdf, .docx 等），返回 spaCy Doc 对象\ndoc = layout(\".\u002Fstarcraft.pdf\")\n\n# 查看纯文本内容\nprint(doc.text)\n\n# 查看文档布局信息（页数、尺寸等）\nprint(doc._.layout)\n\n# 查看提取的表格数据 (pandas.DataFrame)\nprint(doc._.tables)\n\n# 获取文档的 Markdown 表示\nprint(doc._.markdown)\n```\n\n### 2. 遍历布局片段 (Spans)\n\n`doc.spans[\"layout\"]` 包含了所有识别出的布局元素（如标题、段落、表格占位符）。你可以访问其类型标签、位置坐标及关联的标题。\n\n```python\nfor span in doc.spans[\"layout\"]:\n    # 输出：文本内容, 起始\u002F结束 token 索引, 起始\u002F结束字符索引\n    print(span.text, span.start, span.end, span.start_char, span.end_char)\n    \n    # 输出：片段类型 (例如: \"text\", \"title\", \"section_header\", \"table\")\n    print(span.label_)\n    \n    # 输出：布局特征（包含边界框坐标 x, y, width, height 及页码）\n    print(span._.layout)\n    \n    # 输出：距离该片段最近的标题（若存在）\n    print(span._.heading)\n```\n\n### 3. 结合 NLP 流水线\n\n生成的 `Doc` 对象完全兼容 spaCy 的标准流水线。你可以加载预训练模型（如实体识别、依存句法分析）进一步处理文档内容。\n\n```python\n# 加载预训练模型 (需先运行: python -m spacy download en_core_web_trf)\nnlp = spacy.load(\"en_core_web_trf\")\n\n# 重新初始化 layout 处理器（使用带能力的 nlp 对象）\nlayout = spaCyLayout(nlp)\n\n# 处理文档\ndoc = layout(\".\u002Fstarcraft.pdf\")\n\n# 应用 NLP 流水线：添加词性标注、实体识别等信息\ndoc = nlp(doc)\n\n# 现在可以正常使用 spaCy 功能，例如提取实体\nfor ent in doc.ents:\n    print(ent.text, ent.label_)\n```\n\n### 4. 批量处理\n\n处理大量文档时，推荐使用 `.pipe()` 方法以提高效率：\n\n```python\npaths = [\"doc1.pdf\", \"doc2.pdf\", \"doc3.pdf\"]\n\nfor doc in layout.pipe(paths):\n    # 处理每个文档的布局信息\n    print(f\"Processed {len(doc._.pages)} pages\")\n```","某金融合规团队需要从数千份混合格式的招股说明书（PDF 和 Word）中自动提取财务数据表格及风险章节，以构建检索增强生成（RAG）系统。\n\n### 没有 spacy-layout 时\n- **布局信息丢失**：传统文本提取工具将多栏排版强行拼接成单行，导致句子语义断裂，后续 NLP 模型无法正确理解上下文。\n- **表格解析困难**：PDF 中的财务报表被还原为无结构的纯文本，开发人员需编写大量复杂的正则表达式来尝试重建行列关系，维护成本极高且容易出错。\n- **章节定位模糊**：难以区分正文、标题和页脚，导致在切分文档片段（Chunking）时，经常将无关的页码或免责声明混入核心内容，降低 RAG 检索准确率。\n- **流程割裂**：文档预处理与 spaCy 的自然语言处理流水线不兼容，需要额外开发中间件进行数据格式转换，增加了工程复杂度。\n\n### 使用 spacy-layout 后\n- **结构化还原文档**：spacy-layout 结合 Docling 精准识别文档物理布局，自动保留段落顺序和多栏逻辑，直接输出语义连贯的文本供模型分析。\n- **表格自动转 DataFrame**：工具能直接识别文档内的表格并将其转换为 pandas DataFrame，财务人员可立即对提取的营收数据进行量化分析，无需手动清洗。\n- **智能语义分块**：通过识别 `section_header` 等布局标签，spacy-layout 能按真实章节边界进行切分，确保 RAG 系统检索到的每一段内容都完整且独立。\n- **无缝集成 NLP 流水线**：生成的对象原生支持 spaCy 的 `Doc` 结构，团队可直接在提取的文本上运行命名实体识别（NER），一键抽取公司名、金额等关键实体。\n\nspacy-layout 通过将非结构化文档转化为富含布局语义的标准数据对象，让金融文档的自动化分析从“人工清洗”跃升为“端到端智能处理”。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fexplosion_spacy-layout_bfdee8ea.png","explosion","Explosion","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fexplosion_6bc9ac84.png","Software company specializing in developer tools and tailored solutions for AI and Natural Language Processing",null,"contact@explosion.ai","https:\u002F\u002Fexplosion.ai","https:\u002F\u002Fgithub.com\u002Fexplosion",[84],{"name":85,"color":86,"percentage":87},"Python","#3572A5",100,875,61,"2026-04-01T19:15:16","MIT","未说明",{"notes":94,"python":95,"dependencies":96},"该工具是 spaCy 的插件，需配合 Docling 使用以处理 PDF 和 Word 文档。安装后需初始化 spaCyLayout 处理器。若需反序列化包含自定义扩展属性（如布局信息）的 Doc 对象，必须先初始化 spaCyLayout 以注册这些属性。示例代码中使用了 pypdfium2 和 matplotlib 进行可视化，但这属于可选依赖。","3.10+",[97,98,99],"spacy","docling","pandas",[26,13],[102,103,104,105,106,107,108,97,109,110],"docx","generative-ai","natural-language-processing","nlp","pdf","pdf-converter","rag","document-layout","document-layout-analysis","2026-03-27T02:49:30.150509","2026-04-06T06:52:02.986035",[114,119,124,129,134],{"id":115,"question_zh":116,"answer_zh":117,"source_url":118},18281,"加载 PDF 文件时出现 StopIteration 错误或格式不匹配错误怎么办？","这通常是由底层的 Docling 库引起的，而不是 spacy-layout 本身的问题。建议直接使用 Docling 的 DocumentConverter 测试相同的文件以确认问题：\n\n```python\nfrom docling.document_converter import DocumentConverter\nconverter = DocumentConverter()\nresult = converter.convert(\"your_file.pdf\")\n```\n\n如果直接调用 Docling 也报错（例如 'Input document ... does not match any allowed format'），请在 Docling 的项目追踪器中提交该问题。","https:\u002F\u002Fgithub.com\u002Fexplosion\u002Fspacy-layout\u002Fissues\u002F1",{"id":120,"question_zh":121,"answer_zh":122,"source_url":123},18282,"spacy-layout 输出的 span 文本为什么不连续或句子被截断？","这是预期行为，因为 layout spans 直接反映了 PDF 的布局结构，可能不会按完整的句子边界切割。如果需要获取连续的句子，应使用 spaCy 自带的句子分割功能。\n\n首先用包含 parser、senter 或 sentencizer 组件的 pipeline 处理 doc 对象：\n```python\nnlp = spacy.load(\"en_core_web_sm\")  # 或其他模型\ndoc = nlp(doc)\nfor sent in doc.sents:\n    print(sent.text)\n```\n\n注意：默认情况下，layout 部分之间由 `\\n\\n` 分隔，这可能影响句子边界检测。如果句子经常被切断，可以在初始化 spaCyLayout 时调整分隔符：\n```python\nlayout = spaCyLayout(nlp, separator=\" \") # 尝试改为空格或空字符串\n```","https:\u002F\u002Fgithub.com\u002Fexplosion\u002Fspacy-layout\u002Fissues\u002F9",{"id":125,"question_zh":126,"answer_zh":127,"source_url":128},18283,"如何在 spacy-layout 中统计图片或访问 Docling 的其他高级功能（如导出图片）？","spacy-layout 生成的 spans 仅包含文本，因此无法通过 `span.label_ == \"picture\"` 来统计图片。要访问图片计数或导出图片等 Docling 高级功能，需要直接实例化并配置 Docling 的 `DocumentConverter` 和 `PdfPipelineOptions`。\n\n示例代码思路：\n```python\nfrom docling.pipeline.standard_pdf_pipeline import PdfPipelineOptions\nfrom docling.document_converter import DocumentConverter\n\npipeline_options = PdfPipelineOptions()\npipeline_options.generate_picture_images = True # 启用图片生成\n# 设置其他选项...\n\ndoc_converter = DocumentConverter(pipeline_options=pipeline_options)\n# 执行转换并访问结果中的图片数据\n```","https:\u002F\u002Fgithub.com\u002Fexplosion\u002Fspacy-layout\u002Fissues\u002F40",{"id":130,"question_zh":131,"answer_zh":132,"source_url":133},18284,"是否有替代 Docling 的 PDF 解析方案（例如 Azure AI）以避免本地 GPU 依赖？","是的，可以使用 Azure AI Document Intelligence 等云服务作为替代方案，它们提供类似的输出且无需管理本地 GPU 硬件。社区已有相关的实现提案，可以将 Azure 的输出转换为兼容格式。具体实现可参考相关的 Pull Request 或 Prodigy 支持论坛中关于使用 Azure AI 替代 Docling 的讨论。","https:\u002F\u002Fgithub.com\u002Fexplosion\u002Fspacy-layout\u002Fissues\u002F41",{"id":135,"question_zh":136,"answer_zh":137,"source_url":138},18285,"运行 Prodigy 的 pdf.layout.fetch 配方时出现内存泄漏警告或非正常退出怎么办？","这个问题在较新的版本中已经得到修复。请确保将相关包升级到以下版本或更高：\n- prodigy_pdf >= 0.4.2\n- spacy_layout >= 0.0.11\n\n升级后再次运行 `python -m prodigy pdf.layout.fetch` 命令，警告和非正常退出问题应已解决。","https:\u002F\u002Fgithub.com\u002Fexplosion\u002Fspacy-layout\u002Fissues\u002F21",[140,145,150,155,160,165,170,175,180,185,190,195],{"id":141,"version":142,"summary_zh":143,"released_at":144},108845,"v0.0.12","- 在 `spaCyLayout.pipe` 中添加 `as_tuples` 参数，与 spaCy 的 `Language.pipe` 类似。（#36）\n- 增加对文档索引表的支持。（#34，@mkessy）\n- 修复文档中的拼写错误。（#33，@svlandeg）\n- 在文档中添加使用 `matplotlib` 可视化页面的代码片段。（#26，@wjbmattingly）\n- 在文档中新增 [序列化](https:\u002F\u002Fgithub.com\u002Fexplosion\u002Fspacy-layout#serialization) 章节，并附上关于使用扩展属性进行反序列化的说明。\n","2025-03-08T06:51:46",{"id":146,"version":147,"summary_zh":148,"released_at":149},108846,"v0.0.11","- 修复会导致分页数字显示错误的回归问题。","2024-12-24T07:29:50",{"id":151,"version":152,"summary_zh":153,"released_at":154},108847,"v0.0.10","- 允许将 `DoclingDocument` 作为输入传递给 `spaCyLayout.__call__`，以将已处理的文档转换为 spaCy 的 `Doc` 对象。","2024-12-13T13:59:17",{"id":156,"version":157,"summary_zh":158,"released_at":159},108848,"v0.0.9","- 添加 `Doc._.markdown`，包含文档的 Markdown 表示。","2024-12-09T11:08:09",{"id":161,"version":162,"summary_zh":163,"released_at":164},108849,"v0.0.8","- 通过 spaCy 的 `DocBin` 修复扩展属性和 `pandas.DataFrame` 的序列化问题。（#11，#14）","2024-12-07T11:42:36",{"id":166,"version":167,"summary_zh":168,"released_at":169},108850,"v0.0.7","- 修复左上角原点的边界框，重构代码并添加测试。","2024-11-24T12:31:31",{"id":171,"version":172,"summary_zh":173,"released_at":174},108851,"v0.0.6","- 增加对表格作为布局跨度的支持，并通过快捷方式 `Doc._.tables` 实现。\n- 添加 `Span._.data`，用于以 `pandas.DataFrame` 格式存储表格数据。\n- 允许通过 `display_table` 回调选项，在 `Doc.text` 中自定义表格的显示文本。","2024-11-24T11:15:09",{"id":176,"version":177,"summary_zh":178,"released_at":179},108852,"v0.0.5","- 改进左下角原点的边界框计算。","2024-11-21T13:19:18",{"id":181,"version":182,"summary_zh":183,"released_at":184},108853,"v0.0.4","- 修复左下角原点的边界框。","2024-11-20T12:32:45",{"id":186,"version":187,"summary_zh":188,"released_at":189},108854,"v0.0.3","- 添加 `spaCyLayout.pipe` 以处理多篇文档。\n- 在内部使用 `nlp.pipe` 进行分词。\n- 同时也接受 `bytes` 类型的输入。","2024-11-20T11:00:02",{"id":191,"version":192,"summary_zh":193,"released_at":194},108855,"v0.0.2","- Add `Span.id` with running index of layout span.\r\n- Add `Span._.heading` that returns closest heading for given span.","2024-11-19T09:36:39",{"id":196,"version":197,"summary_zh":79,"released_at":198},108856,"v0.0.1","2024-11-18T09:08:47"]