Attention Is All You Need
We propose a new simple network architecture, the Transformer, based solely on attention mechanisms, dispensing with recurrence and convolutions entirely.
$$ \text{Attention}(Q, K, V) = \text{softmax}\left(\frac{QK^T}{\sqrt{d_k}}\right)V $$
| Model | Parameters | WMT 2014 EN-DE |
|---|---|---|
| Transformer | 65M | 28.4 BLEU |
| RNN (Baseline) | 76M | 27.3 BLEU |
## 使用指南
### 基础安装
```bash
# PyPI安装
pip install nougat-ocr
# 源码安装
pip install git+https://gitcode.com/gh_mirrors/no/nougat
命令行推理
# 单文件转换
nougat path/to/paper.pdf -o output_dir --model 0.1.0-base
# 批量处理目录
nougat path/to/pdf_dir -o results --batchsize 4 --no-skipping
高级参数调整
# 禁用失败检测(适合低质量PDF)
nougat input.pdf -o out --no-skipping
# 使用CPU全精度模式
nougat input.pdf --full-precision
# 仅转换特定页面
nougat thesis.pdf -p 3-5,7 --model 0.1.0-small
限制与已知问题
- 语言支持:主要优化英文,对中文、日文等非拉丁语言支持有限
- 非学术文档:在简历、手册等非论文类PDF上性能显著下降
- 复杂图表:数学公式识别准确率(~69% BLEU)低于纯文本
- 失败检测:部分清晰页面可能被误判为低质量(可通过
--no-skipping禁用) - 计算资源:基础模型推理需至少4GB GPU内存
模型变体
| 模型标签 | 大小 | 速度 | 准确率 | 适用场景 |
|---|---|---|---|---|
| 0.1.0-small | 350MB | 快2× | 0.92× | 快速预览、低资源环境 |
| 0.1.0-base | 1.2GB | 基准 | 1.0× | 生产环境、高精度需求 |
扩展与定制
数据集生成
# 1. 分割HTML与PDF页面
python -m nougat.dataset.split_htmls_to_pages \
--html path/to/htmls --pdfs path/to/pdfs --out paired_data
# 2. 创建训练索引
python -m nougat.dataset.create_index --dir paired_data --out train.jsonl
# 3. 生成Seek Map(加速数据加载)
python -m nougat.dataset.gen_seek train.jsonl
微调训练
# 修改配置文件后启动训练
python train.py --config config/train_nougat.yaml
配置文件关键参数调整:
# config/train_nougat.yaml
max_epochs: 50 # 增加训练轮次
lr: 3e-5 # 降低学习率
dataset_paths: ["custom_train.jsonl"] # 自定义数据集
accumulate_grad_batches: 4 # 模拟更大批次
许可证信息
- 代码:MIT许可证
- 模型权重:CC-BY-NC 4.0(非商业使用)
- 训练数据:arXiv/PMC开放获取论文(遵守各自使用条款)
完整许可证文本见仓库LICENSE与LICENSE-MODEL文件
引用格式
@misc{blecher2023nougat,
title={Nougat: Neural Optical Understanding for Academic Documents},
author={Lukas Blecher and Guillem Cucurull and Thomas Scialom and Robert Stojnic},
year={2023},
eprint={2308.13418},
archivePrefix={arXiv},
primaryClass={cs.LG}
}
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考



