Downloads · 30 days
23
8% of all-time downloads
raghavagps-group/antifp2
antifp2 is a machine learning model from raghavagps-group. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as gpl-3.0.
This repository contains a fine-tuned ESM2 model for classifying antifungal proteins from amino acid sequences. The model is trained to predict binary labels indicating whether a protein is antifungal or not.
Downloads · 30 days
23
8% of all-time downloads
All-time downloads
276
Public
Repo size
36.7 GB
Likes
1
Public
Click a slice to open those files.
.bin11.4 GB · 100%
From the Hugging Face model README
This repository contains a fine-tuned ESM2 model for classifying antifungal proteins from amino acid sequences. The model is trained to predict binary labels indicating whether a protein is antifungal or not.
pytorch_model.bin: Trained model weights.alphabet.bin: ESM2 alphabet (tokenizer).config.json: Model configuration.README.md: This file.Install required Python packages:
pip install torch esm biopython huggingface_hub
import torch
import torch.nn as nn
import esm
from huggingface_hub import hf_hub_download
import json
# Define the classifier architecture (must match training)
class ProteinClassifier(nn.Module):
def __init__(self, esm_model, embedding_dim, num_classes):
super(AntiFP2Classifier, self).__init__()
self.esm_model = esm_model
self.fc = nn.Linear(embedding_dim, num_classes)
def forward(self, tokens):
with torch.no_grad():
results = self.esm_model(tokens, repr_layers=[36])
embeddings = results["representations"][36].mean(1)
output = self.fc(embeddings)
return output
# Download model files from Hugging Face Hub
repo_id = "raghavagps-group/antifp2"
model_weights_path = hf_hub_download(repo_id=repo_id, filename="pytorch_model.bin")
alphabet_path = hf_hub_download(repo_id=repo_id, filename="alphabet.bin")
config_path = hf_hub_download(repo_id=repo_id, filename="config.json")
# Load ESM2 backbone model
esm_model, alphabet = esm.pretrained.esm2_t36_3B_UR50D()
# Load configuration
with open(config_path, 'r') as f:
config = json.load(f)
# Initialize classifier
classifier = ProteinClassifier(esm_model, embedding_dim=config['embedding_dim'], num_classes=config['num_classes'])
# Load weights
classifier.load_state_dict(torch.load(model_weights_path))
classifier.eval()
# Load alphabet tokenizer
alphabet = torch.load(alphabet_path)
batch_converter = alphabet.get_batch_converter()
# Move model to GPU if available
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
classifier = classifier.to(device)
Input sequences must be provided as amino acid strings using standard single-letter codes.
The model outputs logits for two classes, which can be converted to probabilities using softmax. The predicted label is antifungal (1) if the probability exceeds a threshold (e.g., 0.5).