Grobid
GROBID 是一个机器学习库,用于提取、解析和重构原始文档。
它被设计和期望用于解析学术论文,在这方面它尤其有效。
注意:如果提供给 Grobid 的文章是大型文档(例如,学位论文),超过一定数量的元素,则可能无法处理。
此页面介绍如何使用 Grobid 解析 LangChain 的文章。
安装
Grobid 的安装在 https://grobid.readthedocs.io/en/latest/Install-Grobid/ 中详细描述。但是,通过 docker 容器运行 grobid 可能更容易且更少麻烦,如 此处 所述。
将 Grobid 与 LangChain 一起使用
一旦 grobid 安装并运行(您可以通过访问 http://localhost: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()
API 参考:GrobidParser | GenericLoader
块元数据将包括边界框。虽然这些有点难以解析,但在 https://grobid.readthedocs.io/en/latest/Coordinates-in-PDF/ 中有解释