Views
No views yet

1>>> from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
2
3>>> tokenizer = AutoTokenizer.from_pretrained("zjunlp/MolGen-large")
4>>> model = AutoModelForSeq2SeqLM.from_pretrained("zjunlp/MolGen-large")
5
6>>> sf_input = tokenizer("[C][=C][C][=C][C][=C][Ring1][=Branch1]", return_tensors="pt")
7>>> # beam search
8>>> molecules = model.generate(input_ids=sf_input["input_ids"],
9 attention_mask=sf_input["attention_mask"],
10 max_length=15,
11 min_length=5,
12 num_return_sequences=5,
13 num_beams=5)
14>>> sf_output = [tokenizer.decode(g, skip_special_tokens=True, clean_up_tokenization_spaces=True).replace(" ","") for g in molecules]
15['[C][=C][C][=C][C][=C][Ring1][=Branch1]',
16'[C][=C][C][=C][C][=C][C][=C][Ring1][=Branch1]',
17'[C][=C][C][=C][C][=C][Ring1][=Branch1][C][=C][C][=C]',
18'[C][=C][C][=C][C][=C][Ring1][=Branch1][C@H1][C][=C][C]',
19'[C][=C][C][=C][C][=C][Ring1][=Branch1][C@H1][=C][C][=C]']1@inproceedings{fang2023domain,
2 author = {Yin Fang and
3 Ningyu Zhang and
4 Zhuo Chen and
5 Xiaohui Fan and
6 Huajun Chen},
7 title = {Domain-Agnostic Molecular Generation with Chemical Feedback},
8 booktitle = {{ICLR}},
9 publisher = {OpenReview.net},
10 year = {2024},
11 url = {https://openreview.net/pdf?id=9rPyHyjfwP}
12}