prott5
Skill2 starsChanged 8 months agoMITView on GitHub
Skill for protein embeddings using ProtTrans models (ProtT5, ProtBERT) from Rostlab. Use this skill whenever a user wants protein embeddings or representations for downstream ML tasks, protein classification (subcellular localization, membrane prediction, secondary structure annotation), similarity search, or regression tasks (stability, fitness) using Rostlab's ProtTrans family. ProtT5-XL outperforms BERT-based protein models and is competitive with ESM2 on most benchmarks. Also trigger when the user mentions ProtTrans, ProtT5, ProtBERT, prot_t5, prot_bert, Rostlab protein models, or wants HuggingFace-based protein language model embeddings that aren't ESM2.
- Installs packages
In this repository14 other files it gives its agents.
- alphafold3Skill
- alphafoldSkill
- boltzSkill
- chai1Skill
- diffdockSkill
- esm2Skill
- esm3Skill
- esmcSkill
- evo2Skill
- prostt5Skill
- proteinmpnnSkill
- rfdiffusionSkill
- rnafmSkill
- scgptSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 39
Use prot_t5_xl_half_uniref50-enc as the default: it's encoder-only (no decoder weights), loads in half-precision, and is what all published …
- Distinctive: line 171
L2-normalize: before cosine similarity or FAISS indexing
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
ProtT5: Protein Language Model Embeddings
Overview
ProtT5 is a family of T5-based protein language models from Rostlab, trained on millions of UniRef protein sequences. The recommended model — ProtT5-XL-U50 — is an encoder-decoder transformer with 3B parameters whose encoder produces 1024-dimensional embeddings that outperform earlier BERT-based protein models and match or exceed ESM2 on most tasks.
Primary use cases:
- Per-residue and per-protein embeddings for downstream ML
- Protein classification (localization, membrane, function)
- Regression (stability, fitness, thermostability)
- Sequence similarity search
Installation
pip install transformers torch sentencepieceModel Selection
| Model | Type | Params | HF ID | Best for |
| ProtT5-XL-U50 | T5 encoder | 3B | Rostlab/prot_t5_xl_half_uniref50-enc | Best default — half-precision encoder only |
| ProtT5-XL-U50 (full) | T5 enc-dec | 3B | Rostlab/prot_t5_xl_uniref50 | When you also need the decoder |
| ProtT5-XXL-U50 | T5 encoder | 11B | Rostlab/prot_t5_xxl_uniref50 | Maximum accuracy, multi-GPU |
| ProtBERT-BFD | BERT | ~420M | Rostlab/prot_bert_bfd | Faster/lighter, lower quality |
| ProtBERT | BERT | ~420M | Rostlab/prot_bert | UniRef100 trained BERT |
Use prot_t5_xl_half_uniref50-enc as the default: it's encoder-only (no decoder weights), loads in half-precision, and is what all published benchmarks use.
Critical Preprocessing
This is the most important thing to get right. ProtT5 requires two preprocessing steps that ESM2 does not:
import re
def preprocess(sequence: str) -> str:
# 1. Map rare/ambiguous amino acids to X
sequence = re.sub(r"[UZOB]", "X", sequence)
# 2. Space-separate every amino acid (ProtT5 is character-level)
return " ".join(list(sequence))
sequence = "MKTAYIAKQRQISFVK"
processed = preprocess(sequence)
# → "M K T A Y I A K Q R Q I S F V K"Skip either step and you will get garbage embeddings — the model was trained on this exact format.
Core Usage
Single Sequence
import re
import torch
from transformers import T5Tokenizer, T5EncoderModel
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
tokenizer = T5Tokenizer.from_pretrained("Rostlab/prot_t5_xl_half_uniref50-enc", do_lower_case=False)
model = T5EncoderModel.from_pretrained("Rostlab/prot_t5_xl_half_uniref50-enc").to(device)
if device.type == "cpu":
model = model.float() # half-precision not supported on CPU
model.eval()
sequence = "MKTAYIAKQRQISFVK"
processed = " ".join(list(re.sub(r"[UZOB]", "X", sequence)))
ids = tokenizer(processed, return_tensors="pt", add_special_tokens=True).to(device)
with torch.no_grad():
output = model(**ids)
# output.last_hidden_state: (1, seq_len + 1, 1024)
# T5 encoder adds an EOS token at the end — slice to remove it
per_residue = output.last_hidden_state[0, :len(sequence)] # (L, 1024)
per_sequence = per_residue.mean(dim=0) # (1024,)
print(per_residue.shape) # (16, 1024)
print(per_sequence.shape) # (1024,)Note: T5 encoder output has shape (seq_len + 1, 1024) — the +1 is the trailing EOS token. Slice [:len(sequence)] to get only residue embeddings. Unlike BERT/ESM2, there is no leading [CLS] token in the T5 encoder output.
Batch Processing
def get_embeddings(model, tokenizer, sequences, device):
"""Mean-pooled per-sequence embeddings for a list of sequences."""
# Preprocess all sequences
processed = [" ".join(list(re.sub(r"[UZOB]", "X", s))) for s in sequences]
lengths = [len(s) for s in sequences]
ids = tokenizer(
processed,
return_tensors="pt",
padding="longest",
add_special_tokens=True,
).to(device)
with torch.no_grad():
output = model(**ids)
embeddings = []
for i, seq_len in enumerate(lengths):
# Slice per-residue embeddings (no leading special token, EOS at end)
per_residue = output.last_hidden_state[i, :seq_len] # (L, 1024)
per_sequence = per_residue.mean(dim=0) # (1024,)
embeddings.append(per_sequence.cpu().float())
return torch.stack(embeddings) # (N, 1024)See scripts/embed.py for a CLI that reads FASTA and saves embeddings.
Scripts
# Batch embed a FASTA file → .npy
python scripts/embed.py sequences.fasta --output embeddings.npy
# Save as HDF5, L2-normalized
python scripts/embed.py sequences.fasta --output embeddings.h5 --normalize
# Use ProtBERT-BFD for faster/lighter inference
python scripts/embed.py sequences.fasta --model Rostlab/prot_bert_bfd --output embeddings.npyFine-Tuned Checkpoints
Rostlab publishes ready-to-use fine-tuned models:
| Task | HF ID |
| Secondary structure (3-class) | Rostlab/prot_bert_bfd_ss3 |
| Membrane prediction | Rostlab/prot_bert_bfd_membrane |
| Subcellular localization | Rostlab/prot_bert_bfd_localization |
Load with the appropriate HuggingFace pipeline for quick prediction without training.
Comparison with ESM2 and ESM-C
| ProtT5-XL-U50 | ESM2-650M | ESM-C 600M | |
| Architecture | T5 encoder | BERT encoder | Custom encoder |
| Package | transformers | transformers | esm SDK |
| Hidden dim | 1024 | 1280 | 1152 |
| Preprocessing | space-sep + X mapping | none | none |
| Special token handling | slice [:seq_len] | slice [1:-1] | none |
| Subcell. Loc. (DeepLoc) | 86 | 83 | — |
| Variant effect (DMS) | 0.53 | — | — |
ProtT5 is a strong choice for localization, function prediction, and variant effect tasks. ESM-C is faster for pure embedding throughput.
Best Practices
- Always use half-precision on GPU (
prot_t5_xl_half_uniref50-encis already half-precision by default) - Max sequence length: 1022 residues (1024 minus 2 for special tokens) — truncate or chunk longer sequences
- L2-normalize before cosine similarity or FAISS indexing
- For comparison with published benchmarks, always use
prot_t5_xl_half_uniref50-enc
Resources
- GitHub: https://github.com/agemagician/ProtTrans
- HuggingFace: https://huggingface.co/Rostlab
- Paper: Elnaggar et al., IEEE TPAMI 2021 — https://doi.org/10.1109/TPAMI.2021.3095381
- Pre-computed embeddings: available via UniProt for all reviewed sequences
- LambdaPP webservice: https://embed.predictprotein.org/
References
references/prott5-api.md— batch processing, layer extraction, ProtBERT usage, downstream tasks, FAISS, fine-tuning patterns
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

