---
title: MolGen-large
canonical_url: "https://www.modelscope.cn/models/AI-ModelScope/MolGen-large"
md_url: "https://www.modelscope.cn/models/AI-ModelScope/MolGen-large.md"
repository: AI-ModelScope/MolGen-large
last_updated: 2023-10-20
pipeline_tag: text-generation
tasks:
  - text-generation
model_type:
  - bart
architectures:
  - BartForConditionalGeneration
library_name:
  - pytorch
frameworks:
  - pytorch
inference_backends:
  - "deploy_task text/emb"
  - "vllm 0.9.2"
downloads: 36
stars: 0
tags:
  - "molecular language model"
  - SELFIES
  - "molecule generation"
---

# MolGen-large

> MolGen-large - AI-ModelScope 在 ModelScope 开源的模型。MolGen-large MolGen-large was introduced in the paper "Domain-Agnostic Molecular Generation with Self-feedback" and first released in this repository. It is a pre-trained molecular generative model built using…

AI-ModelScope/MolGen-large 是 ModelScope 魔搭社区上的text-generation模型，可用 deploy_task text/emb、vllm 0.9.2 部署。

- **Repository**: AI-ModelScope/MolGen-large
- **Tasks**: text-generation
- **Inference backends**: deploy_task text/emb, vllm 0.9.2
- **Tags**: molecular language model, SELFIES, molecule generation
- **Downloads**: 36
- **Stars**: 0
- **Last updated**: 2023-10-20

Source: https://www.modelscope.cn/models/AI-ModelScope/MolGen-large

---

# MolGen-large
MolGen-large was introduced in the paper ["Domain-Agnostic Molecular Generation with Self-feedback"](https://arxiv.org/pdf/2301.11259.pdf) and first released in [this repository](https://github.com/zjunlp/MolGen). It is a pre-trained molecular generative model built using the 100\% robust molecular language representation, SELFIES.

## Model description
MolGen-large is the first pre-trained model that only produces chemically valid molecules. 
With a training corpus of over 100 million molecules in SELFIES representation, MolGen-large learns the intrinsic structural patterns of molecules by mapping corrupted SELFIES to their original forms.
Specifically, MolGen-large employs a bidirectional Transformer as its encoder and an autoregressive Transformer as its decoder.
Through its carefully designed multi-task molecular prefix tuning (MPT), MolGen-large can generate molecules with desired properties, making it a valuable tool for molecular optimization.

![image.png](./model.png)

## Intended uses
You can use the raw model for molecule generation or fine-tune it to a downstream task. Please take note that the following examples only demonstrate the utilization of our pre-trained model for molecule generation. See the [repository](https://github.com/zjunlp/MolGen) to look for fine-tune details on a task that interests you.

### How to use
Molecule generation example:
```python
from modelscope import AutoTokenizer, AutoModelForSeq2SeqLM
tokenizer = AutoTokenizer.from_pretrained("AI-ModelScope/MolGen-large")
model = AutoModelForSeq2SeqLM.from_pretrained("AI-ModelScope/MolGen-large")

sf_input = tokenizer("[C][=C][C][=C][C][=C][Ring1][=Branch1]", return_tensors="pt")
# beam search
molecules = model.generate(input_ids=sf_input["input_ids"],
                              attention_mask=sf_input["attention_mask"],
                              max_length=15,
                              min_length=5,
                              num_return_sequences=5,
                              num_beams=5)
sf_output = [tokenizer.decode(g, skip_special_tokens=True, clean_up_tokenization_spaces=True).replace(" ","") for g in molecules]
['[C][=C][C][=C][C][=C][Ring1][=Branch1]',
'[C][=C][C][=C][C][=C][C][=C][Ring1][=Branch1]',
'[C][=C][C][=C][C][=C][Ring1][=Branch1][C][=C][C][=C]',
'[C][=C][C][=C][C][=C][Ring1][=Branch1][C@H1][C][=C][C]',
'[C][=C][C][=C][C][=C][Ring1][=Branch1][C@H1][=C][C][=C]']
```


### BibTeX entry and citation info
```bibtex
@article{fang2023molecular,
  title={Molecular Language Model as Multi-task Generator},
  author={Fang, Yin and Zhang, Ningyu and Chen, Zhuo and Fan, Xiaohui and Chen, Huajun},
  journal={arXiv preprint arXiv:2301.11259},
  year={2023}
}
```
