跳到主要内容
Open on GitHub

Grobid

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()

分块元数据将包含边界框(Bounding Boxes)。尽管这些边界框解析起来有点复杂,但在 https://grobid.readthedocs.io/en/latest/Coordinates-in-PDF/ 中有详细解释。