Upload model card
Browse files12345678910---tags:- model_hub_mixin- pytorch_model_hub_mixin---This model has been pushed to the Hub using the [PytorchModelHubMixin](https://huggingface.co/docs/huggingface_hub/package_reference/mixins#huggingface_hub.PyTorchModelHubMixin) integration:- Code: https://github.com/netknowledge/COMO- Paper: https://arxiv.org/abs/2604.23546- Docs: https://github.com/netknowledge/COMO/tree/main/doc123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170---library_name: pytorchlicense: cc-by-nc-4.0metrics:- accuracypipeline_tag: image-to-texttags:- OCSR---# COMO[Demo](https://huggingface.co/spaces/lyuzhuoqi/COMO) \\(\cdot\\) [GitHub](https://github.com/netknowledge/COMO) \\(\cdot\\) [PyPI](https://pypi.org/project/como-ocsr/)**COMO** (**C**losed-loop **O**ptical **M**olecule rec**O**gnition) is a deep learning framework forOptical Chemical Structure Recognition (OCSR). It recognizes chemical structurediagrams from images and predicts SMILES strings with atom-level 2D coordinatesand bond matrices. COMO uses Minimum Risk Training (MRT) to directly optimizemolecular-level, non-differentiable objectives, closing the gap betweentoken-level training and molecular-level evaluation.## Model Summary- **Architecture:** Swin-B encoder β 6-layer Transformer decoder β bond MLP- **Input:** 384Γ384 RGB image of a chemical structure diagram- **Output:** SMILES string + atom coordinates + bond matrix- **Vocabulary:** chartok_coords format (200 tokens: SMILES chars + 64 X/Y bins)- **Parameters:** ~94M- **Training data:** [1M PubChem](https://huggingface.co/Keylab/COMO/tree/main/training_data/pubchem_smiles) + [652K USPTO](https://huggingface.co/Keylab/COMO/blob/main/training_data/uspto_mol.zip) (MLE) + [83K MolParser-SFT](https://huggingface.co/Keylab/COMO/blob/main/training_data/molparser_sft_real.tar.gz) (MRT)## Installation```bashpip install como-ocsr```## Usage```pythonimport como# Load pretrained checkpoints from Hugging Facemodel = como.load_model("Keylab/COMO-Tanimoto")# or download checkpoint files from HuggingFace:# huggingface-cli download Keylab/COMO models/tanimoto/final.pthmodel = como.load_model(checkpint_path="models/tanimoto/final.pth")# Single image predictionsmiles = como.predict(model, "molecule.png")print(smiles) # "CC(=O)O"# Batch predictionsmiles_list = como.predict_batch(model, ["mol1.png", "mol2.png"])# Benchmark evaluationmetrics = como.evaluate(model, "benchmark/USPTO/", "benchmark/USPTO.csv")print(f"Exact Match: {metrics['postprocess/exact_match_acc']:.2%}")```Full documentation: Github (**[netknowledge/COMO](https://github.com/netknowledge/COMO/tree/main/doc)**)## Architecture```Image (384Γ384)β Swin-B backbone (ImageNet pretrained)β 2D sinusoidal positional encodingβ 6-layer Transformer decoder (d=256, 8 heads)β chartok_coords tokens β SMILES + coordinatesβ Bond MLP (2-layer, GELU) β 7-class bond matrixβ Graph reconstruction β canonical SMILES```The model outputs a molecular graph \\(G = (A, B)\\) where:- \\(A = \{(l_i, x_i, y_i)\}\\) β atom SMILES labels with 2D image coordinates- \\(B\\) β pairwise bond types (none, single, double, triple, aromatic, wedge, dash)## Training### MLE Phase- **Data:** 1M PubChem SMILES (synthetic) + 652K USPTO patent molecules- **Augmentation:** Indigo-rendered images with random styles, functional groupsubstitution, R-group insertion, wavy bonds, scan shadows, multilingual comments- **Optimizer:** AdamW, lr=4Γ10β»β΄ (encoder & decoder), weight decay=10β»βΆ- **Schedule:** 2% linear warmup β cosine decay, batch size 64/GPU- **Loss:** Label-smoothed cross-entropy (Ξ΅=0.1) + bond classification CE### MRT Phase- **Data:** 83K real-world molecular images (MolParser-SFT)- **Candidates:** N=32 per image, multinomial sampling at Ο=0.5- **Reward weights:** validity=0.1, similarity=0.5, exact match=0.4- **Sharpening:** Ξ±=1.0, loss weight Ξ»=0.1- **Schedule:** First 5 epochs MLE-only warmup, then interleaved MLE+MRT## Benchmark DatasetsBenchmark datasets are published as a HuggingFace Dataset with one config per benchmark:**[Keylab/OCSR-Benchmarks](https://huggingface.co/datasets/Keylab/OCSR-Benchmarks)**| Config | Size | Type ||--------|-----:|------|| `CLEF` | 992 | Real (patents) || `JPO` | 449 | Real (patents) || `UOB` | 5,740 | Real (academic) || `USPTO` | 5,719 | Real (patents) || `USPTO-10K` | 9,999 | Real (patents) || `Staker` | 50,000 | Real || `ACS` | 331 | Real (publications) || `WildMol-10K` | 9,889 | Real (wild) || `Indigo` | 5,719 | Synthetic || `ChemDraw` | 5,719 | Synthetic |Each sample has three fields: `image_id` (str), `image` (PIL), `SMILES` (str).```pythonfrom datasets import load_dataset# Load a single benchmarkds = load_dataset("Keylab/OCSR-Benchmarks", name="USPTO", split="test")sample = ds[0]sample["image"].show() # PIL Imageprint(sample["SMILES"]) # ground-truth SMILES# Iterate over all benchmarksconfigs = ["CLEF", "JPO", "UOB", "USPTO", "USPTO-10K","Staker", "ACS", "WildMol-10K", "Indigo", "ChemDraw"]for name in configs:ds = load_dataset("Keylab/OCSR-Benchmarks", name=name, split="test")print(f"{name}: {len(ds)} samples")```Pre-packaged `.tar.gz` archives are also available for bulk download in the**[Keylab/COMO](https://huggingface.co/Keylab/COMO/tree/main/benchmarks)**.## Evaluation ResultsExact match accuracy (%) on 10 benchmarks (COMO-Tanimoto variant):| Benchmark | Images | Synthetic/Real | COMO-Tanimoto ||-----------|--------|----------------|---------------|| Indigo | 5,719 | Synthetic | 98.6 || ChemDraw | 5,719 | Synthetic | 96.5 || CLEF | 992 | Real (patents) | 94.8 || JPO | 449 | Real (patents) | 88.4 || UOB | 5,740 | Real (academic) | 98.0* || USPTO | 5,719 | Real (patents) | 93.4 || USPTO-10K | 9,999 | Real (patents) | 96.1 || Staker | 50,000 | Real | 87.3 || ACS | 331 | Real (publications) | 84.6 || WildMol-10K | 9,899 | Real (wild) | 77.1 |*\*UOB results after tautomer standardization.*See the [paper](https://arxiv.org/abs/2604.23546) for full comparison with MolScribe, MolParser,SwinOCSR, and other baselines.## License- **Code & Model Weights:** CC BY-NC 4.0 (non-commercial use only)- **Benchmarks:** See original sources for applicable terms## Citation```bibtex@article{lyu2026closed,title={COMO: Closed-Loop Optical Molecule Recognition with Minimum Risk Training},author={Lyu, Zhuoqi and Ke, Qing},journal={arXiv preprint arXiv:2604.23546},year={2026}}```
README.md+166-6