Views
No views yet

1>>> from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
2
3>>> tokenizer = AutoTokenizer.from_pretrained("zjunlp/MolGen-large-opt")
4>>> model = AutoModelForSeq2SeqLM.from_pretrained("zjunlp/MolGen-large-opt")
5
6>>> sf_input = tokenizer("[N][#C][C][C][C@@H1][C][C][C][C][C][C][C][C][C][C][C][Ring1][N][=O]", 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=35,
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['[N][#C][C][C][C@@H1][C][C][C][C][C][C][C][C][C][C][C][C][Ring1][N][=O]',
16'[N][#C][C][C][C@@H1][C][C][C][C][C][C][C][C][C][C][C][Ring1][N][=O]',
17'[N][#C][C][C][C@@H1][C][C][C][C][C][C][C][C][C][C][C][C][C][Ring1][N][=O]',
18'[N][#C][C][C][C@@H1][C][C][C][C][C][C][C][C][C][C][Ring1][N][=O]',
19'[N][#C][C][C][C@@H1][C][C][C][C][C][C][C][C][C][C][C][C][C][C][Ring1][N][=O]']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}