Nougat:结合光学神经网络,引领学术PDF文档的智能解析、挖掘学术论文PDF的价值

本文涉及的产品
公共DNS(含HTTPDNS解析),每月1000万次HTTP解析
云解析 DNS,旗舰版 1个月
全局流量管理 GTM,标准版 1个月
简介: Nougat:结合光学神经网络,引领学术PDF文档的智能解析、挖掘学术论文PDF的价值

Nougat:结合光学神经网络,引领学术PDF文档的智能解析、挖掘学术论文PDF的价值

这是Nougat的官方存储库,Nougat是一种学术文档PDF解析器,可以理解LaTeX数学和表格。

Project page: https://facebookresearch.github.io/nougat/

1.安装

From pip:

pip install nougat-ocr

From repository:

pip install git+https://github.com/facebookresearch/nougat

Note, on Windows: If you want to utilize a GPU, make sure you first install the correct PyTorch version. Follow instructions here

如果您想从API调用模型或生成数据集,则会有额外的依赖项。
安装通过

pip install "nougat-ocr[api]" or pip install "nougat-ocr[dataset]"

1.2 获取PDF的预测

1.2.1 CLI

To get predictions for a PDF run

$ nougat path/to/file.pdf -o output_directory

目录或文件的路径(其中每行都是PDF的路径)也可以作为位置参数传递

$ nougat path/to/directory -o output_directory
usage: nougat [-h] [--batchsize BATCHSIZE] [--checkpoint CHECKPOINT] [--model MODEL] [--out OUT]
              [--recompute] [--markdown] [--no-skipping] pdf [pdf ...]

positional arguments:
  pdf                   PDF(s) to process.

options:
  -h, --help            show this help message and exit
  --batchsize BATCHSIZE, -b BATCHSIZE
                        Batch size to use.
  --checkpoint CHECKPOINT, -c CHECKPOINT
                        Path to checkpoint directory.
  --model MODEL_TAG, -m MODEL_TAG
                        Model tag to use.
  --out OUT, -o OUT     Output directory.
  --recompute           Recompute already computed PDF, discarding previous predictions.
  --full-precision      Use float32 instead of bfloat16. Can speed up CPU conversion for some setups.
  --no-markdown         Do not add postprocessing step for markdown compatibility.
  --markdown            Add postprocessing step for markdown compatibility (default).
  --no-skipping         Don't apply failure detection heuristic.
  --pages PAGES, -p PAGES
                        Provide page numbers like '1-4,7' for pages 1 through 4 and page 7. Only works for single PDFs.

The default model tag is 0.1.0-small. If you want to use the base model, use 0.1.0-base.

$ nougat path/to/file.pdf -o output_directory -m 0.1.0-base

In the output directory every PDF will be saved as a .mmd file, the lightweight markup language, mostly compatible with Mathpix Markdown (we make use of the LaTeX tables).

Note: On some devices the failure detection heuristic is not working properly. If you experience a lot of [MISSING_PAGE] responses, try to run with the --no-skipping flag. Related: #11, #67

1.2.2 API

With the extra dependencies you use app.py to start an API. Call

$ nougat_api

通过向http://127.0.0.1:8503/ predict/发出POST请求来获得PDF文件的预测。它还接受参数“start”和“stop”,以限制计算选择页码(包括边界)。

响应是一个带有文档标记文本的字符串。

curl -X 'POST' \
  'http://127.0.0.1:8503/predict/' \
  -H 'accept: application/json' \
  -H 'Content-Type: multipart/form-data' \
  -F 'file=@<PDFFILE.pdf>;type=application/pdf'

To use the limit the conversion to pages 1 to 5, use the start/stop parameters in the request URL: http://127.0.0.1:8503/predict/?start=1&stop=5

2.Dataset

2.1 生成数据集

To generate a dataset you need

  1. A directory containing the PDFs
  2. A directory containing the .html files (processed .tex files by LaTeXML) with the same folder structure
  3. A binary file of pdffigures2 and a corresponding environment variable export PDFFIGURES_PATH="/path/to/binary.jar"

