Views
No views yet
Hyformer_peptides_34M jointly fine-tuned on minimal inhibitory concentration values (MIC) against E. coli bacteria[n, 1], where n is the number of chemical compounds, each on a new line[str]input/sequences.smiles[n, 512], where n is the number of chemical compounds1# Create the conda environment called virtual-human-chc-hyformer
2conda env create -f environment.yaml
3
4# Activate the environment
5conda activate virtual-human-chc-hyformer1from pathlib import Path
2
3import torch
4from huggingface_hub import hf_hub_download
5
6from hyformer.models.auto import AutoModel
7from hyformer.models.base import Encoder
8from hyformer.utils import set_seed
9from hyformer.utils.tokenizers.auto import AutoTokenizer
10from hyformer.configs.tokenizer import TokenizerConfig
11from hyformer.configs.model import ModelConfig
12from hyformer.utils.tokenizers.base import BaseTokenizer
13
14SEED = 1337
15set_seed(SEED)
16
17device = "cuda" if torch.cuda.is_available() else "cpu"
18repo = "virtual-human-chc/hyformer_molecules_50M"
19local = Path("virtual-human-chc/hyformer_molecules_50M")
20
21def download(repo_id, filename):
22 return hf_hub_download(repo_id=repo_id, filename=filename, local_dir=local)
23
24sequences = Path("input\sequences.smiles").read_text().splitlines()
25
26download(repo, "vocab.txt")
27
28tokenizer = AutoTokenizer.from_config(
29 TokenizerConfig.from_config_file(download(repo, "tokenizer_config.json"))
30)
31
32model = AutoModel.from_config(
33 ModelConfig.from_config_file(download(repo, "model_config.json"))
34)
35
36model.load_pretrained(download(repo, "ckpt.pt"))
37model.to(device)
38model.eval()
39
40featurizer = model.to_encoder(tokenizer, 128, device) # batch_size=128
41embeddings = featurizer.encode(sequences)
42print(embeddings)
43
44# Output:
45# [[ 0.12989292 -0.04472789 1.27521825 ... -0.31017503 -2.61905527
46# -0.26748869]
47# [ 0.04795801 -0.71846646 3.47797537 ... 2.37488675 -0.28063831
48# 1.84492266]
49# [-0.00499679 0.72711295 0.48343059 ... -1.17737067 0.93289232
50# 0.32299849]