Skip to content

Repository files navigation

Hiro-OCSR

Hiro-OCSR is an optical chemical structure recognition project for converting chemical structure images into machine-readable SMILES. It is designed for robust recognition of real-world chemistry figures, including complex structures found in biochemical patent images.

This repository contains the local inference SDK and chemical post-processing implementation. Model weights are hosted separately on Hugging Face and are downloaded when local inference is first used.

Highlights

  • Local image-to-SMILES inference with a stable Python API.
  • File path, PIL image, binary data, and Base64 image inputs.
  • Single-image and batch inference.
  • Local post-processing for abbreviations, R-groups, variable attachments, abstract rings, and repeat units.
  • RDKit-based structure validation, depiction, and classification.
  • Real-world chemistry figure recognition for patent-style and biochemical structures.
  • Real-world 24k dataset hosted on Hugging Face.

Hosted API available for trial

Hiro-OCSR is also available through hosted APIs for evaluation and feedback:

Installation

Install the local chemistry utilities:

pip install -e .

Install the model inference dependencies:

pip install -e ".[inference]"

Optional API dependencies are reserved for service integrations:

pip install -e ".[api]"

Model availability

The current model weights are hosted at PatSnap/Hiro-OCSR. They are not duplicated or tracked in this Git repository. By default, Transformers downloads and caches the weights from Hugging Face when HiroOCSR is first initialized.

The released weights are an early-training Qwen3-VL-8B checkpoint intended for evaluation and continued improvement. It should not be treated as a final or fully validated OCSR model. Model revisions may change recognition quality and output behavior.

The source code and model weights are separate artifacts. Review the license and usage terms attached to each artifact before use or redistribution. See models/README.md for model download and loading details.

Benchmark

The table below summarizes results for Hiro-OCSR, MolScribe, and DECIMER on four classic subsets of the OCSR Benchmarks. Hiro-OCSR uses InChIKey accuracy: predicted and reference structures are converted to InChIKeys and matched exactly. MolScribe and DECIMER use canonical SMILES Exact Match as reported in Table 2 of the original MolScribe paper: predictions and references are converted to canonical SMILES before exact matching. Tetrahedral chirality is included, while other forms of stereoisomerism that are generally unavailable in the ground truth are ignored.

Model Metric JPO CLEF USPTO UOB Result source
Hiro-OCSR InChIKey accuracy 85.7% 91.2% 92.7% 97.5% Internal Hiro-OCSR evaluation
MolScribe Canonical SMILES Exact Match 76.2% 88.9% 92.6% 87.9% MolScribe paper, Table 2
DECIMER v2.1.0 Canonical SMILES Exact Match 55.2% 62.7% 41.1% 88.2% MolScribe paper, Table 2

The OCSR Benchmarks are a collection of public datasets rather than a single test set; the table uses the classic JPO, CLEF, USPTO, and UOB subsets. Hiro-OCSR results come from an internal evaluation based on InChIKey exact matching. Both the MolScribe and DECIMER v2.1.0 results come from Table 2 of the same MolScribe paper, avoiding a mixture of evaluation protocols from different publications.

Metric note: InChIKey accuracy for Hiro-OCSR and canonical SMILES Exact Match for the other two models are not fully equivalent. These results provide an overall reference rather than a strict like-for-like ranking. A rigorous comparison requires rerunning all models with the same structure-normalization pipeline and evaluation script.

Usage

Local inference uses the Hugging Face model by default:

from hiro_ocsr import HiroOCSR

model = HiroOCSR()
result = model.run({
    "image": "path/to/chemical-structure.png",
    "depict": False,
})

print(result[0]["SMILES"])

Batch inference accepts a list of images:

results = model.predict([
    "path/to/structure-1.png",
    "path/to/structure-2.png",
])

To use an already downloaded checkpoint:

model = HiroOCSR(model_path="/path/to/Hiro-OCSR-model")

Set debug=True to include the internal SMILES_expanded field, or depict=True to include a Base64-encoded PNG depiction:

result = model.run({
    "image": "path/to/chemical-structure.png",
    "debug": True,
    "depict": True,
})

SMILES depiction and local post-processing do not require model weights:

model = HiroOCSR(load=False)
print(model.run({"SMILES": "CCO"}))

The example script also uses the Hugging Face model by default:

python examples/predict.py path/to/chemical-structure.png

Data

The real-world 24k dataset is hosted on Hugging Face:

https://huggingface.co/datasets/PatSnap/hiro-ocsr-real-24k

The datasets/ directory documents dataset access only. Dataset files, raw figures, generated corpora, and local experiments should not be committed.

Development

pip install -e ".[inference,dev]"
ruff check .
pytest

License and Disclaimer

The source code in this repository is licensed under the Apache License 2.0. See the Copyright Notice for copyright and trademark information. Model weights, datasets, hosted APIs, and related artifacts may carry their own terms.

Hiro-OCSR outputs may be inaccurate or chemically invalid and must be reviewed and validated by qualified users before being relied upon. Users are responsible for ensuring they have the necessary rights to process input materials and for complying with applicable licenses, laws, and regulations. See the full disclaimer before using this project.

About

Hiro-OCSR is a high-accuracy optical chemical structure recognition system built for robust generalization on real-world data, with particular strength in extracting complex chemical structures from biochemical patent images.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages