Skip to main content

A protein language model that outputs amino acid sequence embeddings for use in clustering, classification, locality-sensitive hashing, and more.

Project description

ESMC ProtHash

ESMC ProtHash Banner

A protein language model that outputs contextual embeddings that align in vector-space according to the protein's underlying biological properties such as structure and function. Distilled from the ESMC family of models and trained on the UniRef50 dataset of over 53 million unique protein sequences, ProtHash embeddings align with the embedding space of ESMC but at a greatly reduced computational cost.

Key Features

  • Blazing fast and efficient: ProtHash uses significantly less computational resources than ESMC while matching up to 98% of the embedding space.

  • Biologically-relevant: Biologically similar proteins will show up nearby in the embedding space enabling downstream tasks such as clustering, classification, and locality-sensitive hashing.

  • Compatible with ESMC: ProtHash can output either ESMC or native embeddings - allowing it to serve as both a faster drop-in replacement for ESMC embeddings or a more compressed representation.

  • Quantization-ready: With quantization-aware post-training, ProtHash allows you to quantize the weights of the model while maintaining its high cosine similarity to the teacher's embedding space.

Pretrained Models

These model weights can be loaded using the prothash library using the from_pretrained() method. ONNX versions are also available.

Version 1

Coming soon ...

Legacy Models

Name Context Length Embedding Dimensions Attention Heads (Q/KV) Encoder Layers Total Params Teacher Model Teacher Dimensions Library Version
andrewdalpino/ProtHash-V0-384-Tiny 2048 384 16/4 4 4.2M esmc_300m 960 0.2.x
andrewdalpino/ProtHash-V0-384 2048 384 16/4 10 10M esmc_300m 960 0.2.x
andrewdalpino/ProtHash-V0-512-Tiny 2048 512 16/4 4 7.4M esmc_600m 1152 0.2.x
andrewdalpino/ProtHash-V0-512 2048 512 16/4 10 18M esmc_600m 1152 0.2.x

Note: The V0 models were trained on the SwissProt dataset and only trained to match the output of the classification token and not the per-token embeddings.

Example

First, you'll need the prothash and esm packages installed into your environment. For ProtHash version 1 use library version 0.1.x and for version 2 install library version 0.2.x. We recommend using a virtual environment such as Python's venv module to prevent version conflicts with other packages.

pip install prothash~=0.2.0 esm

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.

import torch

from esm.tokenization import EsmSequenceTokenizer

from prothash.model import ProtHash

tokenizer = EsmSequenceTokenizer()

model_name = "andrewdalpino/ProtHash-V0-512"

model = ProtHash.from_pretrained(model_name)

# Optionally quantize the weights to Int8.
model.quantize_weights()

sequence = input("Enter a sequence: ")

out = tokenizer(sequence, max_length=2048)

tokens = out["input_ids"]

# Input is a [1, T] tensor of token indices. 
x = torch.tensor(tokens, dtype=torch.int64).unsqueeze(0)

# Output the sequence embedding in native dimensionality.
y_embed_native = model.embed_native(x).squeeze(0)

# Output a drop-in replacement for the teacher's embeddings.
y_embed_teacher = model.embed_teacher(x).squeeze(0)

print(y_embed_native.shape)
print(y_embed_teacher.shape)

References

  • The UniProt Consortium, UniProt: the Universal Protein Knowledgebase in 2025, Nucleic Acids Research, 2025, 53, D609–D617.
  • T. Hayes, et al. Simulating 500 million years of evolution with a language model, 2024.
  • B. Zhang, et al. Root Mean Square Layer Normalization. 33rd Conference on Neural Information Processing Systems, NeurIPS 2019.
  • T. Kim, et al. Comparing Kullback-Leibler Divergence and Mean Squared Error Loss in Knowledge Distillation, 2021.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prothash-1.0.0.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

prothash-1.0.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file prothash-1.0.0.tar.gz.

File metadata

  • Download URL: prothash-1.0.0.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for prothash-1.0.0.tar.gz
Algorithm Hash digest
SHA256 94870eb451570a9b6f34f79a18383ef897a71c8d39897494caf72ea3fe5383ef
MD5 ace0b03842f99e4bedfe74aacb9c9465
BLAKE2b-256 0a55f7b7afbfb6ccf1ce5f278f79c6b096fcb2232751c0c22a5ef9d4d2145057

See more details on using hashes here.

File details

Details for the file prothash-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: prothash-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for prothash-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ed388f822266ac3734be2872758414ea638147003b9edfb3b0cf7649878f8afc
MD5 4284f3fd3d3e73f8eac09893f6d1f4ad
BLAKE2b-256 6400a89e72ff3deeaf4b1501e71541723847fa01c2d0e385d632b5e6132059a1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page