CoolFace
Modelpublic

Rostlab/prot_bert_bfd

sourceHugging Faceupdated 6y agoView on Hugging Face
18likes17kdownloads
README.md142 linesDownload Raw Back to root
1---2language: protein3tags:4- protein language model5datasets:6- BFD7---8 9# ProtBert-BFD model10 11Pretrained model on protein sequences using a masked language modeling (MLM) objective. It was introduced in12[this paper](https://doi.org/10.1101/2020.07.12.199554) and first released in13[this repository](https://github.com/agemagician/ProtTrans). This model is trained on uppercase amino acids: it only works with capital letter amino acids.14 15 16## Model description17 18ProtBert-BFD is based on Bert model which pretrained on a large corpus of protein sequences in a self-supervised fashion.19This 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 of20publicly available data) with an automatic process to generate inputs and labels from those protein sequences.21 22One important difference between our Bert model and the original Bert version is the way of dealing with sequences as separate documents23This means the Next sentence prediction is not used, as each sequence is treated as a complete document.24The masking follows the original Bert training with randomly masks 15% of the amino acids in the input. 25 26At the end, the feature extracted from this model revealed that the LM-embeddings from unlabeled data (only protein sequences) captured important biophysical properties governing protein27shape.28This implied learning some of the grammar of the language of life realized in protein sequences.29 30## Intended uses & limitations31 32The model could be used for protein feature extraction or to be fine-tuned on downstream tasks.33We have noticed in some tasks you could gain more accuracy by fine-tuning the model rather than using it as a feature extractor.34 35### How to use36 37You can use this model directly with a pipeline for masked language modeling:38 39```python40>>> from transformers import BertForMaskedLM, BertTokenizer, pipeline41>>> tokenizer = BertTokenizer.from_pretrained('Rostlab/prot_bert_bfd', do_lower_case=False )42>>> model = BertForMaskedLM.from_pretrained("Rostlab/prot_bert_bfd")43>>> unmasker = pipeline('fill-mask', model=model, tokenizer=tokenizer)44>>> unmasker('D L I P T S S K L V V [MASK] D T S L Q V K K A F F A L V T')45 46[{'score': 0.1165614128112793,47  'sequence': '[CLS] D L I P T S S K L V V L D T S L Q V K K A F F A L V T [SEP]',48  'token': 5,49  'token_str': 'L'},50 {'score': 0.08976086974143982,51  'sequence': '[CLS] D L I P T S S K L V V V D T S L Q V K K A F F A L V T [SEP]',52  'token': 8,53  'token_str': 'V'},54 {'score': 0.08864385634660721,55  'sequence': '[CLS] D L I P T S S K L V V S D T S L Q V K K A F F A L V T [SEP]',56  'token': 10,57  'token_str': 'S'},58 {'score': 0.06227643042802811,59  'sequence': '[CLS] D L I P T S S K L V V A D T S L Q V K K A F F A L V T [SEP]',60  'token': 6,61  'token_str': 'A'},62 {'score': 0.06194969266653061,63  'sequence': '[CLS] D L I P T S S K L V V T D T S L Q V K K A F F A L V T [SEP]',64  'token': 15,65  'token_str': 'T'}]66```67 68Here is how to use this model to get the features of a given protein sequence in PyTorch:69 70```python71from transformers import BertModel, BertTokenizer72import re73tokenizer = BertTokenizer.from_pretrained('Rostlab/prot_bert_bfd', do_lower_case=False )74model = BertModel.from_pretrained("Rostlab/prot_bert_bfd")75sequence_Example = "A E T C Z A O"76sequence_Example = re.sub(r"[UZOB]", "X", sequence_Example)77encoded_input = tokenizer(sequence_Example, return_tensors='pt')78output = model(**encoded_input)79```80 81## Training data82 83The ProtBert-BFD model was pretrained on [BFD](https://bfd.mmseqs.com/), a dataset consisting of 2.1 billion protein sequences.84 85## Training procedure86 87### Preprocessing88 89The protein sequences are uppercased and tokenized using a single space and a vocabulary size of 21.90The inputs of the model are then of the form:91 92```93[CLS] Protein Sequence A [SEP] Protein Sequence B [SEP]94```95 96Furthermore, each protein sequence was treated as a separate document.97The preprocessing step was performed twice, once for a combined length (2 sequences) of less than 512 amino acids, and another time using a combined length (2 sequences) of less than 2048 amino acids.98 99The details of the masking procedure for each sequence followed the original Bert model as following:100- 15% of the amino acids are masked.101- In 80% of the cases, the masked amino acids are replaced by `[MASK]`.102- In 10% of the cases, the masked amino acids are replaced by a random amino acid (different) from the one they replace.103- In the 10% remaining cases, the masked amino acids are left as is.104 105### Pretraining106 107The model was trained on a single TPU Pod V3-1024 for one million steps in total.108800k steps using sequence length 512 (batch size 32k), and 200K steps using sequence length 2048 (batch size 6k).109The optimizer used is Lamb with a learning rate of 0.002, a weight decay of 0.01, learning rate warmup for 140k steps and linear decay of the learning rate after.110 111## Evaluation results112 113When fine-tuned on downstream tasks, this model achieves the following results:114 115Test results :116 117| Task/Dataset | secondary structure (3-states) | secondary structure (8-states)  |  Localization | Membrane  |118|:-----:|:-----:|:-----:|:-----:|:-----:|119|   CASP12  | 76 | 65 |    |    |120|   TS115   | 84 | 73 |    |    | 121|   CB513   | 83 | 70 |    |    |122|  DeepLoc  |    |    | 78 | 91 |123 124### BibTeX entry and citation info125 126```bibtex127@article {Elnaggar2020.07.12.199554,128	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},129	title = {ProtTrans: Towards Cracking the Language of Life{\textquoteright}s Code Through Self-Supervised Deep Learning and High Performance Computing},130	elocation-id = {2020.07.12.199554},131	year = {2020},132	doi = {10.1101/2020.07.12.199554},133	publisher = {Cold Spring Harbor Laboratory},134	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.},135	URL = {https://www.biorxiv.org/content/early/2020/07/21/2020.07.12.199554},136	eprint = {https://www.biorxiv.org/content/early/2020/07/21/2020.07.12.199554.full.pdf},137	journal = {bioRxiv}138}139```140 141> Created by [Ahmed Elnaggar/@Elnaggar_AI](https://twitter.com/Elnaggar_AI) | [LinkedIn](https://www.linkedin.com/in/prof-ahmed-elnaggar/)142