Views
No views yet

1 (Ion Channel Modulating), 0 (non-modulating)config.json – Contains configuration settings for the model architecture, hyperparameters, and training details.model.safetensors – This is the actual trained model weights saved in the SafeTensors format, which is safer and faster than the traditional .bin files.special_tokens_map.json – Stores mappings for special tokens, like [CLS], [SEP], or any custom tokens used in your tokenizer.tokenizer_config.json – Contains tokenizer-related settings (like vocabulary size, tokenization method).vocab.txt – Lists all tokens and their corresponding IDs; it's essential for text tokenization.1pip install torch esm biopython huggingface_hub
2
3
4### Loading the Model from Hugging Face
5
6```python
7import torch
8import esm
9from huggingface_hub import hf_hub_download
10from safetensors.torch import load_file
11from transformers import AutoTokenizer, EsmForSequenceClassification
12
13# Set device
14device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
15
16
17print("Downloading fine-tuned models & weights...")
18repo_id = "anandr88/IonNTxPred"
19subfolder = "saved_model_t33_na"
20# Load the tokenizer and model from Hugging Face
21tokenizer = AutoTokenizer.from_pretrained(repo_id, subfolder=subfolder)
22model = EsmForSequenceClassification.from_pretrained(repo_id, subfolder=subfolder)
23weights_path = hf_hub_download(repo_id=repo_id, filename="saved_model_t33_na/model.safetensors")
24
25# Create a simple classifier model
26class ProteinClassifier(torch.nn.Module):
27 def __init__(self, esm_model):
28 super().__init__()
29 self.esm_model = esm_model
30 # We'll dynamically determine the classifier layer size
31 self.classifier = None
32
33 def forward(self, tokens):
34 with torch.no_grad():
35 results = self.esm_model(tokens, repr_layers=[33], return_contacts=False)
36 embeddings = results["representations"][33].mean(1)
37 return self.classifier(embeddings)
38
39# Initialize model
40classifier = ProteinClassifier(model)
41
42# Load the state dict and determine architecture
43state_dict = load_file(weights_path, device=str(device))
44
45# Find the classifier layer (look for a weight matrix)
46for key, tensor in state_dict.items():
47 if len(tensor.shape) == 2: # This should be the weight matrix
48 num_classes = tensor.shape[0]
49 embedding_dim = tensor.shape[1]
50 print(f"Found classifier layer: {key} (input_dim={embedding_dim}, output_dim={num_classes})")
51
52 # Initialize the classifier layer
53 classifier.classifier = torch.nn.Linear(embedding_dim, num_classes).to(device)
54
55 # Create new state dict with proper names
56 new_state_dict = {
57 'classifier.weight': state_dict[key],
58 'classifier.bias': state_dict[key.replace('weight', 'bias')]
59 }
60 classifier.load_state_dict(new_state_dict, strict=False)
61 break
62
63# Move to device and set to eval mode
64classifier = classifier.to(device)
65classifier.eval()
66
67print(f"\nModel successfully loaded on {device} and ready for inference!")1from transformers import AutoTokenizer, EsmForSequenceClassification
2import torch
3
4# Define the repository ID and subfolder
5repo_id = "anandr88/IonNTxPred"
6subfolder = "saved_model_t33_na"
7
8# Load the tokenizer and model from Hugging Face
9tokenizer = AutoTokenizer.from_pretrained(repo_id, subfolder=subfolder)
10model = EsmForSequenceClassification.from_pretrained(repo_id, subfolder=subfolder)
11
12# Move the model to the appropriate device
13device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
14model.to(device)
15model.eval()
16
17# Function to make predictions
18def make_predictions(model, inputs, device):
19 with torch.no_grad():
20 outputs = model(**inputs)
21 logits = outputs.logits
22 probs = torch.softmax(logits, dim=1)[:, 1].cpu().numpy()
23 return probs
24
25# Example protein sequence
26protein_sequence = "MKASTLVVIFIVIFITISSFSIHDVQASGVEKREQKDCLKKLKLCKENKDCCSKSCKRRGTNIEKRCR"
27
28# Tokenize the input sequence
29inputs = tokenizer(protein_sequence, return_tensors="pt", truncation=True, padding=True)
30inputs = {key: value.to(device) for key, value in inputs.items()}
31
32# Make predictions
33prediction = make_predictions(model, inputs, device)
34
35# Apply threshold for final classification
36threshold = 0.5
37final_prediction = "Na+ channel modulating" if prediction[0] > threshold else "Not Na+ channel modulating"
38
39print(f"📊 Prediction Probability: {prediction[0]:.4f}")
40print(f"🏷️ Final Prediction: {final_prediction}")1pip install torch esm biopython huggingface_hub
2
3
4### Loading the Model from Hugging Face
5
6```python
7import torch
8import esm
9from huggingface_hub import hf_hub_download
10from safetensors.torch import load_file
11from transformers import AutoTokenizer, EsmForSequenceClassification
12
13# Set device
14device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
15
16
17print("Downloading fine-tuned models & weights...")
18repo_id = "anandr88/IonNTxPred"
19subfolder = "saved_model_t33_k"
20# Load the tokenizer and model from Hugging Face
21tokenizer = AutoTokenizer.from_pretrained(repo_id, subfolder=subfolder)
22model = EsmForSequenceClassification.from_pretrained(repo_id, subfolder=subfolder)
23weights_path = hf_hub_download(repo_id=repo_id, filename="saved_model_t33_na/model.safetensors")
24
25# Create a simple classifier model
26class ProteinClassifier(torch.nn.Module):
27 def __init__(self, esm_model):
28 super().__init__()
29 self.esm_model = esm_model
30 # We'll dynamically determine the classifier layer size
31 self.classifier = None
32
33 def forward(self, tokens):
34 with torch.no_grad():
35 results = self.esm_model(tokens, repr_layers=[33], return_contacts=False)
36 embeddings = results["representations"][33].mean(1)
37 return self.classifier(embeddings)
38
39# Initialize model
40classifier = ProteinClassifier(model)
41
42# Load the state dict and determine architecture
43state_dict = load_file(weights_path, device=str(device))
44
45# Find the classifier layer (look for a weight matrix)
46for key, tensor in state_dict.items():
47 if len(tensor.shape) == 2: # This should be the weight matrix
48 num_classes = tensor.shape[0]
49 embedding_dim = tensor.shape[1]
50 print(f"Found classifier layer: {key} (input_dim={embedding_dim}, output_dim={num_classes})")
51
52 # Initialize the classifier layer
53 classifier.classifier = torch.nn.Linear(embedding_dim, num_classes).to(device)
54
55 # Create new state dict with proper names
56 new_state_dict = {
57 'classifier.weight': state_dict[key],
58 'classifier.bias': state_dict[key.replace('weight', 'bias')]
59 }
60 classifier.load_state_dict(new_state_dict, strict=False)
61 break
62
63# Move to device and set to eval mode
64classifier = classifier.to(device)
65classifier.eval()
66
67print(f"\nModel successfully loaded on {device} and ready for inference!")1from transformers import AutoTokenizer, EsmForSequenceClassification
2import torch
3
4# Define the repository ID and subfolder
5repo_id = "anandr88/IonNTxPred"
6subfolder = "saved_model_t33_k"
7
8# Load the tokenizer and model from Hugging Face
9tokenizer = AutoTokenizer.from_pretrained(repo_id, subfolder=subfolder)
10model = EsmForSequenceClassification.from_pretrained(repo_id, subfolder=subfolder)
11
12# Move the model to the appropriate device
13device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
14model.to(device)
15model.eval()
16
17# Function to make predictions
18def make_predictions(model, inputs, device):
19 with torch.no_grad():
20 outputs = model(**inputs)
21 logits = outputs.logits
22 probs = torch.softmax(logits, dim=1)[:, 1].cpu().numpy()
23 return probs
24
25# Example protein sequence
26protein_sequence = "MKASTLVVIFIVIFITISSFSIHDVQASGVEKREQKDCLKKLKLCKENKDCCSKSCKRRGTNIEKRCR"
27
28# Tokenize the input sequence
29inputs = tokenizer(protein_sequence, return_tensors="pt", truncation=True, padding=True)
30inputs = {key: value.to(device) for key, value in inputs.items()}
31
32# Make predictions
33prediction = make_predictions(model, inputs, device)
34
35# Apply threshold for final classification
36threshold = 0.5
37final_prediction = "K+ channel modulating" if prediction[0] > threshold else "Not K+ channel modulating"
38
39print(f"📊 Prediction Probability: {prediction[0]:.4f}")
40print(f"🏷️ Final Prediction: {final_prediction}")1pip install torch esm biopython huggingface_hub
2
3
4### Loading the Model from Hugging Face
5
6```python
7import torch
8import esm
9from huggingface_hub import hf_hub_download
10from safetensors.torch import load_file
11from transformers import AutoTokenizer, EsmForSequenceClassification
12
13# Set device
14device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
15
16
17print("Downloading fine-tuned models & weights...")
18repo_id = "anandr88/IonNTxPred"
19subfolder = "saved_model_t33_ca"
20# Load the tokenizer and model from Hugging Face
21tokenizer = AutoTokenizer.from_pretrained(repo_id, subfolder=subfolder)
22model = EsmForSequenceClassification.from_pretrained(repo_id, subfolder=subfolder)
23weights_path = hf_hub_download(repo_id=repo_id, filename="saved_model_t33_ca/model.safetensors")
24
25# Create a simple classifier model
26class ProteinClassifier(torch.nn.Module):
27 def __init__(self, esm_model):
28 super().__init__()
29 self.esm_model = esm_model
30 # We'll dynamically determine the classifier layer size
31 self.classifier = None
32
33 def forward(self, tokens):
34 with torch.no_grad():
35 results = self.esm_model(tokens, repr_layers=[33], return_contacts=False)
36 embeddings = results["representations"][33].mean(1)
37 return self.classifier(embeddings)
38
39# 4. Initialize model
40classifier = ProteinClassifier(model)
41
42# 5. Load the state dict and determine architecture
43state_dict = load_file(weights_path, device=str(device))
44
45# Find the classifier layer (look for a weight matrix)
46for key, tensor in state_dict.items():
47 if len(tensor.shape) == 2: # This should be the weight matrix
48 num_classes = tensor.shape[0]
49 embedding_dim = tensor.shape[1]
50 print(f"Found classifier layer: {key} (input_dim={embedding_dim}, output_dim={num_classes})")
51
52 # Initialize the classifier layer
53 classifier.classifier = torch.nn.Linear(embedding_dim, num_classes).to(device)
54
55 # Create new state dict with proper names
56 new_state_dict = {
57 'classifier.weight': state_dict[key],
58 'classifier.bias': state_dict[key.replace('weight', 'bias')]
59 }
60 classifier.load_state_dict(new_state_dict, strict=False)
61 break
62
63# Move to device and set to eval mode
64classifier = classifier.to(device)
65classifier.eval()
66
67print(f"\nModel successfully loaded on {device} and ready for inference!")1from transformers import AutoTokenizer, EsmForSequenceClassification
2import torch
3
4# Define the repository ID and subfolder
5repo_id = "anandr88/IonNTxPred"
6subfolder = "saved_model_t33_ca"
7
8# Load the tokenizer and model from Hugging Face
9tokenizer = AutoTokenizer.from_pretrained(repo_id, subfolder=subfolder)
10model = EsmForSequenceClassification.from_pretrained(repo_id, subfolder=subfolder)
11
12# Move the model to the appropriate device
13device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
14model.to(device)
15model.eval()
16
17# Function to make predictions
18def make_predictions(model, inputs, device):
19 with torch.no_grad():
20 outputs = model(**inputs)
21 logits = outputs.logits
22 probs = torch.softmax(logits, dim=1)[:, 1].cpu().numpy()
23 return probs
24
25# Example protein sequence
26protein_sequence = "MKASTLVVIFIVIFITISSFSIHDVQASGVEKREQKDCLKKLKLCKENKDCCSKSCKRRGTNIEKRCR"
27
28# Tokenize the input sequence
29inputs = tokenizer(protein_sequence, return_tensors="pt", truncation=True, padding=True)
30inputs = {key: value.to(device) for key, value in inputs.items()}
31
32# Make predictions
33prediction = make_predictions(model, inputs, device)
34
35# Apply threshold for final classification
36threshold = 0.5
37final_prediction = "Ca++ channel modulating" if prediction[0] > threshold else "Not Ca++ channel modulating"
38
39print(f"📊 Prediction Probability: {prediction[0]:.4f}")
40print(f"🏷️ Final Prediction: {final_prediction}")1pip install torch esm biopython huggingface_hub
2
3
4### Loading the Model from Hugging Face
5
6```python
7import torch
8import esm
9from huggingface_hub import hf_hub_download
10from safetensors.torch import load_file
11from transformers import AutoTokenizer, EsmForSequenceClassification
12
13# Set device
14device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
15
16
17print("Downloading fine-tuned models & weights...")
18repo_id = "anandr88/IonNTxPred"
19subfolder = "saved_model_t33_other"
20# Load the tokenizer and model from Hugging Face
21tokenizer = AutoTokenizer.from_pretrained(repo_id, subfolder=subfolder)
22model = EsmForSequenceClassification.from_pretrained(repo_id, subfolder=subfolder)
23weights_path = hf_hub_download(repo_id=repo_id, filename="saved_model_t33_na/model.safetensors")
24
25# Create a simple classifier model
26class ProteinClassifier(torch.nn.Module):
27 def __init__(self, esm_model):
28 super().__init__()
29 self.esm_model = esm_model
30 # We'll dynamically determine the classifier layer size
31 self.classifier = None
32
33 def forward(self, tokens):
34 with torch.no_grad():
35 results = self.esm_model(tokens, repr_layers=[33], return_contacts=False)
36 embeddings = results["representations"][33].mean(1)
37 return self.classifier(embeddings)
38
39# Initialize model
40classifier = ProteinClassifier(model)
41
42# Load the state dict and determine architecture
43state_dict = load_file(weights_path, device=str(device))
44
45# Find the classifier layer (look for a weight matrix)
46for key, tensor in state_dict.items():
47 if len(tensor.shape) == 2: # This should be the weight matrix
48 num_classes = tensor.shape[0]
49 embedding_dim = tensor.shape[1]
50 print(f"Found classifier layer: {key} (input_dim={embedding_dim}, output_dim={num_classes})")
51
52 # Initialize the classifier layer
53 classifier.classifier = torch.nn.Linear(embedding_dim, num_classes).to(device)
54
55 # Create new state dict with proper names
56 new_state_dict = {
57 'classifier.weight': state_dict[key],
58 'classifier.bias': state_dict[key.replace('weight', 'bias')]
59 }
60 classifier.load_state_dict(new_state_dict, strict=False)
61 break
62
63# Move to device and set to eval mode
64classifier = classifier.to(device)
65classifier.eval()
66
67print(f"\nModel successfully loaded on {device} and ready for inference!")1from transformers import AutoTokenizer, EsmForSequenceClassification
2import torch
3
4# Define the repository ID and subfolder
5repo_id = "anandr88/IonNTxPred"
6subfolder = "saved_model_t33_other"
7
8# Load the tokenizer and model from Hugging Face
9tokenizer = AutoTokenizer.from_pretrained(repo_id, subfolder=subfolder)
10model = EsmForSequenceClassification.from_pretrained(repo_id, subfolder=subfolder)
11
12# Move the model to the appropriate device
13device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
14model.to(device)
15model.eval()
16
17# Function to make predictions
18def make_predictions(model, inputs, device):
19 with torch.no_grad():
20 outputs = model(**inputs)
21 logits = outputs.logits
22 probs = torch.softmax(logits, dim=1)[:, 1].cpu().numpy()
23 return probs
24
25# Example protein sequence
26protein_sequence = "MKASTLVVIFIVIFITISSFSIHDVQASGVEKREQKDCLKKLKLCKENKDCCSKSCKRRGTNIEKRCR"
27
28# Tokenize the input sequence
29inputs = tokenizer(protein_sequence, return_tensors="pt", truncation=True, padding=True)
30inputs = {key: value.to(device) for key, value in inputs.items()}
31
32# Make predictions
33prediction = make_predictions(model, inputs, device)
34
35# Apply threshold for final classification
36threshold = 0.5
37final_prediction = "Other channel modulating" if prediction[0] > threshold else "Not Other channel modulating"
38
39print(f"📊 Prediction Probability: {prediction[0]:.4f}")
40print(f"🏷️ Final Prediction: {final_prediction}")