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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
datasets:
|
| 5 |
+
- RosettaCommons/PISCES-CulledPDB
|
| 6 |
+
license: mit
|
| 7 |
+
library_name: pytorch
|
| 8 |
+
base_model: facebook/esm2_t6_8M_UR50D
|
| 9 |
+
tags:
|
| 10 |
+
- biology
|
| 11 |
+
- bioinformatics
|
| 12 |
+
- protein-secondary-structure
|
| 13 |
+
- esm2
|
| 14 |
+
- pytorch
|
| 15 |
+
- bilstm
|
| 16 |
+
pipeline_tag: token-classification
|
| 17 |
+
model-index:
|
| 18 |
+
- name: SERAPH
|
| 19 |
+
results:
|
| 20 |
+
- task:
|
| 21 |
+
type: token-classification
|
| 22 |
+
name: Secondary Structure Prediction (Q3)
|
| 23 |
+
metrics:
|
| 24 |
+
- name: Q3 Test Accuracy
|
| 25 |
+
type: accuracy
|
| 26 |
+
value: 75.31
|
| 27 |
+
---
|
| 28 |
+
|
| 29 |
+
# SERAPH (Secondary Structure Recognition & Prediction Hub)
|
| 30 |
+
|
| 31 |
+
**SERAPH** is a deep learning model designed for 3-state (Q3) protein secondary structure prediction. It processes raw single amino acid sequences and predicts residue-level secondary structure states: **Alpha Helix (`H`)**, **Beta Sheet (`E`)**, or **Coil/Loop (`C`)**.
|
| 32 |
+
|
| 33 |
+
The model leverages a fine-tuned `facebook/esm2_t6_8M_UR50D` backbone combined with a 1D Convolutional feature extractor and a 2-layer Bidirectional LSTM to capture local motifs and long-range sequence context simultaneously.
|
| 34 |
+
|
| 35 |
+
## Model Details
|
| 36 |
+
|
| 37 |
+
### Model Description
|
| 38 |
+
|
| 39 |
+
- **Developed by:** Rogue Builds
|
| 40 |
+
- **Model Type:** Protein Language Model + Conv1D + BiLSTM
|
| 41 |
+
- **Language(s):** Protein Sequences (Amino Acid single-letter codes)
|
| 42 |
+
- **License:** MIT
|
| 43 |
+
- **Finetuned from model:** `facebook/esm2_t6_8M_UR50D`
|
| 44 |
+
|
| 45 |
+
### Model Sources
|
| 46 |
+
|
| 47 |
+
- **Repository:** `PypCoder/SERAPH`
|
| 48 |
+
|
| 49 |
+
---
|
| 50 |
+
|
| 51 |
+
## Intended Uses & Limitations
|
| 52 |
+
|
| 53 |
+
### Direct Use
|
| 54 |
+
* Residue-level 3-state (Q3) protein secondary structure prediction.
|
| 55 |
+
* Single-sequence inference when Multiple Sequence Alignment (MSA) generation is computationally prohibitive or unavailable.
|
| 56 |
+
* Integration into downstream bioinformatics analysis pipelines and structural annotation tools.
|
| 57 |
+
|
| 58 |
+
### Out-of-Scope & Misuse
|
| 59 |
+
* **3D Coordinate Generation**: SERAPH predicts 1D structural states (`H`, `E`, `C`), not 3D atomic coordinates.
|
| 60 |
+
* **Q8 DSSP Prediction**: The model is trained strictly for 3-state classification and does not differentiate between 8-state DSSP assignments (e.g., distinguishing $3_{10}$-helices from $\alpha$-helices).
|
| 61 |
+
|
| 62 |
+
### Known Limitations
|
| 63 |
+
* **Sequence Length Limit**: Input sequences are capped at **512 tokens** due to the positional encoding window of the underlying ESM-2 backbone.
|
| 64 |
+
* **Single-Sequence Bias**: Lacks explicit MSA input features; evolutionary context is derived solely from pre-trained ESM-2 representations.
|
| 65 |
+
|
| 66 |
+
---
|
| 67 |
+
|
| 68 |
+
## How to Get Started
|
| 69 |
+
|
| 70 |
+
### Prerequisites
|
| 71 |
+
|
| 72 |
+
```bash
|
| 73 |
+
pip install torch transformers huggingface_hub
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
### Python Inference Example
|
| 77 |
+
|
| 78 |
+
```python
|
| 79 |
+
import torch
|
| 80 |
+
import torch.nn as nn
|
| 81 |
+
from transformers import EsmModel, EsmTokenizer
|
| 82 |
+
|
| 83 |
+
# 1. Define SERAPH Architecture
|
| 84 |
+
class SERAPH(nn.Module):
|
| 85 |
+
def __init__(self, esm_model, conv_channels=256, kernel_size=7, lstm_hidden=256, num_classes=3, dropout=0.3):
|
| 86 |
+
super().__init__()
|
| 87 |
+
self.esm = esm_model
|
| 88 |
+
esm_embed_dim = self.esm.config.hidden_size
|
| 89 |
+
self.conv = nn.Conv1d(esm_embed_dim, conv_channels, kernel_size=kernel_size, padding=kernel_size // 2)
|
| 90 |
+
self.bn = nn.BatchNorm1d(conv_channels)
|
| 91 |
+
self.dropout = nn.Dropout(dropout)
|
| 92 |
+
self.bilstm = nn.LSTM(conv_channels, lstm_hidden, num_layers=2, batch_first=True, bidirectional=True)
|
| 93 |
+
self.fc = nn.Linear(lstm_hidden * 2, num_classes)
|
| 94 |
+
|
| 95 |
+
def forward(self, input_ids, attention_mask=None):
|
| 96 |
+
x = self.esm(input_ids=input_ids, attention_mask=attention_mask).last_hidden_state
|
| 97 |
+
x = x.transpose(1, 2)
|
| 98 |
+
x = torch.relu(self.bn(self.conv(x)))
|
| 99 |
+
x = self.dropout(x)
|
| 100 |
+
x = x.transpose(1, 2)
|
| 101 |
+
x, _ = self.bilstm(x)
|
| 102 |
+
x = self.dropout(x)
|
| 103 |
+
return self.fc(x)
|
| 104 |
+
|
| 105 |
+
# 2. Load Tokenizer & Base Backbone
|
| 106 |
+
ESM_MODEL_ID = "facebook/esm2_t6_8M_UR50D"
|
| 107 |
+
tokenizer = EsmTokenizer.from_pretrained(ESM_MODEL_ID)
|
| 108 |
+
esm_backbone = EsmModel.from_pretrained(ESM_MODEL_ID)
|
| 109 |
+
|
| 110 |
+
model = SERAPH(esm_model=esm_backbone)
|
| 111 |
+
|
| 112 |
+
# Load weight checkpoint
|
| 113 |
+
# checkpoint = torch.load("SERAPH.pth", map_location="cpu")
|
| 114 |
+
# model.load_state_dict(checkpoint["model_state_dict"])
|
| 115 |
+
model.eval()
|
| 116 |
+
|
| 117 |
+
# 3. Perform Prediction
|
| 118 |
+
IDX_TO_LABEL = {0: 'H', 1: 'E', 2: 'C'}
|
| 119 |
+
sequence = "MVLSPADKTNVKAAWGKVGAHAGEYGAEALERMFLSFPTTKTYFPHFDLSHGSAQVKGHGKKVADALTNAVAHVDDMPNALSALSDLHAHKLRVDPVNFKLLSHCLLVTLAAHLPAEFTPAVHASLDKFLASVSTVLTSKYR"
|
| 120 |
+
|
| 121 |
+
tokens = tokenizer(sequence, return_tensors="pt", truncation=True, max_length=512)
|
| 122 |
+
|
| 123 |
+
with torch.no_grad():
|
| 124 |
+
output = model(input_ids=tokens["input_ids"], attention_mask=tokens["attention_mask"])
|
| 125 |
+
preds = output.argmax(dim=-1)[0]
|
| 126 |
+
|
| 127 |
+
# Omit special tokens [CLS] and [EOS]
|
| 128 |
+
prediction = "".join([IDX_TO_LABEL[p.item()] for p in preds[1:-1]])
|
| 129 |
+
print(f"Sequence: {sequence}")
|
| 130 |
+
print(f"Prediction: {prediction}")
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
---
|
| 134 |
+
|
| 135 |
+
## Training Details
|
| 136 |
+
|
| 137 |
+
### Training Data
|
| 138 |
+
|
| 139 |
+
* **Dataset**: CullPDB (~6,000 non-redundant protein chains).
|
| 140 |
+
|
| 141 |
+
### Training Procedure
|
| 142 |
+
|
| 143 |
+
* **Optimizer**: Adam (`lr=5e-5`, `weight_decay=1e-4`)
|
| 144 |
+
* **Loss Function**: `CrossEntropyLoss` with class weight adjustments `[H: 1.3, E: 1.3, C: 1.0]`
|
| 145 |
+
* **Gradient Clipping**: `max_norm = 1.0`
|
| 146 |
+
* **Scheduler**: `ReduceLROnPlateau` (`patience=3`, `factor=0.5`)
|
| 147 |
+
* **Batch Size**: 32 (with dynamic sequence padding)
|
| 148 |
+
* **Epochs**: 15
|
| 149 |
+
* **Backbone Unfreezing**: Top 2 transformer layers of `facebook/esm2_t6_8M_UR50D` unfrozen during training.
|
| 150 |
+
|
| 151 |
+
### Parameter Distribution
|
| 152 |
+
|
| 153 |
+
| Layer Component | Trainable Parameters |
|
| 154 |
+
|---|---|
|
| 155 |
+
| ESM-2 Backbone (Unfrozen layers) | ~2,600,000 |
|
| 156 |
+
| Conv1D (`320 → 256`, `k=7`) | 573,440 |
|
| 157 |
+
| BatchNorm1d (`256`) | 512 |
|
| 158 |
+
| BiLSTM (2 Layers, hidden=256) | ~1,311,232 |
|
| 159 |
+
| Linear Head (`512 → 3`) | 1,539 |
|
| 160 |
+
| **Total Trainable Parameters** | **3,205,379** |
|
| 161 |
+
|
| 162 |
+
---
|
| 163 |
+
|
| 164 |
+
## Evaluation Results
|
| 165 |
+
|
| 166 |
+
### Evaluation Benchmark
|
| 167 |
+
|
| 168 |
+
Evaluated on the standard **CB513** benchmark dataset.
|
| 169 |
+
|
| 170 |
+
### Metrics
|
| 171 |
+
|
| 172 |
+
| Evaluation Metric | Score |
|
| 173 |
+
|---|---|
|
| 174 |
+
| **Q3 Test Accuracy (CB513)** | **75.31%** |
|
| 175 |
+
| **Q3 Training Accuracy** | **79.34%** |
|
| 176 |
+
|
| 177 |
+
#### Class Breakdown
|
| 178 |
+
|
| 179 |
+
| Structure Class | Precision | Recall |
|
| 180 |
+
|---|---|---|
|
| 181 |
+
| **Helix (`H`)** | 0.82 | 0.80 |
|
| 182 |
+
| **Sheet (`E`)** | 0.63 | 0.81 |
|
| 183 |
+
| **Coil (`C`)** | 0.79 | 0.68 |
|
| 184 |
+
|
| 185 |
+
---
|
| 186 |
+
|
| 187 |
+
## Citation & Contact
|
| 188 |
+
|
| 189 |
+
If you use SERAPH in your work, please cite the underlying ESM-2 paper and reference this repository:
|
| 190 |
+
|
| 191 |
+
```bibtex
|
| 192 |
+
@software{seraph2026,
|
| 193 |
+
author = {Muhammad Asad Ullah},
|
| 194 |
+
title = {SERAPH: Secondary Structure Recognition & Prediction Hub},
|
| 195 |
+
year = {2026},
|
| 196 |
+
url = {https://huggingface.co/PypCoder/SERAPH}
|
| 197 |
+
}
|
| 198 |
+
```
|