Next run

python -m nougat.dataset.split_htmls_to_pages --html path/html/root --pdfs path/pdf/root --out path/paired/output --figure path/pdffigures/outputs

Additional arguments include

Argument Description
--recompute recompute all splits
--markdown MARKDOWN Markdown output dir
--workers WORKERS How many processes to use
--dpi DPI What resolution the pages will be saved at
--timeout TIMEOUT max time per paper in seconds
--tesseract Tesseract OCR prediction for each page

Finally create a jsonl file that contains all the image paths, markdown text and meta information.

python -m nougat.dataset.create_index --dir path/paired/output --out index.jsonl

For each jsonl file you also need to generate a seek map for faster data loading:

python -m nougat.dataset.gen_seek file.jsonl

The resulting directory structure can look as follows:

root/
├── images
├── train.jsonl
├── train.seek.map
├── test.jsonl
├── test.seek.map
├── validation.jsonl
└── validation.seek.map

Note that the .mmd and .json files in the path/paired/output (here images) are no longer required.
This can be useful for pushing to a S3 bucket by halving the amount of files.

2.2Training

To train or fine tune a Nougat model, run

python train.py --config config/train_nougat.yaml

2.3 Evaluation

Run

python test.py --checkpoint path/to/checkpoint --dataset path/to/test.jsonl --save_path path/to/results.json

To get the results for the different text modalities, run

python -m nougat.metrics path/to/results.json

