Protein sequence and inverse folding

ESM3 multitrack embedding and confidence fusion

MediumRaw PyTorchAbout 20 min3 public examples plus private tests

ESM3

Write and run your solution Sign in

Free account with email, Google or GitHub. Your code runs in an isolated PyTorch sandbox.

Your task

Combine supplied ESM3 sequence, structure, secondary-structure, accessibility, function, annotation, and confidence inputs. Return one fused embedding for each valid token.

Function signature

multitrack_embedding_fusion(
    activations: dict,
    parameters: dict,
    masks: dict,
    structure: dict,
) -> torch.Tensor

Worked example

Add categorical tracks and a nontrivial confidence response

The four main table lookups add to [10, 10]. Function heads concatenate to [5, 6]; two occurrences of annotation 1 add [2, 4]. Confidence values [0, 1] use center 0 and width 1, giving radial features 1 and e^{-1}. Their projection weights are [1, 1] and [2, 3], with zero biases, so confidence contributes [1+2/e,1+3/e]. The final embedding is [18+2/e,21+3/e]. This distinguishes concatenated function heads, counted duplicate annotations, and distance-dependent confidence features.

Parameters

ParameterShape and meaning
activationsdictSupplied intermediate tensors.
parametersdictSupplied model parameters, keyed as shown below.
masksdictSupplied masks. Each field below defines what True includes or permits.
structuredictFields supplied together in this dictionary.

Return

torch.Tensor · [B, N, C]

Return float[B,N,C], all track contributions added and observation-masked.

Required behavior

  • Fuse the complete supplied ESM3-style multitrack input representation. All token axes are [B,N], B,N\ge 1, and mask [B,N] is True means valid.
  • The four main tracks (\mathrm{sequence},\mathrm{structure},\mathrm{ss8},\mathrm{sasa}) each have int64 tokens [B,N] and a floating table [V_{\mathrm{track}},C]; add their row lookups. Token 0 is an ordinary learned category in these four tracks.
  • function_tokens [B,N,H] address function_table [H,\mathrm{Vf},\mathrm{Dh}], H,\mathrm{Dh}\ge 1 with C=H\cdot \mathrm{Dh}. Look up each head independently and CONCATENATE head 0..H-1 embeddings, not sum/average. Function ID 0 is padding and contributes exact zero even if the supplied table's zero row is nonzero.
  • annotation_tokens [B,N,A] address annotation_table [\mathrm{Va},C]. SUM annotations within a token, excluding ID 0. A may be 0 and duplicate IDs count repeatedly. Add this bag to the main/function embeddings. confidence [B,N,2] contains average-structure and per-residue confidence in that order.
  • For supplied centers [R] and positive scalar width, compute \phi_{\mathrm{bntr}}=\operatorname{exp}(-((\mathrm{confidence\_bnt}-\mathrm{centers\_r})/\mathrm{width})^{2}), with R\ge 1. Each t has its own confidence_weight [2,R,C] and confidence_bias [2,C].
  • Add \sum_{t}(\phi_{t}\mathbin{@}\mathrm{weight\_t}+\mathrm{bias\_t}). The original open encoder uses R=16, centers evenly spaced from 0 to 1 inclusive, width 1/16; these resources are supplied so smaller examples and derivatives can be studied. There is no one-half in the exponent and no normalization over centers.
  • Return embedding [B,N,C], the sum of these eight contributions (four main tracks, function concatenation, annotation sum and two confidence projections). All floating tensors share \mathrm{float32}/64. Valid token IDs must index their table; valid confidence, tables and parameters are finite and width> 0.
  • Scaled confidence differences, their squares, and projection/reduction intermediates must remain finite in the common dtype. Masked token IDs may be arbitrary and masked confidence may be NaN: sanitize before lookup or arithmetic; final output is exact zero. has no keys.
  • Tokenizers, structure quantization, annotation retrieval, confidence prediction and pretrained parameters are outside this computation.

Why this matters

Different tracks use different aggregation rules: some tables add, function heads concatenate, and repeated residue annotations form a summed bag.

Starter code

You write the body of this function in the BioTorch workspace. Your code runs in an isolated PyTorch sandbox; Run checks the public examples and Submit grades the full test suite, including gradients.

import torch


def multitrack_embedding_fusion(
    activations: dict,
    parameters: dict,
    masks: dict,
    structure: dict,
) -> torch.Tensor:
    """Return a tensor with shape (B, N, C)."""
    # Implement the operation. Inputs and test setup are supplied by BioTorch.
    raise NotImplementedError("Implement multitrack_embedding_fusion")

Ready to implement it?

3 progressive hints, a solution walkthrough, and grading that checks values, shapes and gradients are waiting in the workspace.

Write and run your solution Sign in

Free account with email, Google or GitHub. Your code runs in an isolated PyTorch sandbox.

Sources and further reading

A primitive exercise, not an end-to-end reproduction of the named models. No affiliation or endorsement is implied.