CoolFace
Modelpublic

virtual-human-chc/prot_bert_bfd

sourceHugging Faceupdated 11mo agoView on Hugging Face
0likes11downloads
README.md129 linesDownload Raw Back to root
1---2language: en3tags:4- protein language model5datasets:6- BFD7pipeline_tag: fill-mask8library_name: transformers9---10 11# ProtBert-BFD model12 13Pretrained model on protein sequences using a masked language modeling (MLM) objective. It was introduced in14[this paper](https://doi.org/10.1101/2020.07.12.199554) and first released in15[this repository](https://github.com/agemagician/ProtTrans). This repository is a fork of their [HuggingFace repository](https://huggingface.co/Rostlab/prot_t5_xxl_bfd/tree/main). This model is trained on uppercase amino acids: it only works with capital letter amino acids.16 17 18## Model description19 20ProtBert-BFD is based on Bert model which pretrained on a large corpus of protein sequences in a self-supervised fashion.21This 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 of22publicly available data) with an automatic process to generate inputs and labels from those protein sequences.23 24One important difference between this Bert model and the original Bert version is the way of dealing with sequences as separate documents.25This means the `Next Sentence Prediction` is not used, as each sequence is treated as a complete document. The masking follows the original Bert training with randomly masks 15% of the amino acids in the input. 26 27At the end, the feature extracted from this model revealed that the LM-embeddings from unlabeled data (only protein sequences) captured important biophysical properties governing protein28shape. This 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('virtual-human-chc/prot_bert_bfd', do_lower_case=False )42>>> model = BertForMaskedLM.from_pretrained('virtual-human-chc/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 re73 74tokenizer = BertTokenizer.from_pretrained("virtual-human-chc/prot_bert_bfd", do_lower_case=False )75model = BertModel.from_pretrained("virtual-human-chc/prot_bert_bfd")76 77sequence_Example = "A E T C Z A O"78sequence_Example = re.sub(r"[UZOB]", "X", sequence_Example)79 80encoded_input = tokenizer(sequence_Example, return_tensors='pt')81output = model(**encoded_input)82```83 84## Training data85 86The ProtBert-BFD model was pretrained on [BFD](https://bfd.mmseqs.com/), a dataset consisting of 2.1 billion protein sequences.87 88## Training procedure89 90### Preprocessing91 92The protein sequences are uppercased and tokenized using a single space and a vocabulary size of 21.93The inputs of the model are then of the form:94 95```96[CLS] Protein Sequence A [SEP] Protein Sequence B [SEP]97```98 99Furthermore, each protein sequence was treated as a separate document.100The 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.101 102The details of the masking procedure for each sequence followed the original Bert model as following:103- 15% of the amino acids are masked.104- In 80% of the cases, the masked amino acids are replaced by `[MASK]`.105- In 10% of the cases, the masked amino acids are replaced by a random amino acid (different) from the one they replace.106- In the 10% remaining cases, the masked amino acids are left as is.107 108### Pretraining109 110The model was trained on a single TPU Pod V3-1024 for one million steps in total.111800k steps using sequence length 512 (batch size 32k), and 200K steps using sequence length 2048 (batch size 6k).112The 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.113 114## Evaluation results115 116When fine-tuned on downstream tasks, this model achieves the following results:117 118Test results :119 120| Task/Dataset | secondary structure (3-states) | secondary structure (8-states)  |  Localization | Membrane  |121|:-----:|:-----:|:-----:|:-----:|:-----:|122|   CASP12  | 76 | 65 |    |    |123|   TS115   | 84 | 73 |    |    | 124|   CB513   | 83 | 70 |    |    |125|  DeepLoc  |    |    | 78 | 91 |126 127# Copyright128 129Code derived from https://github.com/agemagician/ProtTrans is licensed under the MIT License, Copyright (c) 2025 Ahmed Elnaggar. The ProtTrans pretrained models are released under the under terms of the [Academic Free License v3.0 License](https://choosealicense.com/licenses/afl-3.0/), Copyright (c) 2025 Ahmed Elnaggar. The other code is licensed under the MIT license, Copyright (c) 2025 Maksim Pavlov.