2.4 FAQ

  • Why am I only getting [MISSING_PAGE]?

    Nougat was trained on scientific papers found on arXiv and PMC. Is the document you're processing similar to that?
    What language is the document in? Nougat works best with English papers, other Latin-based languages might work. Chinese, Russian, Japanese etc. will not work.
    If these requirements are fulfilled it might be because of false positives in the failure detection, when computing on CPU or older GPUs (#11). Try passing the --no-skipping flag for now.

  • Where can I download the model checkpoint from.

    They are uploaded here on GitHub in the release section. You can also download them during the first execution of the program. Choose the preferred preferred model by passing --model 0.1.0-{base,small}

参考链接:
https://github.com/facebookresearch/nougat

更多优质内容请关注公号:汀丶人工智能;会提供一些相关的资源和优质文章,免费获取阅读。

相关文章
|
2天前
|
网络协议 网络虚拟化
接收网络包的过程——从硬件网卡解析到IP
【9月更文挑战第18天】这段内容详细描述了网络包接收过程中机制。当网络包触发中断后,内核处理完这批网络包,会进入主动轮询模式,持续处理后续到来的包,直至处理间隙返回其他任务,从而减少中断次数,提高处理效率。此机制涉及网卡驱动初始化时注册轮询函数,通过软中断触发后续处理,并逐步深入内核网络协议栈,最终到达TCP层。整个接收流程分为多个层次,包括DMA技术存入Ring Buffer、中断通知CPU、软中断处理、以及进入内核网络协议栈等多个步骤。
|
2天前
|
数据采集 存储 JSON
从零到一构建网络爬虫帝国:HTTP协议+Python requests库深度解析
在网络数据的海洋中,网络爬虫遵循HTTP协议,穿梭于互联网各处,收集宝贵信息。本文将从零开始,使用Python的requests库,深入解析HTTP协议,助你构建自己的网络爬虫帝国。首先介绍HTTP协议基础,包括请求与响应结构;然后详细介绍requests库的安装与使用,演示如何发送GET和POST请求并处理响应;最后概述爬虫构建流程及挑战,帮助你逐步掌握核心技术,畅游数据海洋。
17 3
|
3天前
|
监控 安全 网络安全
网络安全的盾与剑:漏洞防御与加密技术解析
【9月更文挑战第17天】在数字时代的浪潮中,网络安全成为保护数据和隐私的关键防线。本文深入浅出地探讨了网络安全的两大支柱:漏洞防御和加密技术,旨在提升公众的安全意识并分享防护策略。我们将从基础概念出发,逐步深入到技术细节,不仅阐释原理,还提供实际案例分析,帮助读者构建起一道坚固的数字防御墙。
17 3
|
9天前
|
机器学习/深度学习 人工智能 TensorFlow
神经网络深度剖析:Python带你潜入AI大脑,揭秘智能背后的秘密神经元
【9月更文挑战第12天】在当今科技飞速发展的时代,人工智能(AI)已深入我们的生活,从智能助手到自动驾驶,从医疗诊断到金融分析,其力量无处不在。这一切的核心是神经网络。本文将带领您搭乘Python的航船,深入AI的大脑,揭秘智能背后的秘密神经元。通过构建神经网络模型,我们可以模拟并学习复杂的数据模式。以下是一个使用Python和TensorFlow搭建的基本神经网络示例,用于解决简单的分类问题。
32 10
|
8天前
|
存储 安全 算法
网络安全与信息安全的全方位解析
在现代社会,随着信息技术的飞速发展,网络安全和信息安全问题日益凸显。本文将通过浅显易懂的语言和具体的实例,全面解析网络安全漏洞、加密技术以及安全意识等方面的知识,帮助读者提升对网络安全与信息安全的认知和应对能力。
|
10天前
|
机器学习/深度学习 人工智能 TensorFlow
深入骨髓的解析:Python中神经网络如何学会‘思考’,解锁AI新纪元
【9月更文挑战第11天】随着科技的发展,人工智能(AI)成为推动社会进步的关键力量,而神经网络作为AI的核心,正以其强大的学习和模式识别能力开启AI新纪元。本文将探讨Python中神经网络的工作原理,并通过示例代码展示其“思考”过程。神经网络模仿生物神经系统,通过加权连接传递信息并优化输出。Python凭借其丰富的科学计算库如TensorFlow和PyTorch,成为神经网络研究的首选语言。
12 1
|
11天前
|
存储 SQL 安全
网络安全的盾牌:漏洞防御与加密技术解析
【9月更文挑战第9天】在数字时代,网络安全的重要性日益凸显,它不仅是保护个人隐私和数据安全的屏障,也是维护社会稳定和经济繁荣的关键。本文将深入探讨网络安全中的漏洞防御策略、加密技术的运用以及提升公众安全意识的必要性,旨在通过知识分享,增强大众对网络威胁的防范能力,共同构建更安全的网络环境。
|
4天前
|
安全 网络安全 数据安全/隐私保护
网络安全漏洞、加密技术与安全意识的深度解析
【9月更文挑战第16天】在数字化时代,网络安全的重要性不言而喻。本文将深入探讨网络安全的三大支柱:网络漏洞、加密技术和安全意识。我们将从实际案例出发,揭示网络攻击者如何利用安全漏洞进行入侵,分析加密技术如何保护数据安全,以及为何培养良好的安全意识对于防范网络威胁至关重要。通过本文,您将获得实用的网络安全知识和技能,以更好地保护自己和他人的网络空间。
|
4天前
|
安全 网络安全 数据安全/隐私保护
网络安全的护城河:漏洞防御与加密技术解析
【9月更文挑战第16天】在数字信息的海洋中,网络安全是守护数据宝库的坚固城墙。本文将深入探讨网络安全中的漏洞防御和加密技术,揭示安全意识的重要性,并提供实用的代码示例,帮助读者构建起一道道防护墙,确保信息安全的堡垒坚不可摧。
16 0
|
14天前
|
域名解析 监控 负载均衡
智能DNS解析:自动选择最快服务器的奥秘
【9月更文挑战第7天】智能DNS解析是一种根据用户网络环境和服务器负载动态选择最佳服务器的技术,显著提升了访问速度与稳定性。本文详细介绍了其工作原理,包括实时监控、数据分析和路由选择,并探讨了自动选择最快服务器背后的算法策略,如负载均衡、地理位置识别及实时测试。附带示例代码帮助理解其基本实现过程。
48 0

推荐镜像

更多