Skip to main content
ESM2 generates per-residue embeddings from protein sequences using Meta’s ESM-2 protein language model. These embeddings capture structural and functional information and can be used for downstream tasks like similarity comparison, clustering, or as features for other models.

Quick example

Methods

.embed()

Generate embeddings for one or more protein sequences.
str | Sequence[str]
required
A single amino acid sequence string or a list of sequences. Use ":" to separate chains in a multimer (e.g., "CHAIN_A:CHAIN_B").
dict | None
default:"None"
Per-call configuration overrides. Only dynamic config keys can be set here — static keys raise ValueError. See Configuration.
Returns: ESM2Output (see Output below)

Output

The ESM2Output dataclass returned by .embed().

Always included

PredictionMetadata
Prediction metadata with timing information. See PredictionMetadata.
np.ndarray
Per-residue embeddings from the final transformer layer. Shape: (batch, seq_len, embedding_dim).
np.ndarray
Per-residue chain assignment. Shape: (batch, seq_len).
np.ndarray
Per-residue residue numbering. Shape: (batch, seq_len).

Optional

np.ndarray | None
Embeddings from all intermediate transformer layers. Shape: (batch, num_layers, seq_len, embedding_dim). Only included when include_fields contains "hidden_states" or "*".

Model sizes

ESM-2 is available in 6 sizes. Set the model via config={"model_name": "..."}. The default model is esm2_t33_650M_UR50D (650M parameters).

Configuration

These keys can be set via config={} at initialization or options={} per call (unless marked static).

Multimer embedding

Separate chains with ":" in the sequence string:

Hidden states

To retrieve embeddings from all intermediate transformer layers, include "hidden_states" in include_fields: