智能解析科学文献PDF文件的工具包

发布于:2024-07-03 ⋅ 阅读:(17) ⋅ 点赞:(0)

智能解析科学文献PDF文件的工具包

智能解析科研文献PDF的工具,我发现的主要有grobid和papermage。

1 grobid

grobid是一个开源的Java实现的软件系统,不能直接使用,可通过对外提供的接口服务实现识别标题、摘要、作者、参考文献和关键词等。不过它提供了Docker安装服务,下载docker镜像也很费劲。

# 开发文档
https://grobid.readthedocs.io/en/latest/

# Github地址
https://github.com/kermitt2/grobid

# 客户端参考地址
# python
https://github.com/kermitt2/grobid_client_python

# java
https://github.com/kermitt2/grobid-client-java

# Node.js
https://github.com/kermitt2/grobid-client-node

官方源代码

注意:需要安装grobid-client-python

pip install grobid-client-python

config.json文件

{
    "grobid_server": "http://localhost:8070",
    "batch_size": 1000,
    "sleep_time": 5,
    "timeout": 60,
    "coordinates": [ "persName", "figure", "ref", "biblStruct", "formula", "s" ]
}

coordinates的参考地址:

https://grobid.readthedocs.io/en/latest/Coordinates-in-PDF/

Python代码

from grobid_client.grobid_client import GrobidClient

client = GrobidClient(config_path="./config.json")
client.process("processFulltextDocument", "/mnt/data/covid/pdfs", n=20)

2 papermage

备注:经过多次安装,无法安装成功,最终放弃。

papermage是开源的Python工具包,主要用于处理科学文献PDF文件中的信息,包括:标题、作者、摘要、关键词、段落标题、标注和参考文献等。从官网提供的Demo效果确实不错。

缺点:可能是国内环境的问题,我一直安装不成功,官网的安装方法不够详细。从Github上HuggingFace上看识别模型比较中,估计识别过程会比较慢。

# 官网地址
https://openreader.semanticscholar.org/

# 官网Demo地址
https://papermage.org/

# GitHub地址
https://github.com/allenai/papermage/tree/main

# HuggingFace上的地址,下载模型
https://hf-mirror.com/allenai

官方Python代码

from papermage.recipes import CoreRecipe

recipe = CoreRecipe()

# 解析pdf
doc = recipe.run("tests/fixtures/papermage.pdf")

我没安装成功,根据自己的理解可下载模型

下载模型的地址

# allenai/ivila-row-layoutlm-finetuned-s2vl-v2
https://hf-mirror.com/allenai/ivila-row-layoutlm-finetuned-s2vl-v2

# allenai/vila-roberta-large-s2vl-internal
https://hf-mirror.com/allenai/vila-roberta-large-s2vl-internal

# svm_word_predictor
https://ai2-s2-research-public.s3.us-west-2.amazonaws.com/mmda/models/svm_word_predictor.tar.gz
from papermage.recipes import CoreRecipe

# 自定义模型下载
recipe = CoreRecipe(
    ivila_predictor_path="E:/model/pdf/ivila-row-layoutlm-finetuned-s2vl-v2",
    bio_roberta_predictor_path="E:/model/pdf/vila-roberta-large-s2vl-internal",
    svm_word_predictor_path="E:/model/pdf/svm_word_predictor.tar.gz"
)

# 预测pdf文档 
doc = recipe.run("E:/test/test1.pdf")

print(doc)

print(doc.symbols)

一直有错误提示

OSError: [Errno 22] Invalid argument: 'C:\\Users\\XXX/.torch/iopath_cache\\s/ukbw5s673633hsw\\publaynet-tf_efficientdet_d0.pth.tar?dl=1.lock'

刚开始我以为是文件无法下载,我下载后,依旧不行。

# 注意:下面的模型无法直接下载。
MODEL_CATALOG = {
    "PubLayNet": {
        "tf_efficientdet_d0": "https://www.dropbox.com/s/ukbw5s673633hsw/publaynet-tf_efficientdet_d0.pth.tar?dl=1",
        "tf_efficientdet_d1": "https://www.dropbox.com/s/gxy11xkkiwnpgog/publaynet-tf_efficientdet_d1.pth.tar?dl=1"
    },
    "MFD": {
        "tf_efficientdet_d0": "https://www.dropbox.com/s/dkr22iux7thlhel/mfd-tf_efficientdet_d0.pth.tar?dl=1",
        "tf_efficientdet_d1": "https://www.dropbox.com/s/icmbiaqr5s9bz1x/mfd-tf_efficientdet_d1.pth.tar?dl=1"
    }
}