Image-to-Text
Transformers
PyTorch
English
udop
text-generation
chemistry
markush
cxsmiles
molecular-structure
ocr
document-understanding
vision-language-model
patent-analysis
Instructions to use docling-project/MarkushGrapher-2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use docling-project/MarkushGrapher-2 with Transformers:
# Use a pipeline as a high-level helper # Warning: Pipeline type "image-to-text" is no longer supported in transformers v5. # You must load the model directly (see below) or downgrade to v4.x with: # pip install "transformers<5.0.0" from transformers import pipeline pipe = pipeline("image-to-text", model="docling-project/MarkushGrapher-2")# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForSeq2SeqLM processor = AutoProcessor.from_pretrained("docling-project/MarkushGrapher-2") model = AutoModelForSeq2SeqLM.from_pretrained("docling-project/MarkushGrapher-2", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
tags:
|
| 6 |
+
- chemistry
|
| 7 |
+
- markush
|
| 8 |
+
- cxsmiles
|
| 9 |
+
- molecular-structure
|
| 10 |
+
- ocr
|
| 11 |
+
- document-understanding
|
| 12 |
+
- image-to-text
|
| 13 |
+
- vision-language-model
|
| 14 |
+
- patent-analysis
|
| 15 |
+
library_name: transformers
|
| 16 |
+
pipeline_tag: image-to-text
|
| 17 |
+
datasets:
|
| 18 |
+
- docling-project/MarkushGrapher-2-Datasets
|
| 19 |
+
---
|
| 20 |
+
|
| 21 |
+
<p align="center">
|
| 22 |
+
<img src="markushgrapher_2_repo_banner.png" alt="MarkushGrapher-2 Banner" width="100%">
|
| 23 |
+
</p>
|
| 24 |
+
|
| 25 |
+
# MarkushGrapher-2
|
| 26 |
+
|
| 27 |
+
**MarkushGrapher-2** is an end-to-end multimodal model for recognizing chemical structures from patent document images. It jointly encodes vision, text, and layout information to convert Markush structure images into machine-readable CXSMILES representations.
|
| 28 |
+
|
| 29 |
+
## Overview
|
| 30 |
+
|
| 31 |
+
MarkushGrapher-2 is a transformer-based model that integrates two complementary encoders:
|
| 32 |
+
- A **Vision Encoder** (Swin-B ViT), pretrained for Optical Chemical Structure Recognition (OCSR)
|
| 33 |
+
- A **Vision-Text-Layout (VTL) Encoder** (T5-base), trained for Markush feature extraction
|
| 34 |
+
|
| 35 |
+
The model also includes **ChemicalOCR**, a dedicated OCR module fine-tuned for chemical images, enabling fully end-to-end processing without external OCR dependencies.
|
| 36 |
+
|
| 37 |
+
### Architecture
|
| 38 |
+
|
| 39 |
+
The input image is processed through two parallel pipelines:
|
| 40 |
+
1. **Vision pipeline**: The image is encoded by the OCSR vision encoder and projected via an MLP.
|
| 41 |
+
2. **VTL pipeline**: The image is passed through ChemicalOCR to extract text and bounding boxes, which are then fused with image patches in the VTL encoder.
|
| 42 |
+
|
| 43 |
+
The outputs of both pipelines are concatenated and fed to a text decoder that autoregressively generates a CXSMILES sequence describing the Markush backbone and a substituent table.
|
| 44 |
+
|
| 45 |
+
### Two-Stage Training Strategy
|
| 46 |
+
|
| 47 |
+
- **Phase 1 (Adaptation)**: The Vision Encoder is frozen while the projector and text decoder are trained on 243K real-world image-SMILES pairs for standard molecular structure recognition.
|
| 48 |
+
- **Phase 2 (Fusion)**: The VTL encoder is introduced and trained jointly with the text decoder on 235K synthetic and 145K real-world Markush structure samples for CXSMILES and substituent table prediction.
|
| 49 |
+
|
| 50 |
+
## Performance
|
| 51 |
+
|
| 52 |
+
### Markush Structure Recognition (CXSMILES Accuracy)
|
| 53 |
+
|
| 54 |
+
| Benchmark | MarkushGrapher-2 | MolParser-Base | MolScribe | MarkushGrapher-1 | DeepSeek-OCR | GPT-5 |
|
| 55 |
+
|---|---|---|---|---|---|---|
|
| 56 |
+
| **M2S** (103) | **56** | 39 | 21 | 38 | 0 | 3 |
|
| 57 |
+
| **USPTO-M** (74) | **55** | 30 | 7 | 32 | 0 | - |
|
| 58 |
+
| **WildMol-M** (10K) | **48.0** | 38.1 | 28.1 | - | 1.9 | - |
|
| 59 |
+
| **IP5-M** (1K) | **53.7** | 47.7 | 22.3 | - | 0.0 | - |
|
| 60 |
+
|
| 61 |
+
### Molecular Structure Recognition (SMILES Accuracy)
|
| 62 |
+
|
| 63 |
+
| Benchmark | MarkushGrapher-2 | MolParser-Base | MolScribe | MolGrapher |
|
| 64 |
+
|---|---|---|---|---|
|
| 65 |
+
| **WildMol** (10K) | 68.4 | **76.9** | 66.4 | 45.5 |
|
| 66 |
+
| **JPO** (450) | 71.0 | **78.9** | 76.2 | 67.5 |
|
| 67 |
+
| **UOB** (5.7K) | **96.6** | 91.8 | 87.4 | 94.9 |
|
| 68 |
+
| **USPTO** (5.7K) | 89.8 | 93.0 | **93.1** | 91.5 |
|
| 69 |
+
|
| 70 |
+
## Model Details
|
| 71 |
+
|
| 72 |
+
- **Parameters**: 831M total (744M trainable)
|
| 73 |
+
- **Vision Encoder**: Swin-B ViT (from MolScribe, frozen during Phase 2)
|
| 74 |
+
- **VTL Encoder/Decoder**: T5-base architecture with UDOP fusion
|
| 75 |
+
- **OCR Module**: ChemicalOCR (256M parameters, based on SmolDocling)
|
| 76 |
+
- **Input**: Patent document image crop (1024x1024)
|
| 77 |
+
- **Output**: CXSMILES sequence + substituent table
|
| 78 |
+
|
| 79 |
+
## Usage
|
| 80 |
+
|
| 81 |
+
```python
|
| 82 |
+
# Load the model checkpoint
|
| 83 |
+
from transformers import AutoModel
|
| 84 |
+
|
| 85 |
+
model = AutoModel.from_pretrained("docling-project/markushgrapher-2-checkpoint")
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
For full inference pipeline usage, see the [MarkushGrapher-IBM repository](https://github.ibm.com/DeepSearch/MarkushGrapher-IBM).
|
| 89 |
+
|
| 90 |
+
## Datasets
|
| 91 |
+
|
| 92 |
+
Training and evaluation datasets are available at [docling-project/MarkushGrapher-2-Datasets](https://huggingface.co/datasets/docling-project/MarkushGrapher-2-Datasets).
|
| 93 |
+
|
| 94 |
+
## Citation
|
| 95 |
+
|
| 96 |
+
```bibtex
|
| 97 |
+
@inproceedings{strohmeyer2025markushgrapher2,
|
| 98 |
+
title={MarkushGrapher-2: End-to-end Multimodal Recognition of Chemical Structures},
|
| 99 |
+
author={Strohmeyer, Tim},
|
| 100 |
+
booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
|
| 101 |
+
year={2026}
|
| 102 |
+
}
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
## License
|
| 106 |
+
|
| 107 |
+
This model is released under the [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0).
|