Image-Text-to-Text
Transformers
Safetensors
English
qwen2_5_vl
chemistry
multimodal
reasoning
vision-language
grpo
smiles
iupac
spectroscopy
conversational
text-generation-inference
Instructions to use zzha6204/CheMM-R1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use zzha6204/CheMM-R1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="zzha6204/CheMM-R1") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("zzha6204/CheMM-R1") model = AutoModelForMultimodalLM.from_pretrained("zzha6204/CheMM-R1", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use zzha6204/CheMM-R1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "zzha6204/CheMM-R1" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "zzha6204/CheMM-R1", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/zzha6204/CheMM-R1
- SGLang
How to use zzha6204/CheMM-R1 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "zzha6204/CheMM-R1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "zzha6204/CheMM-R1", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "zzha6204/CheMM-R1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "zzha6204/CheMM-R1", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use zzha6204/CheMM-R1 with Docker Model Runner:
docker model run hf.co/zzha6204/CheMM-R1
Add model card
Browse files
README.md
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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13 |
+
- smiles
|
| 14 |
+
- iupac
|
| 15 |
+
- spectroscopy
|
| 16 |
+
language:
|
| 17 |
+
- en
|
| 18 |
+
---
|
| 19 |
+
|
| 20 |
+
# CheMM-R1
|
| 21 |
+
|
| 22 |
+
CheMM-R1 is a chemistry-specific multimodal large language model (MLLM) for molecular structure recognition and spectral elucidation. It is built on top of **Qwen2.5-VL-3B-Instruct** and trained with **CheMMGRPO** — a domain-adapted Group Relative Policy Optimisation pipeline that combines a chemistry cold-start SFT stage with reinforcement learning driven by chemistry-specific reward functions.
|
| 23 |
+
|
| 24 |
+
The model is introduced in the paper *"CheMM-R1: Enhancing Chemical Structure Recognition and Elucidation with Reasoning Multimodal Large Language Models"*.
|
| 25 |
+
|
| 26 |
+
- Code & benchmark: https://github.com/ZhihaoZhang97/CheMM-R1
|
| 27 |
+
|
| 28 |
+
## Capabilities
|
| 29 |
+
|
| 30 |
+
CheMM-R1 is designed for the following tasks:
|
| 31 |
+
|
| 32 |
+
- **SmilesQA** — predict the SMILES string of a molecule from its 2D structure image.
|
| 33 |
+
- **IupacQA** — predict the IUPAC name of a molecule from its 2D structure image.
|
| 34 |
+
- **MwQA** — predict the molecular weight of a molecule from its 2D structure image.
|
| 35 |
+
- **SpectraQA** — predict the SMILES of a molecule from its spectral images (IR, ¹H-NMR, ¹³C-NMR, positive-ion MS, negative-ion MS).
|
| 36 |
+
|
| 37 |
+
The model produces explicit step-by-step reasoning in `<think>` tags, intermediate SMILES in `<smiles>` tags, and the final answer in `<answer>` tags.
|
| 38 |
+
|
| 39 |
+
## Method
|
| 40 |
+
|
| 41 |
+
### Base model
|
| 42 |
+
|
| 43 |
+
- Architecture: `Qwen2_5_VLForConditionalGeneration` (Qwen2.5-VL-3B-Instruct)
|
| 44 |
+
- Precision: bfloat16
|
| 45 |
+
- Context length: up to 128K tokens, trained with max sequence length 20,480 (cold-start) and output length 5,120 (RL)
|
| 46 |
+
|
| 47 |
+
### Training pipeline (CheMMGRPO)
|
| 48 |
+
|
| 49 |
+
1. **Cold start (SFT)** — the base model is fine-tuned on 40,000 chemistry QA instances from CheMM-Bench with multimodal Chain-of-Thought reasoning distilled from Gemini-2.5-Pro, to inject organic chemistry knowledge and reasoning patterns.
|
| 50 |
+
2. **Reinforcement learning (GRPO)** — the cold-started model is further optimised with GRPO using four chemistry-specific reward functions:
|
| 51 |
+
- `smiles_acc` — chemical validity of generated SMILES
|
| 52 |
+
- `atom_acc`, `func_group_acc` — structural accuracy
|
| 53 |
+
- `output_format` — format compliance with `<think>/<smiles>/<answer>` tags
|
| 54 |
+
- `answer_acc` — factual correctness via Levenshtein-based fuzzy match for textual answers (SMILES, IUPAC) and ±0.05 g/mol tolerance for molecular weights
|
| 55 |
+
|
| 56 |
+
### Key hyperparameters
|
| 57 |
+
|
| 58 |
+
- Framework: MS-SWIFT
|
| 59 |
+
- Cold start: lr 1e-4, Adam (β1=0.9, β2=0.95, ε=1e-8), batch size 64, max model length 20,480, max image pixels 262,144
|
| 60 |
+
- RL (GRPO): 4 rollouts per question, sampling temperature 1.0, lr 1e-4, KL coefficient β=0.001, batch size 48, max output length 5,120
|
| 61 |
+
- Hardware: 8× H200 (141 GB) GPUs, ~12 hours total training
|
| 62 |
+
|
| 63 |
+
## Dataset: CheMM-Bench
|
| 64 |
+
|
| 65 |
+
CheMM-R1 is trained and evaluated on **CheMM-Bench**, a multimodal chemistry reasoning benchmark with 48,500 long Chain-of-Thought reasoning steps across four tasks:
|
| 66 |
+
|
| 67 |
+
- 26,500 molecules for structure recognition (SmilesQA / IupacQA / MwQA)
|
| 68 |
+
- 22,000 molecules for structure elucidation (SpectraQA) with five spectral image types (IR, ¹H-NMR, ¹³C-NMR, +ion MS, −ion MS)
|
| 69 |
+
|
| 70 |
+
Molecules are derived from the Alberts spectroscopic dataset (USPTO reaction database). SMILES → 2D structure conversion is performed with RDKit; IUPAC names are sourced from PubChem.
|
| 71 |
+
|
| 72 |
+
## Results
|
| 73 |
+
|
| 74 |
+
Averaged accuracy / F1 on CheMM-Bench (CheMM-R1 vs. strongest baselines):
|
| 75 |
+
|
| 76 |
+
| Model | SR Avg ACC | SR Avg F1 | SpectraQA ACC | SpectraQA F1 | Overall ACC | Overall F1 |
|
| 77 |
+
|--------------------|-----------:|----------:|--------------:|-------------:|------------:|-----------:|
|
| 78 |
+
| GPT-o3 | 5.78 | 10.94 | 1.50 | 2.96 | 3.34 | 6.46 |
|
| 79 |
+
| Gemini-2.5-Pro | 16.13 | 27.78 | 1.80 | 3.54 | 7.95 | 14.72 |
|
| 80 |
+
| Claude-Sonnet-4 | 1.99 | 3.91 | 1.60 | 3.15 | 1.77 | 3.48 |
|
| 81 |
+
| Grok-4 | 2.79 | 5.43 | 4.05 | 7.78 | 3.51 | 6.78 |
|
| 82 |
+
| Gemini-2.5-Flash | 8.58 | 15.80 | 1.10 | 2.18 | 4.31 | 8.26 |
|
| 83 |
+
| **CheMM-R1 (3B)** | **23.73** | **38.35** | **36.32** | **53.28** | **30.92** | **47.23** |
|
| 84 |
+
|
| 85 |
+
Tanimoto@1.0 structural match on SmilesQA / SpectraQA:
|
| 86 |
+
|
| 87 |
+
| Model | SmilesQA | SpectraQA |
|
| 88 |
+
|--------------------|---------:|----------:|
|
| 89 |
+
| Gemini-2.5-Pro | 44.52 | 11.46 |
|
| 90 |
+
| Grok-4 | 2.18 | 18.28 |
|
| 91 |
+
| ChemVLM-8B | 31.99 | — |
|
| 92 |
+
| **CheMM-R1 (3B)** | **60.00**| **56.57** |
|
| 93 |
+
|
| 94 |
+
See the paper for full tables including BLEU-1 and Levenshtein-distance similarity and ablations on cold-start vs. GRPO vs. CheMMGRPO.
|
| 95 |
+
|
| 96 |
+
## Usage
|
| 97 |
+
|
| 98 |
+
```python
|
| 99 |
+
from transformers import AutoProcessor, Qwen2_5_VLForConditionalGeneration
|
| 100 |
+
from PIL import Image
|
| 101 |
+
import torch
|
| 102 |
+
|
| 103 |
+
model_id = "zzha6204/CheMM-R1"
|
| 104 |
+
|
| 105 |
+
processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
|
| 106 |
+
model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
|
| 107 |
+
model_id,
|
| 108 |
+
torch_dtype=torch.bfloat16,
|
| 109 |
+
device_map="auto",
|
| 110 |
+
trust_remote_code=True,
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
image = Image.open("molecule.png")
|
| 114 |
+
messages = [
|
| 115 |
+
{
|
| 116 |
+
"role": "user",
|
| 117 |
+
"content": [
|
| 118 |
+
{"type": "image", "image": image},
|
| 119 |
+
{"type": "text", "text": "What is the SMILES representation of this molecule?"},
|
| 120 |
+
],
|
| 121 |
+
}
|
| 122 |
+
]
|
| 123 |
+
|
| 124 |
+
text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 125 |
+
inputs = processor(text=[text], images=[image], return_tensors="pt").to(model.device)
|
| 126 |
+
|
| 127 |
+
output_ids = model.generate(**inputs, max_new_tokens=2048)
|
| 128 |
+
response = processor.batch_decode(
|
| 129 |
+
output_ids[:, inputs.input_ids.shape[1]:], skip_special_tokens=True
|
| 130 |
+
)[0]
|
| 131 |
+
print(response)
|
| 132 |
+
```
|
| 133 |
+
|
| 134 |
+
For SpectraQA, pass all available spectral images (IR, ¹H-NMR, ¹³C-NMR, +ion MS, −ion MS) as a multi-image message.
|
| 135 |
+
|
| 136 |
+
## Output format
|
| 137 |
+
|
| 138 |
+
CheMM-R1 is trained to produce:
|
| 139 |
+
|
| 140 |
+
```
|
| 141 |
+
<think> step-by-step chemical reasoning </think>
|
| 142 |
+
<smiles> intermediate SMILES </smiles>
|
| 143 |
+
<answer> final answer </answer>
|
| 144 |
+
```
|
| 145 |
+
|
| 146 |
+
Downstream parsers should extract the content of `<answer>` as the final prediction.
|
| 147 |
+
|
| 148 |
+
## Intended use and limitations
|
| 149 |
+
|
| 150 |
+
- Intended for **research on multimodal chemistry reasoning**: molecular structure recognition and spectral elucidation of small organic molecules.
|
| 151 |
+
- Molecules are drawn from the USPTO-derived Alberts dataset; out-of-distribution performance on larger natural products, organometallics, or experimentally noisy real-world spectra is not guaranteed.
|
| 152 |
+
- Outputs — including SMILES, IUPAC names, molecular weights, and reasoning traces — may be incorrect and **must not be used for safety-critical decisions in chemistry or medicinal research** without expert verification.
|
| 153 |
+
- The model is derived from Qwen2.5-VL-3B-Instruct and inherits its license and any biases of the base model and distilled reasoning data (Gemini-2.5-Pro).
|
| 154 |
+
|
| 155 |
+
## Citation
|
| 156 |
+
|
| 157 |
+
If you use CheMM-R1 or CheMM-Bench in your research, please cite:
|
| 158 |
+
|
| 159 |
+
```bibtex
|
| 160 |
+
@inproceedings{huang2025chemmr1,
|
| 161 |
+
title = {CheMM-R1: Enhancing Chemical Structure Recognition and Elucidation with Reasoning Multimodal Large Language Models},
|
| 162 |
+
author = {Huang, Liting and Zhang, Zhihao and Wang, Shoujin},
|
| 163 |
+
year = {2025}
|
| 164 |
+
}
|
| 165 |
+
```
|
| 166 |
+
|
| 167 |
+
## Acknowledgements
|
| 168 |
+
|
| 169 |
+
- Base model: [Qwen2.5-VL-3B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-3B-Instruct)
|
| 170 |
+
- Training framework: [MS-SWIFT](https://github.com/modelscope/ms-swift)
|
| 171 |
+
- Spectroscopic data: Alberts et al. (USPTO-derived), PubChem, RDKit
|