Views
No views yet
1import torch
2import transformers
3from huggingface_hub import login
4from transformers import AutoTokenizer
5from transformers.models.t5 import T5ForConditionalGeneration
6import torch
7
8login('<your_hf_token>')
9device = "cuda" if torch.cuda.is_available() else "cpu"
10
11tokenizer = AutoTokenizer.from_pretrained("Neeze/ChemAligner-T5")
12model = T5ForConditionalGeneration.from_pretrained("Neeze/ChemAligner-T5").to(device)
13
14sample_caption = (
15 "The molecule is a energy storage and a fat storage, which impacts cardiovascular "
16 "disease, cancer, and metabolic syndrome, and is characterized as thyroxine treatment. "
17 "The molecule is a membrane stabilizer and inflammatory, and it impacts pancreatitis. "
18 "The molecule is a energy source and a nutrient, impacting both obesity and atherosclerosis."
19)
20
21task_definition = (
22 "Definition: You are given a molecule description in English. "
23 "Your job is to generate the corresponding molecule in SELFIES representation.\n\n"
24)
25
26task_input = (
27 f"{task_definition}"
28 f"Now complete the following example -\n"
29 f"Input: {sample_caption}\nOutput: "
30)
31
32inputs = tokenizer(
33 task_input,
34 return_tensors="pt",
35 truncation=True,
36 max_length=512,
37).to(device)
38
39with torch.no_grad():
40 outputs = model.generate(
41 **inputs,
42 max_length=512,
43 num_beams=1,
44 do_sample=False,
45 temperature=1.0,
46 decoder_start_token_id=0,
47 eos_token_id=1,
48 pad_token_id=0
49 )
50
51outputs = [
52 s.replace("<unk>", "").replace("<pad>", "").replace("</s>", "").strip()
53 for s in tokenizer.batch_decode(outputs)
54]
55
56print(*outputs)
57
58# [C][C][C][C][C][C][C][C][C][C][C][C][C][C][C][C][C][C][C][C][C][C][=Branch1][C][=O][O][C][C@@H1][Branch2][Ring1][=Branch2][C][O][C][=Branch1][C][=O][C][C][C][C][C][C][C][C][C][C][C][C][C][C][C][C][C][C][O][C][=Branch1][C][=O][C][C][C][C][C][C][C][C][C][C][C][C][C][C][C][C][C][C][C][C][C][Branch1][C][C][C][C]1@inproceedings{Phan2026ChemAlignerT5,
2 title = {ChemAligner-T5: A Unified Text-to-Molecule Model via Representation Alignment},
3 author = {Nam, Van Hai Phan and
4 Khoa, Minh Nguyen and
5 Phu, Nguyen Ngoc Thien and
6 Nguyen, Doan Hieu Nguyen and
7 Tri, Minh Pham and
8 Duc, Dang Ngoc Minh},
9 booktitle = {Proceedings of the 2nd International Conference on Computational Intelligence in Engineering Science},
10 year = {2026},
11 month = apr,
12 address = {Nha Trang, Khanh Hoa, Vietnam}
13}