跳到主要内容
GROBID 是一个机器学习库,用于提取、解析和重构原始文档。 它旨在并期望用于解析学术论文,在这方面它表现特别出色。 注意:如果提供给 Grobid 的文章是超过一定数量元素的大型文档(例如学位论文),它们可能无法被处理。 本页介绍了如何使用 Grobid 解析文章以供 LangChain 使用。

安装

Grobid 的安装在 https://grobid.readthedocs.io/en/latest/Install-Grobid/ 中有详细说明。然而,通过 Docker 容器运行 Grobid 可能更容易,也麻烦更少,如 此处 所述。

将 Grobid 与 LangChain 结合使用

一旦 Grobid 安装并运行起来(您可以通过访问 https://:8070 进行检查),您就可以开始使用了。 您现在可以使用 GrobidParser 来生成文档。
from langchain_community.document_loaders.parsers import GrobidParser
from langchain_community.document_loaders.generic import GenericLoader

#Produce chunks from article paragraphs
loader = GenericLoader.from_filesystem(
    "/Users/31treehaus/Desktop/Papers/",
    glob="*",
    suffixes=[".pdf"],
    parser= GrobidParser(segment_sentences=False)
)
docs = loader.load()

#Produce chunks from article sentences
loader = GenericLoader.from_filesystem(
    "/Users/31treehaus/Desktop/Papers/",
    glob="*",
    suffixes=[".pdf"],
    parser= GrobidParser(segment_sentences=True)
)
docs = loader.load()
分块元数据将包含边界框。尽管这些框解析起来有些复杂,但它们在 https://grobid.readthedocs.io/en/latest/Coordinates-in-PDF/ 中有解释
以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.