prot t5 xl uniref50

提供商Rostlab
分类text2text-generation
许可证Apache-2.0
下载量1.0M
星标0

简介

ProtT5-XL-UniRef50 是一款专门为蛋白质序列设计的预训练模型,基于 T5 架构并在大规模 UniRef50 数据库上进行了训练。它将蛋白质序列视为一种特殊的“语言”,能够捕捉氨基酸排列中的深层生物学模式。对于生物信息学开发者而言,它不像通用 LLM 那样用于聊天,而是一个强大的特征提取器或基础模型,适用于蛋白质属性预测、序列填充或功能注释等下游任务。上手难度中等,需要一定的 PyTorch/Hugging Face 基础及生物学背景,可将其视为蛋白质领域的“BERT”或“T5”。

核心亮点

  • 基于 UniRef50 大规模数据集预训练
  • 擅长蛋白质序列的表示学习与特征提取
  • 适用于蛋白质功能预测及属性分析
  • 兼容 Hugging Face 生态,部署便捷
  • 采用 Apache-2.0 协议,对商业友好

使用方法

安装依赖
# 安装 Hugging Face transformers
pip install transformers torch
SDK 使用
# 使用 transformers 加载模型
from transformers import AutoModel, AutoTokenizer

model = AutoModel.from_pretrained("Rostlab/prot_t5_xl_uniref50")
tokenizer = AutoTokenizer.from_pretrained("Rostlab/prot_t5_xl_uniref50")

Hugging Face 下载

我们推荐使用命令行或者 Hugging Face Hub SDK 来进行模型的下载。

操作指引:在下载前,请先通过如下命令安装 huggingface_hub:

操作指引
pip install -U huggingface_hub

命令行下载

下载完整模型库

下载完整模型库
huggingface-cli download Rostlab/prot_t5_xl_uniref50

下载单个文件到指定本地文件夹(以下载 config.json 到当前路径下 ./dir 目录为例)

下载单个文件到指定本地文件夹(以下载 config.json 到当前路径下 ./dir 目录为例)
huggingface-cli download Rostlab/prot_t5_xl_uniref50 config.json --local-dir ./dir

更多命令行下载选项,可参见官方文档

SDK 下载

SDK 下载
# 模型下载
from huggingface_hub import snapshot_download
model_dir = snapshot_download('Rostlab/prot_t5_xl_uniref50')

Git 下载

请确保 lfs 已经被正确安装

Git 下载
git lfs install
git clone https://huggingface.co/Rostlab/prot_t5_xl_uniref50

如果您希望跳过 lfs 大文件下载,可以使用如下命令

跳过 LFS
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/Rostlab/prot_t5_xl_uniref50

模型文件托管在 Hugging Face Hub,使用 HF CLI / SDK / Git 直接下载,不经过本站。

PyTorch / Transformers 使用

安装 Transformers

安装 Transformers
pip install -U transformers torch

模型加载和推理

模型加载和推理
from transformers import AutoModelForCausalLM, AutoTokenizer

model = AutoModelForCausalLM.from_pretrained('Rostlab/prot_t5_xl_uniref50')
tokenizer = AutoTokenizer.from_pretrained('Rostlab/prot_t5_xl_uniref50')

完整文档

来源: HuggingFace

---
tags:

  • protein language model

datasets:
  • UniRef50

---

ProtT5-XL-UniRef50 model

Pretrained model on protein sequences using a masked language modeling (MLM) objective. It was introduced in
this paper and first released in
this repository. This model is trained on uppercase amino acids: it only works with capital letter amino acids.

Model description

ProtT5-XL-UniRef50 is based on the t5-3b model and was pretrained on a large corpus of protein sequences in a self-supervised fashion.
This means it was pretrained on the raw protein sequences only, with no humans labelling them in any way (which is why it can use lots of
publicly available data) with an automatic process to generate inputs and labels from those protein sequences.

One important difference between this T5 model and the original T5 version is the denosing objective.
The original T5-3B model was pretrained using a span denosing objective, while this model was pre-trained with a Bart-like MLM denosing objective.
The masking probability is consistent with the original T5 training by randomly masking 15% of the amino acids in the input.

It has been shown that the features extracted from this self-supervised model (LM-embeddings) captured important biophysical properties governing protein shape.
shape.
This implied learning some of the grammar of the language of life realized in protein sequences.

Intended uses & limitations

The model could be used for protein feature extraction or to be fine-tuned on downstream tasks.
We have noticed in some tasks on can gain more accuracy by fine-tuning the model rather than using it as a feature extractor.
We have also noticed that for feature extraction, its better to use the feature extracted from the encoder not from the decoder.

How to use

Here is how to use this model to extract the features of a given protein sequence in PyTorch:

python
sequence_examples = ["PRTEINO", "SEQWENCE"]

this will replace all rare/ambiguous amino acids by X and introduce white-space between all amino acids

sequence_examples = [" ".join(list(re.sub(r"[UZOB]", "X", sequence))) for sequence in sequence_examples]

tokenize sequences and pad up to the longest sequence in the batch

