TECHNOLOGY

ESM-2 protein embeddings: exclude special tokens from residue pooling

In this article
THE QUICK TAKE

A sequence vector must specify which residue features were pooled, from which layer, and under which truncation rule.

A protein vector starts with residue identity

A sequence-search experiment may encode proteins with ESM-2 and average the returned tensor. That operation needs a definition of which positions are actual amino-acid residues. Start and end markers, batch padding, and truncated sequence tails are not interchangeable with biological positions.

The official checkpoint card identifies a protein masked-language model. Its outputs should be connected to a chosen downstream representation rather than treated as an unexplained universal similarity score.

Token features and protein features differ

The original ESM repository illustrates extracting residue representations and averaging the residue portion for sequence features. It separately notes that beginning-token features were not supervised as sequence summaries in these pretrained models.

Consequently, selecting the first returned position is an application choice with different semantics from residue mean pooling. For a retrieval experiment, document the aggregation method and evaluate it on the intended protein collection. Neither a convenient position nor a vector dimension establishes biological relevance by itself.

Padding masks do not define your pooling mask

The ESM-2 model implementation handles its padding index during the forward pass. That internal behavior does not automatically remove special positions from an external averaging operation.

Construct the pooling domain from the encoded sequence metadata. Preserve the mapping back to residue positions when storing per-residue outputs. A downstream annotation attached to an offset token can look plausible while referring to the wrong amino acid.

Layer and truncation belong in cache identity

Features from different representation layers are different artifacts even when their tensor shapes match. A cache should therefore include checkpoint identity, representation layer, tokenizer/alphabet configuration, sequence preprocessing, and truncation policy.

The tensor-axis guide helps distinguish batch positions from sequence positions. If long sequences are truncated, label the represented interval instead of presenting the resulting vector as an unchanged full-protein artifact.

Evaluate the feature contract before throughput

Compare single-sequence and padded-batch outputs under the same evaluation configuration. Check residue counts, special-token removal, and aggregation against a small manually inspected example before processing a collection.

Use the benchmark methodology only after those semantics are stable. The archived original repository is a reproducible implementation reference, not an assertion that every current distribution uses identical defaults or that an embedding alone validates a protein function.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles