安装 SmolDocling 需遵循以下步骤:
- environmental preparation:确保已安装 Python 3.8+,建议使用虚拟环境
- Installation of dependencies: Execute command
pip install torch transformers docling_core
- GPU acceleration(可选):安装 CUDA 版 PyTorch 以提升速度,可通过
torch.cuda.is_available()
检测支持情况
使用流程分为五个阶段:
- 图片加载: Use
load_image()
函数导入待处理图片 - 模型初始化:通过 Hugging Face 自动下载模型权重(需首次联网)
- Document Conversion:使用特定 prompt 模板生成 DocTags
- format conversion:可将 DocTags 输出为 Markdown 等常用格式
- Advanced Optimization:GPU 用户可启用 flash_attention_2 加速处理
注意处理大图片时可能需调整 max_new_tokens
参数(默认 8192),建议首次使用时打印中间结果进行调试。
This answer comes from the articleSmolDocling: a visual language model for efficient document processing in a small volumeThe