ids = tokenizer.batch_encode_plus(sequence_examples, add_special_tokens=True, padding="longest") input_ids = torch.tensor(ids['input_ids']).to(device) attention_mask = torch.tensor(ids['attention_mask']).to(device)

generate embeddings

with torch.no_grad(): embedding_repr = model(input_ids=input_ids,attention_mask=attention_mask)

extract embeddings for the first ([0,:]) sequence in the batch while removing padded & special tokens ([0,:7])

emb_0 = embedding_repr.last_hidden_state[0,:7] # shape (7 x 1024) print(f"Shape of per-residue embedding of first sequences: {emb_0.shape}")

do the same for the second ([1,:]) sequence in the batch while taking into account different sequence lengths ([1,:8])

emb_1 = embedding_repr.last_hidden_state[1,:8] # shape (8 x 1024)

if you want to derive a single representation (per-protein embedding) for the whole protein

emb_0_per_protein = emb_0.mean(dim=0) # shape (1024)

print(f"Shape of per-protein embedding of first sequences: {emb_0_per_protein.shape}")

Training data

The ProtT5-XL-UniRef50 model was pretrained on UniRef50, a dataset consisting of 45 million protein sequences.

Training procedure

Preprocessing

The protein sequences are uppercased and tokenized using a single space and a vocabulary size of 21. The rare amino acids "U,Z,O,B" were mapped to "X".
The inputs of the model are then of the form:

code
Protein Sequence [EOS]

The preprocessing step was performed on the fly, by cutting and padding the protein sequences up to 512 tokens.

The details of the masking procedure for each sequence are as follows:

  • 15% of the amino acids are masked.

  • In 90% of the cases, the masked amino acids are replaced by [MASK] token.

  • In 10% of the cases, the masked amino acids are replaced by a random amino acid (different) from the one they replace.

Pretraining

The model was trained on a single TPU Pod V2-256 for 991.5 thousand steps in total, using sequence length 512 (batch size 2k).
It was trained using ProtT5-XL-BFD model as an initial checkpoint, rather than training from scratch.
It has a total of approximately 3B parameters and was trained using the encoder-decoder architecture.
The optimizer used is AdaFactor with inverse square root learning rate schedule for pre-training.

Evaluation results

When the model is used for feature extraction, this model achieves the following results:

Test results :

| Task/Dataset | secondary structure (3-states) | secondary structure (8-states) | Localization | Membrane |
|:-----:|:-----:|:-----:|:-----:|:-----:|
| CASP12 | 81 | 70 | | |
| TS115 | 87 | 77 | | |
| CB513 | 86 | 74 | | |
| DeepLoc | | | 81 | 91 |

BibTeX entry and citation info

bibtex
@article {Elnaggar2020.07.12.199554,
	author = {Elnaggar, Ahmed and Heinzinger, Michael and Dallago, Christian and Rehawi, Ghalia and Wang, Yu and Jones, Llion and Gibbs, Tom and Feher, Tamas and Angerer, Christoph and Steinegger, Martin and BHOWMIK, DEBSINDHU and Rost, Burkhard},
	title = {ProtTrans: Towards Cracking the Language of Life{\textquoteright}s Code Through Self-Supervised Deep Learning and High Performance Computing},
	elocation-id = {2020.07.12.199554},
	year = {2020},
	doi = {10.1101/2020.07.12.199554},
	publisher = {Cold Spring Harbor Laboratory},
	abstract = {Computational biology and bioinformatics provide vast data gold-mines from protein sequences, ideal for Language Models (LMs) taken from Natural Language Processing (NLP). These LMs reach for new prediction frontiers at low inference costs. Here, we trained two auto-regressive language models (Transformer-XL, XLNet) and two auto-encoder models (Bert, Albert) on data from UniRef and BFD containing up to 393 billion amino acids (words) from 2.1 billion protein sequences (22- and 112 times the entire English Wikipedia). The LMs were trained on the Summit supercomputer at Oak Ridge National Laboratory (ORNL), using 936 nodes (total 5616 GPUs) and one TPU Pod (V3-512 or V3-1024). We validated the advantage of up-scaling LMs to larger models supported by bigger data by predicting secondary structure (3-states: Q3=76-84, 8 states: Q8=65-73), sub-cellular localization for 10 cellular compartments (Q10=74) and whether a protein is membrane-bound or water-soluble (Q2=89). Dimensionality reduction revealed that the LM-embeddings from unlabeled data (only protein sequences) captured important biophysical properties governing protein shape. This implied learning some of the grammar of the language of life realized in protein sequences. The successful up-scaling of protein LMs through HPC to larger data sets slightly reduced the gap between models trained on evolutionary information and LMs. Availability ProtTrans: \<a href="https://github.com/agemagician/ProtTrans"\>https://github.com/agemagician/ProtTrans\</a\>Competing Interest StatementThe authors have declared no competing interest.},
	URL = {https://www.biorxiv.org/content/early/2020/07/21/2020.07.12.199554},
	eprint = {https://www.biorxiv.org/content/early/2020/07/21/2020.07.12.199554.full.pdf},
	journal = {bioRxiv}
}

> Created by Ahmed Elnaggar/@Elnaggar_AI | LinkedIn