Views
No views yet
1from transformers import AutoTokenizer, T5ForConditionalGeneration
2tokenizer = AutoTokenizer.from_pretrained("laituan245/molt5-base", model_max_length=512)
3model = T5ForConditionalGeneration.from_pretrained('PhTae/MolBridge-Gen-Base-C2S')
4
5caption = 'The molecule is a monoterpene that is bicyclo[2.2.1]heptane substituted by methy groups at positions 1, 3 and 3. It is a monoterpene, a terpenoidfundamental parent and a carbobicyclic compound.'
6caption = 'Provide a molecule based on this description: ' + caption
7
8token = tokenizer(caption, return_tensors='pt', padding='longest', truncation=True)
9gen_results = model.generate(input_ids=token['input_ids'],
10 attention_mask=token['attention_mask'],
11 num_beams=5,
12 max_new_tokens=512)
13
14gen_results = tokenizer.decode(gen_results[0], skip_special_tokens=True)
15print(gen_results)