Update README.md
Browse files
README.md
CHANGED
|
@@ -1,10 +1,80 @@
|
|
| 1 |
---
|
|
|
|
|
|
|
|
|
|
| 2 |
tags:
|
| 3 |
-
-
|
| 4 |
-
- pytorch_model_hub_mixin
|
| 5 |
---
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
datasets:
|
| 4 |
+
- andrewdalpino/SwissProt-Gene-Ontology
|
| 5 |
tags:
|
| 6 |
+
- esmc
|
|
|
|
| 7 |
---
|
| 8 |
+
# ProtHash
|
| 9 |
|
| 10 |
+
A protein language model that outputs amino acid sequence embeddings for use in clustering, classification, locality-sensitive hashing, and more. Distilled from the [ESMC](https://www.evolutionaryscale.ai/blog/esm-cambrian) family of models with deep comprehension of protein structure, ProtHash produces contextual embeddings that align in vector space according to the sequences' atomic structure. Trained on the [SwissProt](https://huggingface.co/datasets/andrewdalpino/SwissProt-Gene-Ontology) dataset to mimic the activations of its ESMC teacher model, ProtHash embeddings have near perfect similarity to ESMC embeddings but at a greatly reduced computational cost.
|
| 11 |
+
|
| 12 |
+
## Key Features
|
| 13 |
+
|
| 14 |
+
- **Blazing fast and efficient**: ProtHash uses as few as 1.5% of its ESMC teacher's total parameters to achieve near-perfect cosine similarity between the two embedding spaces.
|
| 15 |
+
|
| 16 |
+
- **Structurally-relevant**: Structurally similar proteins will show up nearby in the embedding space enabling downstream tasks such as clustering, classification, and locality-sensitive hashing based on atomic structure.
|
| 17 |
+
|
| 18 |
+
- **Compatible with ESMC**: ProtHash can output embeddings in its native or ESMC teacher's dimensionality - allowing it to serve as both a faster drop-in replacement for ESMC embeddings and a more efficient compressed representation.
|
| 19 |
+
|
| 20 |
+
- **Quantization-ready**: With quantization-aware post-training, ProtHash allows you to quantize the weights of the model without losing similarity to the teacher's embedding space.
|
| 21 |
+
|
| 22 |
+
## Pretrained Models
|
| 23 |
+
|
| 24 |
+
| Name | Context Length | Embedding Dimensionality | Attention Heads (Q/KV) | Encoder Layers | Total Params | Teacher Model | Teacher Dimensionality |
|
| 25 |
+
|---|---|---|---|---|---|---|---|
|
| 26 |
+
| [andrewdalpino/ProtHash-384-Tiny](https://huggingface.co/andrewdalpino/ProtHash-384-Tiny) | 2048 | 384 | 16/4 | 4 | 5M | esmc_300m | 960 |
|
| 27 |
+
| [andrewdalpino/ProtHash-384](https://huggingface.co/andrewdalpino/ProtHash-384) | 2048 | 384 | 16/4 | 10 | 11M | esmc_300m | 960 |
|
| 28 |
+
| [andrewdalpino/ProtHash-512-Tiny](https://huggingface.co/andrewdalpino/ProtHash-512-Tiny) | 2048 | 512 | 16/4 | 4 | 8.5M | esmc_600m | 1152 |
|
| 29 |
+
| [andrewdalpino/ProtHash-512](https://huggingface.co/andrewdalpino/ProtHash-512) | 2048 | 512 | 16/4 | 10 | 19M | esmc_600m | 1152 |
|
| 30 |
+
|
| 31 |
+
## Pretrained Example
|
| 32 |
+
|
| 33 |
+
First, you'll need the `prothash` and `esm` packages installed into your environment. We recommend using a virtual environment such as Python's `venv` module to prevent version conflicts with any system packages.
|
| 34 |
+
|
| 35 |
+
```sh
|
| 36 |
+
pip install prothash esm
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
Then, load the weights from HuggingFace Hub, tokenize a protein sequence, and pass it to the model. ProtHash adopts the ESM tokenizer as it's amino acids tokenization scheme which consists of a vocabulary of 33 amino acid and special tokens. The output will be an embedding vector that can be used in downstream tasks such as comparing to other protein sequence embeddings, clustering, and near-duplicate detection.
|
| 40 |
+
|
| 41 |
+
```python
|
| 42 |
+
import torch
|
| 43 |
+
|
| 44 |
+
from esm.tokenization import EsmSequenceTokenizer
|
| 45 |
+
|
| 46 |
+
from prothash.model import ProtHash
|
| 47 |
+
|
| 48 |
+
tokenizer = EsmSequenceTokenizer()
|
| 49 |
+
|
| 50 |
+
model_name = "andrewdalpino/ProtHash-512-Tiny"
|
| 51 |
+
|
| 52 |
+
model = ProtHash.from_pretrained(model_name)
|
| 53 |
+
|
| 54 |
+
sequence = input("Enter a sequence: ")
|
| 55 |
+
|
| 56 |
+
out = tokenizer(sequence, max_length=2048)
|
| 57 |
+
|
| 58 |
+
tokens = out["input_ids"]
|
| 59 |
+
|
| 60 |
+
# Input is a [1, T] tensor of token indices.
|
| 61 |
+
x = torch.tensor(tokens, dtype=torch.int64).unsqueeze(0)
|
| 62 |
+
|
| 63 |
+
# Output the sequence embedding in native dimensionality.
|
| 64 |
+
y_embed_native = model.embed_native(x).squeeze(0)
|
| 65 |
+
|
| 66 |
+
print(y_embed_native.shape)
|
| 67 |
+
|
| 68 |
+
# Output a drop-in replacement for the teacher's embeddings.
|
| 69 |
+
y_embed_teacher = model.embed_teacher(x).squeeze(0)
|
| 70 |
+
|
| 71 |
+
print(y_embed_teacher.shape)
|
| 72 |
+
```
|
| 73 |
+
|
| 74 |
+
## References
|
| 75 |
+
|
| 76 |
+
>- The UniProt Consortium, UniProt: the Universal Protein Knowledgebase in 2025, Nucleic Acids Research, 2025, 53, D609–D617.
|
| 77 |
+
>- T. Hayes, et al. Simulating 500 million years of evolution with a language model, 2024.
|
| 78 |
+
>- B. Zhang, et al. Root Mean Square Layer Normalization. 33rd Conference on Neural Information Processing Systems, NeurIPS 2019.
|
| 79 |
+
>- J. Ainslie, et al. GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints, Google Research, 2023.
|
| 80 |
+
>- T. Kim, et al. Comparing Kullback-Leibler Divergence and Mean Squared Error Loss in Knowledge Distillation, 2021.
|