跳到主要内容

Grobid

GROBID 是一个机器学习库,用于提取、解析和重构原始文档。

它被设计并期望用于解析学术论文,在这方面它尤其有效。

注意:如果提供给 Grobid 的文章是大型文档(例如,超过一定数量元素的论文),则可能无法处理。

本页介绍如何使用 Grobid 解析 LangChain 的文章。

安装

Grobid 的安装在 https://grobid.readthedocs.io/en/latest/Install-Grobid/ 中有详细描述。但是,通过 docker 容器运行 grobid 可能会更容易且更少麻烦,如 此处 所述。

将 Grobid 与 LangChain 一起使用

一旦 grobid 安装并启动运行(您可以通过访问 https://127.0.0.1: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()

Chunk 元数据将包括边界框。尽管这些有点难以解析,但在 https://grobid.readthedocs.io/en/latest/Coordinates-in-PDF/ 中对此进行了解释


此页面是否对您有帮助?