同步完整源码 - 2026-05-24
@@ -0,0 +1,154 @@
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.nox/
|
||||
.coverage
|
||||
*.cover
|
||||
*.py,cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
coverage.xml
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
db.sqlite3-journal
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# IPython
|
||||
profile_default/
|
||||
ipython_config.py
|
||||
|
||||
# pyenv
|
||||
.python-version
|
||||
|
||||
# pipenv
|
||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||
# install all needed dependencies.
|
||||
#Pipfile.lock
|
||||
|
||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
||||
__pypackages__/
|
||||
|
||||
# Celery stuff
|
||||
celerybeat-schedule
|
||||
celerybeat.pid
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
.dmypy.json
|
||||
dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
# pytype static type analyzer
|
||||
.pytype/
|
||||
|
||||
# Cython debug symbols
|
||||
cython_debug/
|
||||
|
||||
# PyCharm
|
||||
.idea/
|
||||
*.iml
|
||||
|
||||
# VS Code
|
||||
.vscode/
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
|
||||
# macOS
|
||||
.DS_Store
|
||||
|
||||
# Windows
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
Desktop.ini
|
||||
|
||||
fusion_result.json
|
||||
kernel_meta/
|
||||
@@ -0,0 +1,34 @@
|
||||
repos:
|
||||
# 1. isort - 自动排序 Python imports
|
||||
- repo: https://github.com/pycqa/isort
|
||||
rev: 6.0.1 # 使用固定版本号
|
||||
hooks:
|
||||
- id: isort
|
||||
name: isort (python)
|
||||
args: [--profile=black] # 与 Black 兼容的配置
|
||||
language: python
|
||||
|
||||
# 2. Black - 自动格式化 Python 代码
|
||||
- repo: https://github.com/psf/black
|
||||
rev: 25.1.0 # 使用固定版本号
|
||||
hooks:
|
||||
- id: black
|
||||
language: python
|
||||
|
||||
# 3. flake8 - Python 静态检查
|
||||
- repo: https://github.com/pycqa/flake8
|
||||
rev: 7.2.0
|
||||
hooks:
|
||||
- id: flake8
|
||||
args: [--max-line-length=120, --ignore=E203] # 设置行长度为 120
|
||||
additional_dependencies: [flake8-bugbear==24.12.12] # 可选:增强检查
|
||||
|
||||
# 4. pre-commit-hooks - 通用 Git 钩子
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v5.0.0
|
||||
hooks:
|
||||
- id: trailing-whitespace # 删除行尾空格
|
||||
- id: end-of-file-fixer # 确保文件以换行符结束
|
||||
- id: check-yaml # 验证 YAML 文件语法
|
||||
- id: check-added-large-files # 阻止大文件提交
|
||||
args: ["--maxkb=512"]
|
||||
@@ -0,0 +1,54 @@
|
||||
Qwen RESEARCH LICENSE AGREEMENT
|
||||
|
||||
Qwen RESEARCH LICENSE AGREEMENT Release Date: September 19, 2024
|
||||
|
||||
By clicking to agree or by using or distributing any portion or element of the Qwen Materials, you will be deemed to have recognized and accepted the content of this Agreement, which is effective immediately.
|
||||
|
||||
1. Definitions
|
||||
a. This Qwen RESEARCH LICENSE AGREEMENT (this "Agreement") shall mean the terms and conditions for use, reproduction, distribution and modification of the Materials as defined by this Agreement.
|
||||
b. "We" (or "Us") shall mean Alibaba Cloud.
|
||||
c. "You" (or "Your") shall mean a natural person or legal entity exercising the rights granted by this Agreement and/or using the Materials for any purpose and in any field of use.
|
||||
d. "Third Parties" shall mean individuals or legal entities that are not under common control with us or you.
|
||||
e. "Qwen" shall mean the large language models, and software and algorithms, consisting of trained model weights, parameters (including optimizer states), machine-learning model code, inference-enabling code, training-enabling code, fine-tuning enabling code and other elements of the foregoing distributed by us.
|
||||
f. "Materials" shall mean, collectively, Alibaba Cloud's proprietary Qwen and Documentation (and any portion thereof) made available under this Agreement.
|
||||
g. "Source" form shall mean the preferred form for making modifications, including but not limited to model source code, documentation source, and configuration files.
|
||||
h. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
||||
i. "Non-Commercial" shall mean for research or evaluation purposes only.
|
||||
|
||||
2. Grant of Rights
|
||||
a. You are granted a non-exclusive, worldwide, non-transferable and royalty-free limited license under Alibaba Cloud's intellectual property or other rights owned by us embodied in the Materials to use, reproduce, distribute, copy, create derivative works of, and make modifications to the Materials FOR NON-COMMERCIAL PURPOSES ONLY.
|
||||
b. If you are commercially using the Materials, you shall request a license from us.
|
||||
|
||||
3. Redistribution
|
||||
You may distribute copies or make the Materials, or derivative works thereof, available as part of a product or service that contains any of them, with or without modifications, and in Source or Object form, provided that you meet the following conditions:
|
||||
a. You shall give any other recipients of the Materials or derivative works a copy of this Agreement;
|
||||
b. You shall cause any modified files to carry prominent notices stating that you changed the files;
|
||||
c. You shall retain in all copies of the Materials that you distribute the following attribution notices within a "Notice" text file distributed as a part of such copies: "Qwen is licensed under the Qwen RESEARCH LICENSE AGREEMENT, Copyright (c) Alibaba Cloud. All Rights Reserved."; and
|
||||
d. You may add your own copyright statement to your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of your modifications, or for any such derivative works as a whole, provided your use, reproduction, and distribution of the work otherwise complies with the terms and conditions of this Agreement.
|
||||
|
||||
4. Rules of use
|
||||
a. The Materials may be subject to export controls or restrictions in China, the United States or other countries or regions. You shall comply with applicable laws and regulations in your use of the Materials.
|
||||
b. If you use the Materials or any outputs or results therefrom to create, train, fine-tune, or improve an AI model that is distributed or made available, you shall prominently display “Built with Qwen” or “Improved using Qwen” in the related product documentation.
|
||||
|
||||
5. Intellectual Property
|
||||
a. We retain ownership of all intellectual property rights in and to the Materials and derivatives made by or for us. Conditioned upon compliance with the terms and conditions of this Agreement, with respect to any derivative works and modifications of the Materials that are made by you, you are and will be the owner of such derivative works and modifications.
|
||||
b. No trademark license is granted to use the trade names, trademarks, service marks, or product names of us, except as required to fulfill notice requirements under this Agreement or as required for reasonable and customary use in describing and redistributing the Materials.
|
||||
c. If you commence a lawsuit or other proceedings (including a cross-claim or counterclaim in a lawsuit) against us or any entity alleging that the Materials or any output therefrom, or any part of the foregoing, infringe any intellectual property or other right owned or licensable by you, then all licenses granted to you under this Agreement shall terminate as of the date such lawsuit or other proceeding is commenced or brought.
|
||||
|
||||
6. Disclaimer of Warranty and Limitation of Liability
|
||||
a. We are not obligated to support, update, provide training for, or develop any further version of the Qwen Materials or to grant any license thereto.
|
||||
b. THE MATERIALS ARE PROVIDED "AS IS" WITHOUT ANY EXPRESS OR IMPLIED WARRANTY OF ANY KIND INCLUDING WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, OR FITNESS FOR A PARTICULAR PURPOSE. WE MAKE NO WARRANTY AND ASSUME NO RESPONSIBILITY FOR THE SAFETY OR STABILITY OF THE MATERIALS AND ANY OUTPUT THEREFROM.
|
||||
c. IN NO EVENT SHALL WE BE LIABLE TO YOU FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO ANY DIRECT, OR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM YOUR USE OR INABILITY TO USE THE MATERIALS OR ANY OUTPUT OF IT, NO MATTER HOW IT’S CAUSED.
|
||||
d. You will defend, indemnify and hold harmless us from and against any claim by any third party arising out of or related to your use or distribution of the Materials.
|
||||
|
||||
7. Survival and Termination.
|
||||
a. The term of this Agreement shall commence upon your acceptance of this Agreement or access to the Materials and will continue in full force and effect until terminated in accordance with the terms and conditions herein.
|
||||
b. We may terminate this Agreement if you breach any of the terms or conditions of this Agreement. Upon termination of this Agreement, you must delete and cease use of the Materials. Sections 6 and 8 shall survive the termination of this Agreement.
|
||||
|
||||
8. Governing Law and Jurisdiction.
|
||||
a. This Agreement and any dispute arising out of or relating to it will be governed by the laws of China, without regard to conflict of law principles, and the UN Convention on Contracts for the International Sale of Goods does not apply to this Agreement.
|
||||
b. The People's Courts in Hangzhou City shall have exclusive jurisdiction over any dispute arising out of this Agreement.
|
||||
|
||||
9. Other Terms and Conditions.
|
||||
a. Any arrangements, understandings, or agreements regarding the Material not stated herein are separate from and independent of the terms and conditions of this Agreement. You shall request a separate license from us, if you use the Materials in ways not expressly agreed to in this Agreement.
|
||||
b. We shall not be bound by any additional or different terms or conditions communicated by you unless expressly agreed.
|
||||
@@ -0,0 +1,226 @@
|
||||
<div align="center">
|
||||
<img src="./assets/dolphin.png" width="300">
|
||||
</div>
|
||||
|
||||
<div align="center">
|
||||
<a href="https://arxiv.org/abs/2505.14059">
|
||||
<img src="https://img.shields.io/badge/Paper-arXiv-red">
|
||||
</a>
|
||||
<a href="https://huggingface.co/ByteDance/Dolphin-v2">
|
||||
<img src="https://img.shields.io/badge/HuggingFace-Dolphin-yellow">
|
||||
</a>
|
||||
<a href="https://github.com/bytedance/Dolphin">
|
||||
<img src="https://img.shields.io/badge/Code-Github-green">
|
||||
</a>
|
||||
<a href="https://opensource.org/licenses/MIT">
|
||||
<img src="https://img.shields.io/badge/License-MIT-lightgray">
|
||||
</a>
|
||||
<br>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
|
||||
<div align="center">
|
||||
<img src="./assets/demo.gif" width="800">
|
||||
</div>
|
||||
|
||||
# Dolphin: Document Image Parsing via Heterogeneous Anchor Prompting
|
||||
Dolphin-v2 is an enhanced universal document parsing model that substantially improves upon the original Dolphin. It seamlessly handles any document type—whether digital-born or photographed—through a document-type-aware two-stage architecture with scalable anchor prompting.
|
||||
|
||||
|
||||
## 📑 Overview
|
||||
|
||||
Document image parsing is challenging due to diverse document types and complexly intertwined elements such as text paragraphs, figures, formulas, tables, and code blocks. Dolphin-v2 addresses these challenges through a document-type-aware two-stage approach:
|
||||
|
||||
1. **🔍 Stage 1**: Document type classification (digital vs. photographed) + layout analysis with reading order prediction
|
||||
2. **🧩 Stage 2**: Hybrid parsing strategy - holistic parsing for photographed documents, parallel element-wise parsing for digital documents
|
||||
|
||||
<div align="center">
|
||||
<img src="./assets/framework.png" width="680">
|
||||
</div>
|
||||
|
||||
Dolphin achieves promising performance across diverse page-level and element-level parsing tasks while ensuring superior efficiency through its lightweight architecture and parallel parsing mechanism.
|
||||
|
||||
<!-- ## 🚀 Demo
|
||||
Try our demo on [Demo-Dolphin](https://huggingface.co/spaces/ByteDance/Dolphin). -->
|
||||
|
||||
## 📅 Changelog
|
||||
- 🔥 **2025.12.12** Released *Dolphin-v2* model. Upgraded to 3B parameters with 21-element detection, attribute field extraction, dedicated formula/code parsing, and robust photographed document parsing. (Dolphin-1.5 moved to [v1.5 branch](https://github.com/bytedance/Dolphin/tree/v1.5))
|
||||
- 🔥 **2025.10.16** Released *Dolphin-1.5* model. While maintaining the lightweight 0.3B architecture, this version achieves significant parsing improvements. (Dolphin 1.0 moved to [v1.0 branch](https://github.com/bytedance/Dolphin/tree/v1.0))
|
||||
- 🔥 **2025.07.10** Released the *Fox-Page Benchmark*, a manually refined subset of the original [Fox dataset](https://github.com/ucaslcl/Fox). Download via: [Baidu Yun](https://pan.baidu.com/share/init?surl=t746ULp6iU5bUraVrPlMSw&pwd=fox1) | [Google Drive](https://drive.google.com/file/d/1yZQZqI34QCqvhB4Tmdl3X_XEvYvQyP0q/view?usp=sharing).
|
||||
- 🔥 **2025.06.30** Added [TensorRT-LLM support](https://github.com/bytedance/Dolphin/blob/master/deployment/tensorrt_llm/ReadMe.md) for accelerated inference!
|
||||
- 🔥 **2025.06.27** Added [vLLM support](https://github.com/bytedance/Dolphin/blob/master/deployment/vllm/ReadMe.md) for accelerated inference!
|
||||
- 🔥 **2025.06.13** Added multi-page PDF document parsing capability.
|
||||
- 🔥 **2025.05.21** Our demo is released at [link](http://115.190.42.15:8888/dolphin/). Check it out!
|
||||
- 🔥 **2025.05.20** The pretrained model and inference code of Dolphin are released.
|
||||
- 🔥 **2025.05.16** Our paper has been accepted by ACL 2025. Paper link: [arXiv](https://arxiv.org/abs/2505.14059).
|
||||
|
||||
## 📈 Performance
|
||||
|
||||
<table style="width:90%; border-collapse: collapse; text-align: center;">
|
||||
<caption>Comprehensive evaluation of document parsing on OmniDocBench (v1.5)</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="text-align: center !important;">Model</th>
|
||||
<th style="text-align: center !important;">Size</th>
|
||||
<th style="text-align: center !important;">Overall↑</th>
|
||||
<th style="text-align: center !important;">Text<sup>Edit</sup>↓</th>
|
||||
<th style="text-align: center !important;">Formula<sup>CDM</sup>↑</th>
|
||||
<th style="text-align: center !important;">Table<sup>TEDS</sup>↑</th>
|
||||
<th style="text-align: center !important;">Table<sup>TEDS-S</sup>↑</th>
|
||||
<th style="text-align: center !important;">Read Order<sup>Edit</sup>↓</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Dolphin</td>
|
||||
<td>0.3B</td>
|
||||
<td>74.67</td>
|
||||
<td>0.125</td>
|
||||
<td>67.85</td>
|
||||
<td>68.70</td>
|
||||
<td>77.77</td>
|
||||
<td>0.124</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Dolphin-1.5</td>
|
||||
<td>0.3B</td>
|
||||
<td>85.06</td>
|
||||
<td>0.085</td>
|
||||
<td>79.44</td>
|
||||
<td>84.25</td>
|
||||
<td>88.06</td>
|
||||
<td>0.071</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Dolphin-v2</td>
|
||||
<td>3B</td>
|
||||
<td><strong>89.78</strong></td>
|
||||
<td><strong>0.054</strong></td>
|
||||
<td><strong>87.63</strong></td>
|
||||
<td><strong>87.02</strong></td>
|
||||
<td><strong>90.48</strong></td>
|
||||
<td><strong>0.054</strong></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
## 🛠️ Installation
|
||||
|
||||
1. Clone the repository:
|
||||
```bash
|
||||
git clone https://github.com/ByteDance/Dolphin.git
|
||||
cd Dolphin
|
||||
```
|
||||
|
||||
2. Install the dependencies:
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
3. Download the pre-trained models of *Dolphin-v2*:
|
||||
|
||||
Visit our Huggingface [model card](https://huggingface.co/ByteDance/Dolphin-v2), or download model by:
|
||||
|
||||
```bash
|
||||
# Download the model from Hugging Face Hub
|
||||
git lfs install
|
||||
git clone https://huggingface.co/ByteDance/Dolphin-v2 ./hf_model
|
||||
# Or use the Hugging Face CLI
|
||||
pip install huggingface_hub
|
||||
huggingface-cli download ByteDance/Dolphin-v2 --local-dir ./hf_model
|
||||
```
|
||||
|
||||
## ⚡ Inference
|
||||
|
||||
Dolphin provides two inference frameworks with support for two parsing granularities:
|
||||
- **Page-level Parsing**: Parse the entire document page into a structured JSON and Markdown format
|
||||
- **Element-level Parsing**: Parse individual document elements (text, table, formula)
|
||||
|
||||
|
||||
### 📄 Page-level Parsing
|
||||
|
||||
```bash
|
||||
# Process a single document image
|
||||
python demo_page.py --model_path ./hf_model --save_dir ./results \
|
||||
--input_path ./demo/page_imgs/page_1.png
|
||||
|
||||
# Process a single document pdf
|
||||
python demo_page.py --model_path ./hf_model --save_dir ./results \
|
||||
--input_path ./demo/page_imgs/page_6.pdf
|
||||
|
||||
# Process all documents in a directory
|
||||
python demo_page.py --model_path ./hf_model --save_dir ./results \
|
||||
--input_path ./demo/page_imgs
|
||||
|
||||
# Process with custom batch size for parallel element decoding
|
||||
python demo_page.py --model_path ./hf_model --save_dir ./results \
|
||||
--input_path ./demo/page_imgs \
|
||||
--max_batch_size 8
|
||||
```
|
||||
|
||||
### 🧩 Element-level Parsing
|
||||
|
||||
````bash
|
||||
# Process element images (specify element_type: table, formula, text, or code)
|
||||
python demo_element.py --model_path ./hf_model --save_dir ./results \
|
||||
--input_path \
|
||||
--element_type [table|formula|text|code]
|
||||
````
|
||||
|
||||
### 🎨 Layout Parsing
|
||||
````bash
|
||||
# Process a single document image
|
||||
python demo_layout.py --model_path ./hf_model --save_dir ./results \
|
||||
--input_path ./demo/page_imgs/page_1.png \
|
||||
|
||||
# Process a single PDF document
|
||||
python demo_layout.py --model_path ./hf_model --save_dir ./results \
|
||||
--input_path ./demo/page_imgs/page_6.pdf \
|
||||
|
||||
# Process all documents in a directory
|
||||
python demo_layout.py --model_path ./hf_model --save_dir ./results \
|
||||
--input_path ./demo/page_imgs
|
||||
````
|
||||
|
||||
|
||||
## 🌟 Key Features
|
||||
|
||||
- 🔄 Two-stage analyze-then-parse approach based on a single VLM
|
||||
- 📊 Promising performance on document parsing tasks
|
||||
- 🔍 Natural reading order element sequence generation
|
||||
- 🧩 Heterogeneous anchor prompting for different document elements
|
||||
- ⏱️ Efficient parallel parsing mechanism
|
||||
- 🤗 Support for Hugging Face Transformers for easier integration
|
||||
|
||||
|
||||
## 📮 Notice
|
||||
**Call for Bad Cases:** If you have encountered any cases where the model performs poorly, we would greatly appreciate it if you could share them in the issue. We are continuously working to optimize and improve the model.
|
||||
|
||||
## 💖 Acknowledgement
|
||||
|
||||
We would like to acknowledge the following open-source projects that provided inspiration and reference for this work:
|
||||
- [OmniDocBench](https://github.com/opendatalab/OmniDocBench)
|
||||
- [Donut](https://github.com/clovaai/donut/)
|
||||
- [Nougat](https://github.com/facebookresearch/nougat)
|
||||
- [GOT](https://github.com/Ucas-HaoranWei/GOT-OCR2.0)
|
||||
- [MinerU](https://github.com/opendatalab/MinerU/tree/master)
|
||||
- [Swin](https://github.com/microsoft/Swin-Transformer)
|
||||
- [Hugging Face Transformers](https://github.com/huggingface/transformers)
|
||||
|
||||
## 📝 Citation
|
||||
|
||||
If you find this code useful for your research, please use the following BibTeX entry.
|
||||
|
||||
```bibtex
|
||||
@article{feng2025dolphin,
|
||||
title={Dolphin: Document Image Parsing via Heterogeneous Anchor Prompting},
|
||||
author={Feng, Hao and Wei, Shu and Fei, Xiang and Shi, Wei and Han, Yingdong and Liao, Lei and Lu, Jinghui and Wu, Binghong and Liu, Qi and Lin, Chunhui and others},
|
||||
journal={arXiv preprint arXiv:2505.14059},
|
||||
year={2025}
|
||||
}
|
||||
```
|
||||
|
||||
## Star History
|
||||
|
||||
[](https://www.star-history.com/#bytedance/Dolphin&Date)
|
||||
@@ -0,0 +1,223 @@
|
||||
<div align="center">
|
||||
<img src="./assets/dolphin.png" width="300">
|
||||
</div>
|
||||
|
||||
<div align="center">
|
||||
<a href="https://arxiv.org/abs/2505.14059">
|
||||
<img src="https://img.shields.io/badge/论文-arXiv-red">
|
||||
</a>
|
||||
<a href="https://huggingface.co/ByteDance/Dolphin-v2">
|
||||
<img src="https://img.shields.io/badge/HuggingFace-Dolphin-yellow">
|
||||
</a>
|
||||
<a href="https://github.com/bytedance/Dolphin">
|
||||
<img src="https://img.shields.io/badge/代码-Github-green">
|
||||
</a>
|
||||
<a href="https://opensource.org/licenses/MIT">
|
||||
<img src="https://img.shields.io/badge/许可证-MIT-lightgray">
|
||||
</a>
|
||||
<br>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
|
||||
<div align="center">
|
||||
<img src="./assets/demo.gif" width="800">
|
||||
</div>
|
||||
|
||||
# Dolphin: 基于异构锚点提示的文档图像解析
|
||||
|
||||
Dolphin(**Do**cument Image **P**arsing via **H**eterogeneous Anchor Prompt**in**g)是一个创新的多模态文档图像解析模型(**0.3B**),采用"分析-解析"的两阶段范式。本仓库包含Dolphin的演示代码和预训练模型。
|
||||
|
||||
## 📑 概述
|
||||
|
||||
由于文档图像中文本段落、图表、公式和表格等元素的复杂交织,文档图像解析具有挑战性。Dolphin通过两阶段方法解决这些挑战:
|
||||
|
||||
1. **🔍 第一阶段**:通过按自然阅读顺序生成元素序列进行全面的页面级布局分析
|
||||
2. **🧩 第二阶段**:使用异构锚点和任务特定提示高效并行解析文档元素
|
||||
|
||||
<div align="center">
|
||||
<img src="./assets/framework.png" width="680">
|
||||
</div>
|
||||
|
||||
Dolphin在多样化的页面级和元素级解析任务中取得了优异的性能,同时通过其轻量级架构和并行解析机制确保了卓越的效率。
|
||||
|
||||
## 📅 更新日志
|
||||
- 🔥 **2025.12.12** *Dolphin-v2* 开源!支持 21 类元素检测、属性字段提取、代码专用解析,以及拍照文档解析。(原1.5版本已迁移至[v1.5分支](https://github.com/bytedance/Dolphin/tree/v1.5))
|
||||
- 🔥 **2025.10.16** *Dolphin-1.5* 开源!在保持轻量级0.3B架构的同时,该版本实现了显著的解析性能提升。(原1.0版本已迁移至[v1.0分支](https://github.com/bytedance/Dolphin/tree/v1.0))
|
||||
- 🔥 **2025.07.10** *Fox-Page* 基准测试开源。这是原始 [Fox 数据集](https://github.com/ucaslcl/Fox) 人工矫正标注后的版本。下载地址:[百度网盘](https://pan.baidu.com/share/init?surl=t746ULp6iU5bUraVrPlMSw&pwd=fox1) | [Google Drive](https://drive.google.com/file/d/1yZQZqI34QCqvhB4Tmdl3X_XEvYvQyP0q/view?usp=sharing)。
|
||||
- 🔥 **2025.06.30** 新增[TensorRT-LLM](https://github.com/bytedance/Dolphin/blob/master/deployment/tensorrt_llm/ReadMe.md)支持,提升推理速度!
|
||||
- 🔥 **2025.06.27** 新增[vLLM](https://github.com/bytedance/Dolphin/blob/master/deployment/vllm/ReadMe.md)支持,提升推理速度!
|
||||
- 🔥 **2025.06.13** 新增多页PDF文档解析功能。
|
||||
- 🔥 **2025.05.21** 我们的演示已在 [链接](http://115.190.42.15:8888/dolphin/) 发布。快来体验吧!
|
||||
- 🔥 **2025.05.20** Dolphin的预训练模型和推理代码已发布。
|
||||
- 🔥 **2025.05.16** 我们的论文已被ACL 2025接收。论文链接:[arXiv](https://arxiv.org/abs/2505.14059)。
|
||||
|
||||
## 📈 性能表现
|
||||
|
||||
<table style="width:90%; border-collapse: collapse; text-align: center;">
|
||||
<caption>OmniDocBench (v1.5) 测试基准上评估结果</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="text-align: center !important;">模型</th>
|
||||
<th style="text-align: center !important;">参数</th>
|
||||
<th style="text-align: center !important;">总体↑</th>
|
||||
<th style="text-align: center !important;">文本<sup>Edit</sup>↓</th>
|
||||
<th style="text-align: center !important;">公式<sup>CDM</sup>↑</th>
|
||||
<th style="text-align: center !important;">表格<sup>TEDS</sup>↑</th>
|
||||
<th style="text-align: center !important;">表格<sup>TEDS-S</sup>↑</th>
|
||||
<th style="text-align: center !important;">阅读顺序<sup>Edit</sup>↓</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tr>
|
||||
<td>Dolphin</td>
|
||||
<td>0.3B</td>
|
||||
<td>74.67</td>
|
||||
<td>0.125</td>
|
||||
<td>67.85</td>
|
||||
<td>68.70</td>
|
||||
<td>77.77</td>
|
||||
<td>0.124</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Dolphin-1.5</td>
|
||||
<td>0.3B</td>
|
||||
<td>85.06</td>
|
||||
<td>0.085</td>
|
||||
<td>79.44</td>
|
||||
<td>84.25</td>
|
||||
<td>88.06</td>
|
||||
<td>0.071</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Dolphin-v2</td>
|
||||
<td>0.3B</td>
|
||||
<td><strong>89.78</strong></td>
|
||||
<td><strong>0.054</strong></td>
|
||||
<td><strong>87.63</strong></td>
|
||||
<td><strong>87.02</strong></td>
|
||||
<td><strong>90.48</strong></td>
|
||||
<td><strong>0.054</strong></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
## 🛠️ 安装
|
||||
|
||||
1. 克隆仓库:
|
||||
```bash
|
||||
git clone https://github.com/ByteDance/Dolphin.git
|
||||
cd Dolphin
|
||||
```
|
||||
|
||||
2. 安装依赖:
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
3. 使用以下选项之一下载 *Dolphin-v2* 的预训练模型:
|
||||
访问我们的Huggingface [模型卡片](https://huggingface.co/ByteDance/Dolphin-v2),或通过以下方式下载模型:
|
||||
|
||||
```bash
|
||||
# 从Hugging Face Hub下载模型
|
||||
git lfs install
|
||||
git clone https://huggingface.co/ByteDance/Dolphin-v2 ./hf_model
|
||||
# 或使用Hugging Face CLI
|
||||
pip install huggingface_hub
|
||||
huggingface-cli download ByteDance/Dolphin-v2 --local-dir ./hf_model
|
||||
```
|
||||
|
||||
## ⚡ 推理
|
||||
|
||||
Dolphin提供两个推理框架,支持两种解析粒度:
|
||||
- **页面级解析**:将整个文档页面解析为结构化的JSON和Markdown格式
|
||||
- **元素级解析**:解析单个文档元素(文本、表格、公式)
|
||||
|
||||
|
||||
### 📄 页面级解析
|
||||
|
||||
```bash
|
||||
# 处理单个文档图像
|
||||
python demo_page.py --model_path ./hf_model --save_dir ./results \
|
||||
--input_path ./demo/page_imgs/page_1.png
|
||||
|
||||
# 处理单个文档PDF
|
||||
python demo_page.py --model_path ./hf_model --save_dir ./results \
|
||||
--input_path ./demo/page_imgs/page_6.pdf
|
||||
|
||||
# 处理目录中的所有文档
|
||||
python demo_page.py --model_path ./hf_model --save_dir ./results \
|
||||
--input_path ./demo/page_imgs
|
||||
|
||||
# 使用自定义批次大小进行并行元素解码
|
||||
python demo_page.py --model_path ./hf_model --save_dir ./results \
|
||||
--input_path ./demo/page_imgs \
|
||||
--max_batch_size 8
|
||||
```
|
||||
|
||||
### 🧩 元素级解析
|
||||
|
||||
````bash
|
||||
# 解析块图像 (支持块图像类型: table, formula, text, or code)
|
||||
python demo_element.py --model_path ./hf_model --save_dir ./results \
|
||||
--input_path \
|
||||
--element_type [table|formula|text|code]
|
||||
````
|
||||
|
||||
### 🎨 元素定位及阅读顺序解析
|
||||
````bash
|
||||
# 处理单个文档图像
|
||||
python demo_layout.py --model_path ./hf_model --save_dir ./results \
|
||||
--input_path ./demo/page_imgs/page_1.png \
|
||||
|
||||
# 处理单个文档PDF
|
||||
python demo_layout.py --model_path ./hf_model --save_dir ./results \
|
||||
--input_path ./demo/page_imgs/page_6.pdf \
|
||||
|
||||
# 处理目录中的所有文档
|
||||
python demo_layout.py --model_path ./hf_model --save_dir ./results \
|
||||
--input_path ./demo/page_imgs
|
||||
````
|
||||
|
||||
|
||||
## 🌟 主要特性
|
||||
|
||||
- 🔄 基于单一VLM的两阶段分析-解析方法
|
||||
- 📊 在文档解析任务上的优异性能
|
||||
- 🔍 自然阅读顺序元素序列生成
|
||||
- 🧩 针对不同文档元素的异构锚点提示
|
||||
- ⏱️ 高效的并行解析机制
|
||||
- 🤗 支持Hugging Face Transformers,便于集成
|
||||
|
||||
|
||||
## 📮 通知
|
||||
**征集不良案例:** 如果您遇到模型表现不佳的案例,我们非常欢迎您在issue中分享。我们正在持续优化和改进模型。
|
||||
|
||||
|
||||
## 💖 致谢
|
||||
|
||||
我们要感谢以下开源项目为本工作提供的灵感和参考:
|
||||
- [OmniDocBench](https://github.com/opendatalab/OmniDocBench)
|
||||
- [Donut](https://github.com/clovaai/donut/)
|
||||
- [Nougat](https://github.com/facebookresearch/nougat)
|
||||
- [GOT](https://github.com/Ucas-HaoranWei/GOT-OCR2.0)
|
||||
- [MinerU](https://github.com/opendatalab/MinerU/tree/master)
|
||||
- [Swin](https://github.com/microsoft/Swin-Transformer)
|
||||
- [Hugging Face Transformers](https://github.com/huggingface/transformers)
|
||||
|
||||
|
||||
## 📝 引用
|
||||
|
||||
如果您在研究中发现此代码有用,请使用以下BibTeX条目。
|
||||
|
||||
```bibtex
|
||||
@article{feng2025dolphin,
|
||||
title={Dolphin: Document Image Parsing via Heterogeneous Anchor Prompting},
|
||||
author={Feng, Hao and Wei, Shu and Fei, Xiang and Shi, Wei and Han, Yingdong and Liao, Lei and Lu, Jinghui and Wu, Binghong and Liu, Qi and Lin, Chunhui and others},
|
||||
journal={arXiv preprint arXiv:2505.14059},
|
||||
year={2025}
|
||||
}
|
||||
```
|
||||
|
||||
## 星标历史
|
||||
|
||||
[](https://www.star-history.com/#bytedance/Dolphin&Date)
|
||||
|
After Width: | Height: | Size: 3.1 MiB |
|
After Width: | Height: | Size: 81 KiB |
|
After Width: | Height: | Size: 9.4 MiB |
|
After Width: | Height: | Size: 90 KiB |
|
After Width: | Height: | Size: 383 KiB |
|
After Width: | Height: | Size: 54 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 82 KiB |
|
After Width: | Height: | Size: 167 KiB |
|
After Width: | Height: | Size: 920 KiB |
|
After Width: | Height: | Size: 207 KiB |
|
After Width: | Height: | Size: 1.4 MiB |
|
After Width: | Height: | Size: 439 KiB |
|
After Width: | Height: | Size: 363 KiB |
|
After Width: | Height: | Size: 626 KiB |
|
After Width: | Height: | Size: 93 KiB |