File size: 4,066 Bytes
0fd57f3 137d72a 0fd57f3 5f7be17 5689fa8 5f7be17 5689fa8 5f7be17 5689fa8 5f7be17 df8b64e 5f7be17 df8b64e 5f7be17 d11ff99 5689fa8 d11ff99 2b3bd52 3ab5289 6db8e40 2b3bd52 d11ff99 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
---
license: apache-2.0
pipeline_tag: text-generation
tags:
- chemistry
- biology
- text-generation-inference
---
## ๐ก Model description
This repo contains a large molecular generative model built with molecular language SELFIES.
## ๐ Intended uses
You can use the model to generate molecules from scratch (i.e., inputting the bos_token), or input a partial structure for the model to complete.
## ๐ ๏ธ How to use
We have provided two types of examples. You can modify the input, generation parameters, etc., according to your needs.
- Denovo molecule generation example:
```python
>>> from transformers import AutoTokenizer, LlamaForCausalLM
>>> import torch
>>> tokenizer = AutoTokenizer.from_pretrained("zjunlp/MolGen-7b")
>>> model = LlamaForCausalLM.from_pretrained(
"zjunlp/MolGen-7b",
load_in_8bit=True,
torch_dtype=torch.float16,
device_map="auto",
)
>>> device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
>>> sf_input = tokenizer(tokenizer.bos_token, return_tensors="pt").to(device)
>>> molecules = model.generate(input_ids=sf_input["input_ids"],
attention_mask=sf_input["attention_mask"],
do_sample=True,
max_new_tokens=10,
top_p=0.75,
top_k=30,
return_dict_in_generate=False,
num_return_sequences=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][Branch2][Ring1][=Branch2][C][=Branch1]',
'[C][N][C][C][C][Branch2][Ring2][Ring2][N][C]',
'[C][O][C][=C][C][=C][C][Branch2][Ring1][Branch1]',
'[C][N][C][C][C@H1][Branch2][Ring1][Branch2][N][Branch1]',
'[C][=C][C][Branch2][Ring1][#C][C][=Branch1][C][=O]']
```
- Molecular completion example:
```python
>>> from transformers import AutoTokenizer, LlamaForCausalLM
>>> import torch
>>> tokenizer = AutoTokenizer.from_pretrained("zjunlp/MolGen-7b")
>>> model = LlamaForCausalLM.from_pretrained(
"zjunlp/MolGen-7b",
load_in_8bit=True,
torch_dtype=torch.float16,
device_map="auto",
)
>>> device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
>>> sf_input = tokenizer("[C][N][O]", return_tensors="pt").to(device)
>>> molecules = model.generate(input_ids=sf_input["input_ids"],
attention_mask=sf_input["attention_mask"],
do_sample=True,
max_new_tokens=10,
top_p=0.75,
top_k=30,
return_dict_in_generate=False,
num_return_sequences=5,
)
>>> sf_output = [tokenizer.decode(g, skip_special_tokens=True, clean_up_tokenization_spaces=True).replace(" ","") for g in molecules]
['[C][N][O][C][=Branch1][C][=O][/C][Ring1][=Branch1][=C][/C][=C]',
'[C][N][O][/C][=Branch1][#Branch1][=C][/N][Branch1][C][C][C][C]',
'[C][N][O][/C][=C][/C][=C][C][=Branch1][C][=O][C][=C]',
'[C][N][O][C][=Branch1][C][=O][N][Branch1][C][C][C][=Branch1]',
'[C][N][O][Ring1][Branch1][C][C][C][C][C][C][C][C]']
```
## ๐ Citation
If you use our repository, please cite:
```bibtex
@inproceedings{fang2023domain,
author = {Yin Fang and
Ningyu Zhang and
Zhuo Chen and
Xiaohui Fan and
Huajun Chen},
title = {Domain-Agnostic Molecular Generation with Chemical Feedback},
booktitle = {{ICLR}},
publisher = {OpenReview.net},
year = {2024},
url = {https://openreview.net/pdf?id=9rPyHyjfwP}
}
```
|