Yin Fang
commited on
Commit
·
89aaa46
1
Parent(s):
17d47f2
Update README.md
Browse files
README.md
CHANGED
|
@@ -19,14 +19,21 @@ You can use the raw model for molecular generation or fine-tune it to a downstre
|
|
| 19 |
### How to use
|
| 20 |
Molecule generation example:
|
| 21 |
```python
|
| 22 |
-
from transformers import AutoTokenizer, BartForConditionalGeneration
|
| 23 |
|
| 24 |
-
tokenizer = AutoTokenizer.from_pretrained("zjunlp/MolGen")
|
| 25 |
-
model = BartForConditionalGeneration.from_pretrained("zjunlp/MolGen", use_auth_token=True)
|
| 26 |
|
| 27 |
-
sf_input = tokenizer("[C][=C][C][=C][C][=C][Ring1][=Branch1]", return_tensors="pt")
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
```
|
| 31 |
|
| 32 |
|
|
|
|
| 19 |
### How to use
|
| 20 |
Molecule generation example:
|
| 21 |
```python
|
| 22 |
+
>>> from transformers import AutoTokenizer, BartForConditionalGeneration
|
| 23 |
|
| 24 |
+
>>> tokenizer = AutoTokenizer.from_pretrained("zjunlp/MolGen")
|
| 25 |
+
>>> model = BartForConditionalGeneration.from_pretrained("zjunlp/MolGen", use_auth_token=True)
|
| 26 |
|
| 27 |
+
>>> sf_input = tokenizer("[C][=C][C][=C][C][=C][Ring1][=Branch1]", return_tensors="pt")
|
| 28 |
+
|
| 29 |
+
>>> # beam search
|
| 30 |
+
>>> molecules = model.generate(input_ids=sf_input["input_ids"],attention_mask=sf_input["attention_mask"],max_length=20,min_length=5,num_return_sequences=5,num_beams=5,past_prompt=None)
|
| 31 |
+
|
| 32 |
+
>>> # top-k search
|
| 33 |
+
>>> molecules = model.generate(input_ids=sf_input["input_ids"],attention_mask=sf_input["attention_mask"],do_sample=True,max_length=20,min_length=5,top_k=5,num_return_sequences=3,past_prompt=None)
|
| 34 |
+
|
| 35 |
+
>>> sf_output = [tokenizer.decode(g, skip_special_tokens=True, clean_up_tokenization_spaces=True).replace(" ","") for g in molecules]
|
| 36 |
+
['[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@H1][C][=C][C][=C][C][=C][Ring1][=Branch1]', '[C][=C][C][=C][C][=C][Ring1][=Branch1][C][=C][C][=C][C][=C][Ring1][=Branch1]', '[C][=C][C][=C][C][=C][Ring1][=Branch1][C@H1][=C][C][=C][Ring1][=Branch1]']
|
| 37 |
```
|
| 38 |
|
| 39 |
|